auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX] Patch to tex-info.el to support node name completion in @..ref


From: Vincent Belaïche
Subject: [AUCTeX] Patch to tex-info.el to support node name completion in @..ref commands, and solve a few other pbs
Date: Sun, 25 Oct 2015 21:15:25 +0100

Dear AUCTeX experts,

I would like to submit to you the attached patch.

VBR,
        Vincent Belaïche



---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
https://www.avast.com/antivirus
diff --git a/ChangeLog b/ChangeLog
index ca4d1e6..407d1dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2015-10-25  Vincent Belaïche  <address@hidden>
+
+       * tex-info.el (Texinfo-nodename-de-escape): New defun
+       (Texinfo-nodename-escape): New defun
+       (Texinfo-make-node-list): New defun, code taken from Texinfo-insert-node
+       into this function for the sake of code factorization. In
+       addition, 1/ allow node name not to be followed by a comma ---
+       i.e. next node etc. unspecified --- 2/ trim trailing blanks after
+       node name, and 3/ de-escape @comma{} before insertion of node name
+       into the list.
+       (Texinfo-insert-node): 1/ Use new function
+       `Texinfo-make-node-list', and 2/ escape node names for commas.
+       (Texinfo-arg-nodename): New defun.
+       (TeX-texinfo-mode): 1/ Remove `group' from list of commands,
+       `group' is an environment, not a command. 2/ Add `guillemetleft',
+       `guillemetright', `guilsinglleft', `guilsinglright',
+       `quotedblbase' and `quotesinglbase' to the list of commands. 3/
+       For commands `pxref', `ref' and `xref', use new fnction
+       `Texinfo-arg-nodename' to read node name with completion.
+
 2014-09-13  Vincent Belaïche  <address@hidden>
 
        * latex.el (LaTeX-dialect): Correct doctstring for consistency
diff --git a/tex-info.el b/tex-info.el
index 2c94b6a..62d022a 100644
--- a/tex-info.el
+++ b/tex-info.el
@@ -288,6 +288,50 @@ beginning of keyword address@hidden' or address@hidden'."
       (goto-char beg)
       (TeX-activate-region) )))
 
+(defun Texinfo-nodename-de-escape (node-name)
+  "In NODE-NAME, convert address@hidden' commands to the corresponding `,'
+character. Return the resulting string."
+  (let ((pos 0) (map '(("comma" . ","))))
+    (while (and (< pos (length
+                       node-name)) (string-match "@\\(comma\\)[[:blank:]]*{}" 
node-name pos))
+      (setq node-name (concat  (substring node-name 0 (match-beginning 0))
+                              (cdr (assoc-string (match-string 1 node-name) 
map))
+                              (substring node-name (match-end 0)))
+           pos (1+ (match-beginning 0)))))
+  node-name)
+
+
+(defun Texinfo-nodename-escape (node-name)
+  "Convert in NODE-NAME the `,' characters to address@hidden'
+commands. Return the resulting string."
+  (let* ((pos 0)
+        (map '(("," . "comma")))
+        (re (regexp-opt (mapcar 'car map))) )
+    (while (and (< pos (length node-name)) (string-match re node-name pos))
+      (setq node-name (concat  (substring node-name 0 (match-beginning 0))
+                              "@" (cdr (assoc-string (match-string 0 
node-name) map))
+                              "{}"
+                              (substring node-name (match-end 0)))
+           pos (1+ (match-beginning 0)))))
+  node-name)
+
+
+(defun Texinfo-make-node-list (&optional nodes)
+    ;; Build list of nodes in current buffer.
+    ;; (What about using `imenu--index-alist'?)
+    ;; FIXME: Support multi-file documents.
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "address@hidden" nil t)
+       (skip-chars-forward "[:blank:]")
+       (add-to-list 'nodes
+                    (list (Texinfo-nodename-de-escape
+                           (buffer-substring-no-properties
+                           (point) (progn (skip-chars-forward "^\r\n,")
+                                          (skip-chars-backward "[:blank:]")
+                                          (point))))))))
+    nodes)
+
 (defun Texinfo-insert-node ()
   "Insert a Texinfo node in the current buffer.
 That means, insert the string address@hidden' and prompt for current,
@@ -297,26 +341,16 @@ a comment on the following line indicating the order of 
arguments
 for @node."
   (interactive)
   (let ((active-mark (and (TeX-active-mark) (not (eq (mark) (point)))))
-       nodes node-name next-node previous-node up-node)
-    ;; Build list of nodes in current buffer.
-    ;; (What about using `imenu--index-alist'?)
-    ;; FIXME: Support multi-file documents.
-    (save-excursion
-      (goto-char (point-min))
-      (while (re-search-forward "address@hidden" nil t)
-       (skip-chars-forward " \t")
-       (add-to-list 'nodes
-                    (list (buffer-substring-no-properties
-                           (point) (progn (skip-chars-forward "^,")
-                                          (point)))))))
+       (nodes (Texinfo-make-node-list))
+       node-name next-node previous-node up-node)
     (unless active-mark
-      (setq node-name (read-string "Node name: ")))
+      (setq node-name (Texinfo-nodename-escape (read-string "Node name: "))))
     ;; FIXME: What if key binding for `minibuffer-complete' was changed?
     ;; `substitute-command-keys' doesn't return the correct value.
-    (setq next-node (completing-read "Next node (TAB completes): " nodes))
+    (setq next-node (Texinfo-nodename-escape (completing-read "Next node (TAB 
completes): " nodes)))
     (setq previous-node
-         (completing-read "Previous node (TAB completes): " nodes))
-    (setq up-node (completing-read "Upper node (TAB completes): " nodes))
+         (Texinfo-nodename-escape (completing-read "Previous node (TAB 
completes): " nodes)))
+    (setq up-node (Texinfo-nodename-escape (completing-read "Upper node (TAB 
completes): " nodes)))
     (when (and active-mark
               (< (mark) (point)))
       (exchange-point-and-mark))
@@ -342,6 +376,18 @@ for @node."
              (progn (skip-chars-forward "^,") (forward-char 2))
            (throw 'break nil)))))))
 
+(defun Texinfo-arg-nodename (optional &optional prompt definition)
+  "Prompt for a node name completing with known node names.
+OPTIONAL is ignored.
+Use PROMPT as the prompt string.
+If DEFINITION is non-nil, then chosen node name is a node name to be
+added to the list of defined node names. Current implementation
+ignored DEFINITION as the full document is scanned for node names at
+each invocation."
+  (let ((node-name (completing-read (TeX-argument-prompt optional prompt "Key")
+                               (Texinfo-make-node-list))))
+    (insert "{" (Texinfo-nodename-escape node-name) "}" )))
+
 ;; Silence the byte-compiler from warnings for variables and functions declared
 ;; in reftex.
 (eval-when-compile
@@ -661,7 +707,10 @@ value of `Texinfo-mode-hook'."
    '("findex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
    '("footnote" "Text of footnote")
    '("footnotestyle" (TeX-arg-literal " ") (TeX-arg-free "Style"))
-   '("group")
+   '("guillemetleft")
+   '("guillemetright")
+   '("guilsinglleft")
+   '("guilsinglright")
    '("heading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
    ;; XXX: Would be nice with completion.
    '("headings" (TeX-arg-literal " ") (TeX-arg-free "On off single double"))
@@ -692,10 +741,12 @@ value of `Texinfo-mode-hook'."
    '("point" nil)
    '("print")
    '("printindex" (TeX-arg-literal " ") (TeX-arg-free "Index name"))
-   '("pxref" "Node name")
+   '("pxref" (Texinfo-arg-nodename "Node name"))
+   '("quotedblbase")
+   '("quotesinglbase")
    '("r" "Text")
    '("raisesections" 0)
-   '("ref" "Node name")
+   '("ref" (Texinfo-arg-nodename "Node name"))
    '("refill")
    '("result")
    '("samp" "Text")
@@ -742,7 +793,7 @@ value of `Texinfo-mode-hook'."
    '("vindex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
    '("vskip" (TeX-arg-literal " ") (TeX-arg-free "Amount"))
    '("w" "Text")
-   '("xref" "Node name"))
+   '("xref" (Texinfo-arg-nodename "Node name")))
 
   ;; RefTeX plugging
   (add-hook 'reftex-mode-hook 'Texinfo-reftex-hook)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]