4

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?

5
  • Have you seen emacswiki.org/emacs/NxmlMode#toc11 ?
    – omajid
    Commented Nov 11, 2016 at 17:55
  • @omajid: Please consider posting that as an answer: summarizing that info and providing the link there.
    – Drew
    Commented Nov 11, 2016 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
    Commented Nov 12, 2016 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
    Commented Nov 12, 2016 at 11:10
  • Since nobody added an answer but I found the solution, I answered my own question.
    – Zoltan
    Commented Nov 15, 2016 at 18:26

1 Answer 1

7

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)
2
  • any idea why using nxml-mode-hook doesn't work? Commented Dec 29, 2023 at 5:53
  • to answer my own question, (which-func-ff-hook) get called by after-change-major-mode-hook, and it sets which-func-mode back to nil Commented Dec 29, 2023 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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