New nxml.el completion functionality
unknown [Mon, 5 Mar 2012 13:21:50 +0000 (14:21 +0100)]
setup/nxml.el

index 208e587..123e6b3 100644 (file)
     ("step" . ("para" "procedure"))
     ("mathphrase" . ("replaceable" "superscript" "subscript"))
     ("title" . ("code" "replaceable"))
-    ("literallayout" . ("replaceable" "emphasis" "code"))))
+    ("literallayout" . ("replaceable" "emphasis" "code"))
+    ("table" . ("title" . "tgroup"))
+    ("tgroup" . ("colspec" "thead" "tbody"))
+    ("thead" . ("row"))
+    ("tbody" . ("row"))
+    ("row". ("entry"))
+    ("entry" . ("emphasis" "code"))))
 
 (defvar nxml-docbook-last-common-element nil)
 
-(defun nxml-docbook-make-common-element ()
-  (interactive)
+(defun nxml-docbook-make-common-element (&optional surrounding)
+  (interactive "P")
   (let ((start (set-marker (make-marker) (point)))
         (end (set-marker (make-marker) (point)))
         do-region)
     (when (or (region-active-p)
               (and (eq real-last-command 'nxml-docbook-make-common-element)
-                   (car nxml-docbook-last-common-element)))
-      (set-marker start (region-beginning))
-      (set-marker end (region-end))
+                   (car nxml-docbook-last-common-element))
+              surrounding)
+      (save-excursion
+        (set-marker start 
+                    (if (region-active-p) 
+                        (region-beginning) 
+                      (nxml-backward-up-element) 
+                      (save-excursion 
+                        (skip-chars-forward "^>") 
+                        (forward-char 1) 
+                        (point))))
+        (set-marker end 
+                    (if (region-active-p)
+                        (region-end)
+                      (nxml-forward-balanced-item)
+                      (skip-chars-backward "^<")
+                      (forward-char -1)
+                      (point))))
       (message "do-mark %s %s" start end)
       (setq do-region t))
     (message "cycle? %s %s" real-last-command nxml-docbook-last-common-element)
-    (when (and (eq real-last-command 'nxml-docbook-make-common-element)
-               (cdr nxml-docbook-last-common-element))
+    (when (or (and (eq real-last-command 'nxml-docbook-make-common-element)
+                   (cdr nxml-docbook-last-common-element))
+              surrounding)
       (delete-region (save-excursion (skip-chars-backward "^<") (1- (point))) start)
       (delete-region end (save-excursion (skip-chars-forward "^>") (1+ (point)))))
     (let* ((token-end (nxml-token-before)) 
               (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 (if (and elements
                            (eq real-last-command 'nxml-docbook-make-common-element)
                            (cdr nxml-docbook-last-common-element))