additional global bindings, goto-last-change, nxml config updates
[emacs-init.git] / setup / nxml.el
index 33a331c..2ee07cf 100644 (file)
                 (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)
 (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"))
 
 (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)
                          (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
               (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)
 
 (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 "</" element ">")
+    (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-<return>") 'nxml-split-element)