2

How to efficiently type in a pair of XML tags such as <tag></tag> in Emacs?

I am hoping some sort of auto-complete behavior.

1
  • I think the most effective way is to use snippets like in the answers to your other question: superuser.com/questions/394802/…. Also, you might want to vote on useful answers to your questions to show appreciation. You have asked 22 question but only voted on 6 answers.
    – N.N.
    Mar 6, 2012 at 15:03

1 Answer 1

3

Add the following to your .emacs file.

;; associate xml, xsd, etc with nxml-mode
(add-to-list 'auto-mode-alist (cons (concat "\\." (regexp-opt '("xml" "xsd" "rng" "xslt" "xsl") t) "\\'") 'nxml-mode))

set the automplete flag to true

(setq nxml-slash-auto-complete-flag t)
6
  • This will complete the appropriate close tag after you type </ Jan 30, 2012 at 19:05
  • How to use this when I am inserting pairs of tags in a file that's not XML, XSD, etc.?
    – qazwsx
    Feb 24, 2012 at 19:47
  • 1
    switch the nxml mode. M-x nmxl-mode Feb 24, 2012 at 19:58
  • This basically works. One drawback of this is that when I need to insert pairs of tags frequently in a markdown file for which I use markdown-mode, I need to switch between markdown-mode and nxml-mode frequently. Any suggestion?
    – qazwsx
    Feb 25, 2012 at 4:00
  • 1
    Emacs does not support multiple major modes. So you should switch between modes. Define a shortcut which does it quickly Feb 25, 2012 at 6:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .