emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/auctex 1dfd31dcf5 2/8: Add an :annotation-function for


From: Tassilo Horn
Subject: [elpa] externals/auctex 1dfd31dcf5 2/8: Add an :annotation-function for completion and CAPF
Date: Tue, 28 Dec 2021 04:06:01 -0500 (EST)

branch: externals/auctex
commit 1dfd31dcf5ce95419292496fa9254d8ae63594e7
Author: Tassilo Horn <tsdh@gnu.org>
Commit: Tassilo Horn <tsdh@gnu.org>

    Add an :annotation-function for completion and CAPF
    
    * tex.el (TeX--completion-annotation-function): New function.
    (TeX--completion-at-point): Use it.
    (TeX--symbol-completion-table): New function.
    (TeX-insert-macro): Use both new functions.
---
 tex.el | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/tex.el b/tex.el
index ab6d3d9e78..8acd12f8d3 100644
--- a/tex.el
+++ b/tex.el
@@ -3242,6 +3242,13 @@ Or alternatively:
                                          (all-completions symbol list nil)))))
         (funcall (nth 1 entry))))))
 
+(defun TeX--completion-annotation-function (sym)
+  "Annotation function for symbol/macro completion.
+Used as `:annotation-function' in `completion-extra-properties'."
+  (let ((ann (cdr (assoc (concat "\\" sym)
+                         tex--prettify-symbols-alist))))
+    (when ann (concat " " (char-to-string ann)))))
+
 (defun TeX--completion-at-point ()
   "(La)TeX completion at point function.
 See `completion-at-point-functions'."
@@ -3253,7 +3260,9 @@ See `completion-at-point-functions'."
                  (end (match-end sub))
                  (symbol (buffer-substring-no-properties begin end))
                  (list (funcall (nth 2 entry))))
-            (list begin end (all-completions symbol list)))
+            (list begin end (all-completions symbol list)
+                  :annotation-function
+                  #'TeX--completion-annotation-function))
         ;; We intentionally don't call the fallback completion functions 
because
         ;; they do completion on their own and don't work too well with things
         ;; like company-mode.  And the default function `ispell-complete-word'
@@ -3322,6 +3331,12 @@ The variable will be temporarily let-bound with the 
necessary value.")
 
 (defvar TeX-macro-history nil)
 
+(defun TeX--symbol-completion-table ()
+  (completion-table-dynamic
+   (lambda (_str)
+     (TeX-symbol-list-filtered))
+   t))
+
 (defun TeX-insert-macro (symbol)
   "Insert TeX macro SYMBOL with completion.
 
@@ -3333,12 +3348,16 @@ is called with \\[universal-argument]."
   ;; details.  Note that this behavior may be changed in favor of a more
   ;; flexible solution in the future, therefore we don't document it at the
   ;; moment.
-  (interactive (list (completing-read (concat "Macro (default "
-                                              TeX-default-macro
-                                              "): "
-                                              TeX-esc)
-                                      (TeX-symbol-list-filtered) nil nil nil
-                                      'TeX-macro-history TeX-default-macro)))
+  (interactive (list
+                (let ((completion-extra-properties
+                       (list :annotation-function
+                             #'TeX--completion-annotation-function)))
+                  (completing-read (concat "Macro (default "
+                                           TeX-default-macro
+                                           "): "
+                                           TeX-esc)
+                                   (TeX--symbol-completion-table) nil nil nil
+                                   'TeX-macro-history TeX-default-macro))))
   (when (called-interactively-p 'any)
     (setq TeX-default-macro symbol))
   (TeX-parse-macro symbol (cdr-safe (assoc symbol (TeX-symbol-list))))



reply via email to

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