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.

link|improve this question

72% accept rate
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 at 15:03
feedback

1 Answer

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)
link|improve this answer
This will complete the appropriate close tag after you type </ – Doug Harris Jan 30 at 19:05
How to use this when I am inserting pairs of tags in a file that's not XML, XSD, etc.? – duperuser Feb 24 at 19:47
1  
switch the nxml mode. M-x nmxl-mode – Oleg Pavliv Feb 24 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? – duperuser Feb 25 at 4:00
1  
Emacs does not support multiple major modes. So you should switch between modes. Define a shortcut which does it quickly – Oleg Pavliv Feb 25 at 6:40
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.