auctex-diffs
[Top][All Lists]
Advanced

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

[AUCTeX-diffs] GNU AUCTeX branch, master, updated. 436371c63da26af56ea07


From: Tassilo Horn
Subject: [AUCTeX-diffs] GNU AUCTeX branch, master, updated. 436371c63da26af56ea076bce8636dcb41fcdfd1
Date: Tue, 3 Jan 2017 20:15:07 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
       via  436371c63da26af56ea076bce8636dcb41fcdfd1 (commit)
      from  1addc62fc10e52ff29e64486a3754627ac2c1495 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 436371c63da26af56ea076bce8636dcb41fcdfd1
Author: Tassilo Horn <address@hidden>
Date:   Tue Jan 3 21:12:29 2017 +0100

    Add completion-at-point support
    
    * doc/auctex.texi (Completion): Document completion-at-point support.
    * doc/changes.texi: Mention completion-at-point support.
    * tex.el (TeX--completion-at-point): New function.
    (VirTeX-common-initialization): Add TeX--completion-at-point to
    completion-at-point-functions in TeX buffers if that's bound.

diff --git a/doc/auctex.texi b/doc/auctex.texi
index 09322f1..87233f1 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -1216,24 +1216,72 @@ If non-nil, insert braces after typing @key{^} and 
@key{_} in math mode.
 @cindex Arguments to @TeX{} macros
 
 Emacs lisp programmers probably know the @code{lisp-complete-symbol}
-command, usually bound to @address@hidden  Users of the wonderful
-ispell mode know and love the @code{ispell-complete-word} command from
-that package.  Similarly, @AUCTeX{} has a @code{TeX-complete-symbol}
-command, by default bound to @address@hidden which is equivalent to
address@hidden  Using @code{TeX-complete-symbol} makes it easier to type
-and remember the names of long @LaTeX{} macros.
+command which was bound to @address@hidden until completion-at-point
+became the new standard completion facility (see below).  Users of the
+wonderful ispell mode know and love the @code{ispell-complete-word}
+command from that package.  Similarly, @AUCTeX{} has a
address@hidden command, by default bound to
address@hidden@key{TAB}} which is equivalent to @kbd{M-C-i}.  Using
address@hidden makes it easier to type and remember the
+names of long @LaTeX{} macros.
 
 In order to use @code{TeX-complete-symbol}, you should write a backslash
 and the start of the macro.  Typing @address@hidden will now complete
 as much of the macro, as it unambiguously can.  For example, if you type
 address@hidden' and then @address@hidden, it will expand to
address@hidden'.
address@hidden'.  But there's more: if point is just after
address@hidden@{}, then @code{TeX-complete-symbol} will complete @LaTeX{}
+environments, etc.  This is controlled by @code{TeX-complete-list}.
 
 @deffn Command TeX-complete-symbol
 @kindex address@hidden
 (@address@hidden)  Complete @TeX{} symbol before point.
 @end deffn
 
address@hidden TeX-complete-list
+List of ways to complete the preceding text.
+
+Each entry is a list with the following elements:
+
address@hidden
address@hidden
+Regexp matching the preceding text.
address@hidden
+A number indicating the subgroup in the regexp containing the text.
address@hidden
+A function returning an alist of possible completions.
address@hidden
+Text to append after a succesful completion.
address@hidden enumerate
+
+Or alternatively:
+
address@hidden
address@hidden
+Regexp matching the preceding text.
address@hidden
+Function to do the actual completion.
address@hidden enumerate
address@hidden defvar
+
+More recent Emacs versions have a new completion mechanism.  Modes may
+define and register custom completion-at-point functions and when the
+user invokes @code{completion-at-point} (usually bound to
address@hidden@key{TAB}}), all such registered functions are consulted for
+checking for possible completions.  Modern completion UIs like
address@hidden support this completion-at-point facility.
+
address@hidden TeX--completion-at-point
address@hidden's completion-at-point function which is automatically added to
address@hidden in @TeX{} and @LaTeX{} buffers.
+
+It offers the same completion candidates as would
address@hidden (and is also controlled by
address@hidden) except that it doesn't fall back on
address@hidden which would be awkward with completion UIs
+like @i{company-mode}.
address@hidden deffn
+
 A more direct way to insert a macro is with @code{TeX-insert-macro},
 bound to @kbd{C-c C-m} which is equivalent to @kbd{C-c @key{RET}}.  It
 has the advantage over completion that it knows about the argument of
diff --git a/doc/changes.texi b/doc/changes.texi
index 74eabe0..e756d96 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -12,6 +12,13 @@
 
 @itemize @bullet
 @item
+In addition to the completion performed by @code{TeX-complete-symbol},
address@hidden now also supports the new Emacs standard completion-at-point
+facility (see the Emacs command @code{completion-at-point}).  This also
+means that modern completion UIs like @i{company-mode} work out of the
+box in @TeX{} and @LaTeX{} buffers.
+
address@hidden
 @AUCTeX{} is able to display several levels of super- and subscripts,
 each one raised above and a bit smaller than its basis.  For this
 feature, have a look at the customize options
diff --git a/tex.el b/tex.el
index ab301fd..ac81b74 100644
--- a/tex.el
+++ b/tex.el
@@ -3202,6 +3202,29 @@ Or alternatively:
                   (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 (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)))
+
 (defcustom TeX-default-macro "ref"
   "*The default macro when creating new ones with `TeX-insert-macro'."
   :group 'TeX-macro
@@ -3730,6 +3753,18 @@ The algorithm is as follows:
       (set (make-local-variable 'prettify-symbols-compose-predicate)
           #'TeX--prettify-symbols-compose-p)))
 
+  ;; Standard Emacs completion-at-point support
+  (when (boundp 'completion-at-point-functions)
+    (add-hook 'completion-at-point-functions
+             #'TeX--completion-at-point nil t)
+
+    ;; Support for company-mode
+    (when (fboundp 'company-mode)
+      ;; By default, company completions kick in after a prefix of 3 chars has
+      ;; been typed.  Since we don't have too many completions, that's too
+      ;; much.
+      (set (make-local-variable 'company-minimum-prefix-length) 1)))
+
   ;; Let `TeX-master-file' be called after a new file was opened and
   ;; call `TeX-update-style' on any file opened.  (The addition to the
   ;; hook has to be made here because its local value will be deleted

-----------------------------------------------------------------------

Summary of changes:
 doc/auctex.texi  |   62 ++++++++++++++++++++++++++++++++++++++++++++++++------
 doc/changes.texi |    7 ++++++
 tex.el           |   35 ++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
GNU AUCTeX



reply via email to

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