1 (defvar nxml-where-elements-to-id 3)
2 (defvar nxml-where-max-elements 6)
7 "Display the hierarchy of XML elements the point is on as a path."
8 (and (eq major-mode 'nxml-mode)
9 (let (path-to-id path-rest)
13 (while (and (not (bobp))
14 (condition-case nil (progn (nxml-backward-up-element) t) (error nil)))
17 (loop with has-id = nil
18 with step = (xmltok-start-tag-local-name)
19 for att in xmltok-attributes
20 if (string= (xmltok-attribute-local-name att) "id")
21 return (values t (concat "\"" (xmltok-attribute-value att) "\""))
22 else if (string= (xmltok-attribute-local-name att) "name")
23 do (setq has-id t step (concat "\"" (xmltok-attribute-value att) "\""))
24 finally return (values has-id step ))
25 (if (or path-to-id has-id)
26 (setq path-to-id (cons step path-to-id))
27 (setq path-rest (cons step path-rest)))))))
28 (let ((path-to-id-len (length path-to-id))
29 (path-rest-len (length path-rest)))
30 (if (> path-to-id-len nxml-where-elements-to-id)
32 (setq path-to-id (nthcdr (- path-to-id-len nxml-where-elements-to-id -1) path-to-id))
33 (setq path-to-id (cons "..." path-to-id))
34 (setq path-to-id-len nxml-where-elements-to-id))
35 (setq path-to-id (cons "" path-to-id)))
36 (when (> (+ path-to-id-len path-rest-len) nxml-where-max-elements)
37 (setq path-rest (nbutlast path-rest (- path-rest-len (- nxml-where-max-elements path-to-id-len) -1)))
38 (setq path-rest (nconc path-rest (list "...")))))
39 (mapconcat 'identity (nconc path-to-id path-rest) "/"))))
43 (add-to-list 'which-func-functions 'nxml-where)
44 (add-to-list 'which-func-modes 'nxml-mode)
45 (add-to-list 'which-func-non-auto-modes 'nxml-mode)
47 (add-to-list 'auto-mode-alist '("\\.xslt?\\'" . nxml-mode))
48 (add-to-list 'auto-mode-alist '("\\.xsd\\'" . nxml-mode))
52 (add-to-list 'hs-special-modes-alist '(nxml-mode ("\\(<[^/>]*>\\)$" 1)
54 (defun nxml-enable-hs ()
55 (setq nxml-sexp-element-flag t)
58 (add-hook 'nxml-mode-hook 'nxml-enable-hs)
60 (defun hs-nxml-enter ()
62 (when (hs-already-hidden-p)
65 (nxml-forward-element)
66 (nxml-backward-element)))
68 (defun hs-nxml-leave ()
70 (nxml-backward-up-element)
72 (nxml-backward-up-element))
74 (define-key nxml-mode-map (kbd "\C-c <left>") 'hs-nxml-leave)
75 (define-key nxml-mode-map (kbd "\C-c <right>") 'hs-nxml-enter)