X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=setup%2Fnxml.el;h=2ee07cfedb83348429f23514d612a425a8e16f0a;hb=a164f6b9835d2e5339ff1e13d98e3cfdc8e40f1a;hp=33a331c86c82089e93424604fed701291451b0f5;hpb=004c6d525beda5fe2c9be56130949ba59f59dc02;p=emacs-init.git diff --git a/setup/nxml.el b/setup/nxml.el index 33a331c..2ee07cf 100644 --- a/setup/nxml.el +++ b/setup/nxml.el @@ -39,6 +39,17 @@ (mapconcat 'identity (nconc path-to-id path-rest) "/")))) (require 'which-func) +(which-func-mode) + +(delete (assoc 'which-func-mode mode-line-format) mode-line-format) +(setq which-func-header-line-format + '(which-func-mode + ("" which-func-format + ))) +(defadvice which-func-ff-hook (after header-line activate) + (when which-func-mode + (delete (assoc 'which-func-mode mode-line-format) mode-line-format) + (setq header-line-format which-func-header-line-format))) (add-to-list 'which-func-functions 'nxml-where) (add-to-list 'which-func-modes 'nxml-mode) @@ -112,17 +123,17 @@ (define-key nxml-mode-map (kbd "\C-c\C-c") 'recompile) (defconst nxml-docbook-common-elements - '(("section" . ("para" "itemizedlist" "variablelist" "section" "bridgehead" "task" "procedure")) + '(("section" . ("para" "itemizedlist" "variablelist" "section" "bridgehead" "task" "procedure" "title")) ("para" . ("emphasis" "code" "replaceable")) ("emphasis" . ("code")) ("itemizedlist" . ("listitem")) ("orderedlist" . ("listitem")) ("variablelist" . ("varlistentry")) ("varlistentry" . ("term" "listitem")) - ("term" . ("emphasis" "code")) + ("term" . ("emphasis" "code" "replaceable")) ("listitem" . ("para" "itemizedlist")) - ("task" . ("tasksummary" "procedure")) - ("tasksummary" . ("para")) + ("task" . ("tasksummary" "procedure" "title")) + ("tasksummary" . ("para" "itemizedlist" "variablelist")) ("procedure" . ("step")) ("step" . ("para" "procedure")) ("mathphrase" . ("replaceable" "superscript" "subscript")) @@ -137,7 +148,7 @@ (defvar nxml-docbook-common-elements-next-args nil) -(defun nxml-docbook-make-common-element (&optional start end kill-tag use-index old-tag) +(defun nxml-docbook-make-common-element (&optional start end kill-tag use-index old-tag valid) (interactive (cond ((and (eq real-last-command 'nxml-docbook-make-common-element) nxml-docbook-common-elements-next-args) nxml-docbook-common-elements-next-args) @@ -180,18 +191,24 @@ (nxml-token-type-friendly-name xmltok-type))) (nxml-scan-element-backward token-end t))) (context (xmltok-start-tag-qname)) - (elements (cdr (assoc context nxml-docbook-common-elements))) -; List valid start tags at point (using schema): -; (let ((lt-pos (point))) (rng-set-state-after lt-pos) (loop for (ns . name) in (rng-match-possible-start-tag-names) collect name)) - (index (or (and elements - (or use-index - (and old-tag - (loop for i from 0 - for elt in elements - if (string= elt old-tag) return (1+ i) - finally return 0)))) - 0)) - (element (and elements (nth index elements)))) + (common-elements (cdr (assoc context nxml-docbook-common-elements))) + (valid-elements (or valid + (let ((lt-pos (point))) + (rng-set-state-after lt-pos) + (loop for (ns . name) in (rng-match-possible-start-tag-names) + if (not (member name elements)) collect name into elements + finally return elements)))) + (elements (loop for element in common-elements + if (member element valid-elements) collect element)) + (index (or (and elements + (or use-index + (and old-tag + (loop for i from 0 + for elt in elements + if (string= elt old-tag) return (1+ i) + finally return 0)))) + 0)) + (element (and elements (nth index elements)))) (when (not elements) (error "No common elements for %s" context)) (if element @@ -204,11 +221,13 @@ (setq nxml-docbook-common-elements-next-args (list (marker-position start) (marker-position end) t - (1+ index)))) + (1+ index) + valid-elements))) (setq nxml-docbook-common-elements-next-args (list (marker-position start) (marker-position end) nil - 0))))))) + 0 + valid-elements))))))) (defun nxml-just-one-space-or-skip-end () (interactive) @@ -223,10 +242,36 @@ (defun nxml-open-line () (interactive) - (open-line 1) - (save-excursion - (forward-line 1) - (indent-according-to-mode)) - (newline-and-indent)) + (if (region-active-p) + (let ((start (region-beginning)) + (end (region-end)) + chars) + (save-excursion + (goto-char end) + (newline-and-indent) + (goto-char start) + (setq chars (- (- (point) (progn (newline-and-indent) (point))))) + (indent-region (+ start chars) (+ end chars)))) + (open-line 1) + (save-excursion + (forward-line 1) + (indent-according-to-mode)) + (newline-and-indent))) + +(defun nxml-split-element () + (interactive) + (let (element block-p) + (save-excursion + (nxml-backward-up-element) + (setq element (xmltok-start-tag-qname) + block-p (looking-back "^\s-*" (save-excursion (beginning-of-line) (point))))) + (delete-horizontal-space) + (insert "") + (fill-paragraph) + (insert "\n") + (newline-and-indent) + (insert "<" element ">") + (fill-paragraph))) (define-key nxml-mode-map (kbd "M-o") 'nxml-open-line) +(define-key nxml-mode-map (kbd "S-") 'nxml-split-element)