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

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

[elpa] externals/auctex 6c155cc 33/57: Refactor normal completion and co


From: Tassilo Horn
Subject: [elpa] externals/auctex 6c155cc 33/57: Refactor normal completion and completion at point a bit
Date: Wed, 11 Jan 2017 18:01:40 +0000 (UTC)

branch: externals/auctex
commit 6c155cce834313a2b9a7529c9c89fd4f44d6c1f8
Author: Tassilo Horn <address@hidden>
Commit: Tassilo Horn <address@hidden>

    Refactor normal completion and completion at point a bit
    
    * tex.el (TeX--complete-find-entry): New function.
    (TeX-complete-symbol,TeX--completion-at-point): Use it.
---
 tex.el |  131 ++++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 65 insertions(+), 66 deletions(-)

diff --git a/tex.el b/tex.el
index 894e076..2eb8536 100644
--- a/tex.el
+++ b/tex.el
@@ -3155,81 +3155,80 @@ Or alternatively:
 0. Regexp matching the preceding text.
 1. Function to do the actual completion.")
 
-(defun TeX-complete-symbol ()
-  "Perform completion on TeX/LaTeX symbol preceding point."
-  (interactive "*")
+(defun TeX--complete-find-entry ()
+  "Return the first applicable entry of `TeX-complete-list'."
   (let ((list TeX-complete-list)
        entry)
     (while list
       (setq entry (car list)
            list (cdr list))
-      (if (if (functionp (car entry))
-             (funcall (car entry))
-           (TeX-looking-at-backward (car entry) 250))
-         (setq list nil)))
-    (if (numberp (nth 1 entry))
-       (let* ((sub (nth 1 entry))
-              (close (nth 3 entry))
-              (begin (match-beginning sub))
-              (end (match-end sub))
-              (pattern (TeX-match-buffer 0))
-              (symbol (buffer-substring begin end))
-              (list (funcall (nth 2 entry)))
-              (completion (try-completion symbol list))
-              (buf-name "*Completions*"))
-         (cond ((eq completion t)
-                (and close
-                     (not (looking-at (regexp-quote close)))
-                     (insert close))
-                (let ((window (get-buffer-window buf-name)))
-                  (when window (delete-window window))))
-               ((null completion)
-                (error "Can't find completion for \"%s\"" pattern))
-               ((not (string-equal symbol completion))
-                (delete-region begin end)
-                (insert completion)
-                (and close
-                     (eq (try-completion completion list) t)
-                     (not (looking-at (regexp-quote close)))
-                     (insert close))
-                (let ((window (get-buffer-window buf-name)))
-                  (when window (delete-window window))))
-               (t
-                (if (fboundp 'completion-in-region)
-                    (completion-in-region begin end
-                                          (all-completions symbol list nil))
-                  (message "Making completion list...")
-                  (let ((list (all-completions symbol list nil)))
-                    (with-output-to-temp-buffer buf-name
-                      (display-completion-list list)))
-                  (set-window-dedicated-p (get-buffer-window buf-name) 'soft)
-                  (message "Making completion list...done")))))
-      (funcall (nth 1 entry)))))
+      (when (if (functionp (car entry))
+               (funcall (car entry))
+             (TeX-looking-at-backward (car entry) 250))
+       (setq list nil)))
+    entry))
+
+(defun TeX-complete-symbol ()
+  "Perform completion on TeX/LaTeX symbol preceding point."
+  (interactive "*")
+  (let ((entry (TeX--complete-find-entry)))
+    (when entry
+      (if (numberp (nth 1 entry))
+         (let* ((sub (nth 1 entry))
+                (close (nth 3 entry))
+                (begin (match-beginning sub))
+                (end (match-end sub))
+                (pattern (TeX-match-buffer 0))
+                (symbol (buffer-substring begin end))
+                (list (funcall (nth 2 entry)))
+                (completion (try-completion symbol list))
+                (buf-name "*Completions*"))
+           (cond ((eq completion t)
+                  (and close
+                       (not (looking-at (regexp-quote close)))
+                       (insert close))
+                  (let ((window (get-buffer-window buf-name)))
+                    (when window (delete-window window))))
+                 ((null completion)
+                  (error "Can't find completion for \"%s\"" pattern))
+                 ((not (string-equal symbol completion))
+                  (delete-region begin end)
+                  (insert completion)
+                  (and close
+                       (eq (try-completion completion list) t)
+                       (not (looking-at (regexp-quote close)))
+                       (insert close))
+                  (let ((window (get-buffer-window buf-name)))
+                    (when window (delete-window window))))
+                 (t
+                  (if (fboundp 'completion-in-region)
+                      (completion-in-region begin end
+                                            (all-completions symbol list nil))
+                    (message "Making completion list...")
+                    (let ((list (all-completions symbol list nil)))
+                      (with-output-to-temp-buffer buf-name
+                        (display-completion-list list)))
+                    (set-window-dedicated-p (get-buffer-window buf-name) 'soft)
+                    (message "Making completion list...done")))))
+       (funcall (nth 1 entry))))))
 
 (defun TeX--completion-at-point ()
   "(La)TeX completion at point function.
 See `completion-at-point-functions'."
-  (let ((list TeX-complete-list)
-       entry)
-    (while list
-      (setq entry (car list)
-           list (cdr list))
-      (if (if (functionp (car entry))
-             (funcall (car entry))
-           (TeX-looking-at-backward (car entry) 250))
-         (setq list nil)))
-    (if (numberp (nth 1 entry))
-       (let* ((sub (nth 1 entry))
-              (begin (match-beginning sub))
-              (end (match-end sub))
-              (symbol (buffer-substring-no-properties begin end))
-              (list (funcall (nth 2 entry))))
-         (list begin end (all-completions symbol list)))
-      ;; 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'
-      ;; isn't so useful anyway.
-      nil)))
+  (let ((entry (TeX--complete-find-entry)))
+    (when entry
+      (if (numberp (nth 1 entry))
+         (let* ((sub (nth 1 entry))
+                (begin (match-beginning sub))
+                (end (match-end sub))
+                (symbol (buffer-substring-no-properties begin end))
+                (list (funcall (nth 2 entry))))
+           (list begin end (all-completions symbol list)))
+       ;; 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'
+       ;; isn't so useful anyway.
+       nil))))
 
 (defcustom TeX-default-macro "ref"
   "*The default macro when creating new ones with `TeX-insert-macro'."



reply via email to

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