vim7: generous XML completion (data storage format)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

vim7: generous XML completion (data storage format)

Mikołaj Machowski
Hello,

I finished XHTML completion file and started thinking about
common XML completion.

Having XHTML completion file as a template writing completion
itself should be relatively easy. Problem is a format of storage
data. Due to limitations of Vim variable's names usage of {}
variables is out of question. Everything should be stored
in one, giant structure (maybe apart from entities).

Here is an example from XHTML. I am asking for comments from
XML users (I am using only XHTML):


let g:xhtml = {
\ "html":
\ [ ["body", "head"], {"id": [], "xmlns": ["http://www.w3.org/1999/xhtml"],
"lang": [], "xml:lang": [], "dir": ["ltr", "rtl"]}],
\ "script":
\ [ [], {"id": [], "charset": [], "type": ["text/javascript"], "src": [],
"defer": ["BOOL"], "xml:space": ["preserve"]}],
\ "meta":
\ [ [], {"id": [], "http-equiv": [], "name": [], "content": [], "scheme":
[], "lang": [], "xml:lang": [], "dir": ["ltr", "rtl"]}]
\ }

Put above lines into separate file and source it. Access to various
elements:

:echo keys(g:xhtml)            " list with all tags of dialect
:echo g:html["html"][0]        " list with child elements
:echo keys(g:xhtml["html"][1]) " list with attributes of chosen tag
:echo g:xhtml["html"][1]["xmlns"] " list with possible values of
          " attribute. Special BOOL value indicates this is boolean
          " attribute

m.

Reply | Threaded
Open this post in threaded view
|

Re: vim7: generous XML completion (data storage format)

Gareth Oakes-2
Hi there,

I might be the only one, but I'm not entirely sure I know what you
mean... I haven't played with vim7 so I guess it has some sort of
"intellisense" stuff built in, which must be what you're talking about.

As for generic XML support: XHTML is a specific XML application so it
seems pretty straight forward (with some grunt work) to encode the rules
into the sort of structure you list below.  To create a completion file
for any XML document is much harder, as you would need to parse and
interpret the DTD file(s) associated with the XML document type.  This
is a non-trivial exercise, unless vim7 also comes with XML libraries and
some nice interface for your scripts (eg. SAX).  Or perhaps you have
some external tool to do the job, in which case this could be applied to
your XHTML DTD (or any other XML DTDs).

Cheers,
Gareth


Mikolaj Machowski wrote:

> Hello,
>
> I finished XHTML completion file and started thinking about
> common XML completion.
>
> Having XHTML completion file as a template writing completion
> itself should be relatively easy. Problem is a format of storage
> data. Due to limitations of Vim variable's names usage of {}
> variables is out of question. Everything should be stored
> in one, giant structure (maybe apart from entities).
>
> Here is an example from XHTML. I am asking for comments from
> XML users (I am using only XHTML):
>
>
> let g:xhtml = {
> \ "html":
> \ [ ["body", "head"], {"id": [], "xmlns": ["http://www.w3.org/1999/xhtml"],
> "lang": [], "xml:lang": [], "dir": ["ltr", "rtl"]}],
> \ "script":
> \ [ [], {"id": [], "charset": [], "type": ["text/javascript"], "src": [],
> "defer": ["BOOL"], "xml:space": ["preserve"]}],
> \ "meta":
> \ [ [], {"id": [], "http-equiv": [], "name": [], "content": [], "scheme":
> [], "lang": [], "xml:lang": [], "dir": ["ltr", "rtl"]}]
> \ }
>
> Put above lines into separate file and source it. Access to various
> elements:
>
> :echo keys(g:xhtml)            " list with all tags of dialect
> :echo g:html["html"][0]        " list with child elements
> :echo keys(g:xhtml["html"][1]) " list with attributes of chosen tag
> :echo g:xhtml["html"][1]["xmlns"] " list with possible values of
>           " attribute. Special BOOL value indicates this is boolean
>           " attribute
>
> m.
>

Reply | Threaded
Open this post in threaded view
|

Re: vim7: generous XML completion (data storage format)

Mikołaj Machowski
Dnia czwartek, 29 wrze?nia 2005 10:36, Gareth Oakes napisa?:

> Hi there,
>
> I might be the only one, but I'm not entirely sure I know what you
> mean... I haven't played with vim7 so I guess it has some sort of
> "intellisense" stuff built in, which must be what you're talking about.
>
> As for generic XML support: XHTML is a specific XML application so it
> seems pretty straight forward (with some grunt work) to encode the rules
> into the sort of structure you list below.  To create a completion file
> for any XML document is much harder, as you would need to parse and
> interpret the DTD file(s) associated with the XML document type.  This
> is a non-trivial exercise, unless vim7 also comes with XML libraries and
> some nice interface for your scripts (eg. SAX).  Or perhaps you have
> some external tool to do the job, in which case this could be applied to
> your XHTML DTD (or any other XML DTDs).

At this moment I am only interested in format of storage of data and
informations which should be retrievable from it.

Retrieving this data from DTD is completely another question. Could be
made by hand, some scripts or any other tools.

So:

Mentioned structure can give info about:

- possible children of parent tag
- possible attributes of tag

  - if attribute is full or boolean (completion to ``attr="`` or ``attr``)
  - could even give info if tag is empty or not by adding ``>`` or
    ``/>`` as attributes

- possible values of attributes of given tag
- maybe function name for customized completion of attr value (like
  completion of CSS inside of ``style`` attribute of HTML.


I am asking what more info would be useful for XML writers.

m.

Reply | Threaded
Open this post in threaded view
|

Re: vim7: generous XML completion (data storage format)

Mikołaj Machowski
In reply to this post by Gareth Oakes-2
Dnia czwartek, 29 wrze?nia 2005 10:36, Gareth Oakes napisa?:
> Hi there,
>
> I might be the only one, but I'm not entirely sure I know what you
> mean... I haven't played with vim7 so I guess it has some sort of
> "intellisense" stuff built in, which must be what you're talking about.

Forgot:

XHTML and CSS completion files are in newest Vim7 snapshots. It
should be available from Tony Mechelynck page:

http://users.skynet.be/antoine.mechelynck

Check

:help compl-omni
:help ft-html-omni

And play a bit with HTML files.

m.

Reply | Threaded
Open this post in threaded view
|

Re: vim7: generous XML completion (data storage format)

A.J.Mechelynck
Mikolaj Machowski wrote:

> Dnia czwartek, 29 wrze?nia 2005 10:36, Gareth Oakes napisa?:
>> Hi there,
>>
>> I might be the only one, but I'm not entirely sure I know what you
>> mean... I haven't played with vim7 so I guess it has some sort of
>> "intellisense" stuff built in, which must be what you're talking about.
>
> Forgot:
>
> XHTML and CSS completion files are in newest Vim7 snapshots. It
> should be available from Tony Mechelynck page:
>
> http://users.skynet.be/antoine.mechelynck

If you already have a recent-enough Vim 7, it should be somewhere among
your runtime files. Otherwise you can get a Windows-only ready-to-go
distribution from my "Vim" page ("The Vim Editor" from the link above),
or the full source and runtimes for all officially supported platforms
as the latest zipfile at http://ftp.vim.org/pub/vim/unstable/snapshot/
(which is where I get my sources); the latter may also be fetched by CVS
or (IIUC) by means of A-A-P which requires Python.


Best regards,
Tony.

>
> Check
>
> :help compl-omni
> :help ft-html-omni
>
> And play a bit with HTML files.
>
> m.
>
>
>
>