2

When editing a long Maven pom.xml I may see a screen full of <plugin> blocks with their parent tags out of sight. I would like to know whether I'm looking at a /project/build/plugins/plugin tag or a /project/profiles/profile/build/plugins/plugin tag.

Is there an easy way to display this information in the modeline or on the top of the screen?

  • Have you seen emacswiki.org/emacs/NxmlMode#toc11 ? – Omair Majid Nov 11 '16 at 17:55
  • @omajid: Please consider posting that as an answer: summarizing that info and providing the link there. – Drew Nov 11 '16 at 17:57
  • Yes, I have seen that, but I percieve this functionality to be so basic that I find it hard to believe there isn't a ready-made solution. If I would like to see the context hierarchy in C++, which-func-mode is ready to use. If I would like to do the same in XML, do I really have to define a function myself? And actually the linked function just prints this info to the echo area on demand, even more code is needed to make it show up in the modeline permanently. Isn't there a Melpa package that provides this functionality? – Zoltan Nov 12 '16 at 10:55
  • I looked into which-func-mode and found that it is extensible by custom functions, so all that is needed to get the nxml-where function work with which-func-mode is (add-hook 'which-func-functions 'nxml-where). @omajid if you combine these two pieces of information into an answer, I am happy to accept it. – Zoltan Nov 12 '16 at 11:10
  • Since nobody added an answer but I found the solution, I answered my own question. – Zoltan Nov 15 '16 at 18:26
4

Install nxml-mode and which-function-mode. Take the nxml-where function from here and add it to your .emacs file followed by:

(defun xml-find-file-hook ()
  (when (derived-mode-p 'nxml-mode)
    (which-function-mode t)
    (setq which-func-mode t)
    (add-hook 'which-func-functions 'nxml-where t t)))

(add-hook 'find-file-hook 'xml-find-file-hook t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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