Yesterday's post about switching back to Emacs saw quite a few comments from people (most of them useful, even). I learned a few things.
My biggest gripe about Vim was that for the file types I worked with most, its indentation and syntax highlighting was inferior to that of Emacs. I'd like to illustrate that with an example.
Let's consider one of those file types: XML containing DocBook markup.
Vim has a DocBook mode. It doesn't autodetect DocBook files, so I have this at the top of each one:
<!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->
Now, why should Vim need a separate DocBook mode? DocBook is just XML or SGML, and these things have a well-formed nature. Well, part of the reason is that /usr/share/vim/vim71/syntax/docbk.vim has a
ton of lines like this:
syn keyword docbkKeyword chapter citation citerefentry citetitle city contained
Yes, they are hard-coding all the DocBook element names into the editing mode. It's probably used for completion, highlighting, maybe indentation. I'm not sure, really. I remember that editing these files without the DocBook mode was much more painful anyway, but that was 8 months ago and I can't quite remember why.
Now, what about Emacs? I don't know if Emacs even has a DocBook mode, mainly because I don't have to care. The Emacs psgml mode actually
parses the DTD for your XML or SGML files. It knows exactly what the valid tags are from doing so. This means it has full functionality not just for DocBook, but for
any XML or SGML file with a DTD.
Not only that, but it knows more about the files than Vim does. For instance, both Emacs and Vim can do completion of various things. Vim </ C-x C-o (ooo, sounds like Emacs!) can complete my closing tags. But it can't autocomplete my opening tags, and it certainly isn't aware
Not only can Emacs autocomplete opening and closing tags, but it
knows exactly what tags are valid at a given place in the document (thanks to the DTD) and will only consider those tags for completion. Moreover, depending on how you have configured it, it could also insert spots for you to add any required attributes. So, for instance, if you're editing XHTML and autocompletion gives you an <img> tag, it would add
src="" in it for you, as a reminder that src is required.
There are a host of other smart things that Emacs can do with XML or SGML documents. For instance, you can get a list of all tags valid at the current point with C-c C-t or Shift-RightClick -- useful if you've forgotten the name of a tag for a moment.
The difference isn't as great with everything. But it sure is noticable as I work with XML and Haskell files.
Comments
Thu, 03.07.2008 19:17
I recently was looking at opti ons for my blog, and decided t o try out blip.tv. Indeed thei r system appears to cate [...]
Thu, 03.07.2008 14:00
When HTML5 video comes out, it should be easy to host your o wn videos. My video site is here: http://video.nat [...]
Thu, 03.07.2008 12:51
You might want to check out [url="http://viddler.com"]Viddler[/url]. I have some command line tools for the API [...]
Thu, 03.07.2008 08:25
I haven't decided for sure yet . I found a nice review of some of them. [...]
Thu, 03.07.2008 07:53
What are you going to use to c apture/edit? You can have a look at kino, if you [...]
Thu, 03.07.2008 07:03
Thanks for the suggestions, ev eryone. To give a very brie f idea of what we have done: For the learning curve [...]
Thu, 03.07.2008 05:29
The original text was discussi ng whether religion is detrime ntal to science. For 1 it was putting the point that s [...]
Wed, 02.07.2008 16:15
Two primary concerns: compatib ility with other hardware, esp ecially MS servers; and ease o f staff updates and installs.