[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex 436371c 31/57: Add completion-at-point support
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex 436371c 31/57: Add completion-at-point support |
Date: |
Wed, 11 Jan 2017 18:01:39 +0000 (UTC) |
branch: externals/auctex
commit 436371c63da26af56ea076bce8636dcb41fcdfd1
Author: Tassilo Horn <address@hidden>
Commit: Tassilo Horn <address@hidden>
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.
---
doc/auctex.texi | 62 ++++++++++++++++++++++++++++++++++++++++++++++++------
doc/changes.texi | 7 ++++++
tex.el | 35 ++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 7 deletions(-)
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
- [elpa] externals/auctex 74c5ac9 09/57: Update style/tcolorbox.el to package v3.96, (continued)
- [elpa] externals/auctex 74c5ac9 09/57: Update style/tcolorbox.el to package v3.96, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 0b16551 51/57: * Makefile.in (release-commit): Use UTF-8 coding for ChangeLog entry., Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 826f17a 54/57: Release_11.90, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 61e56f2 40/57: Fix bug where font-latex-sub/superscript-face was not applied to ^_, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex bc47cb0 39/57: Fontify script characters with a new face, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 6fe7a2e 43/57: Prepare for upcoming release, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 33a6ff8 48/57: ; Change email address., Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 5af3c8e 15/57: Add \switchcolumn to paragraph commands, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex a943b6c 10/57: Add new tcolorbox library style/tcolorboxlib-raster.el, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 3a5ed08 38/57: Support biblatex cite format in all Emacsen, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 436371c 31/57: Add completion-at-point support,
Tassilo Horn <=
- [elpa] externals/auctex a181b14 55/57: ; make change-history-commit, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 4ebbf90 56/57: Make gitlog-to-changelog ignore release-commit, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex a9ec6ba 01/57: Update style/minted.el to package version 2.4.1., Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 4c59f77 42/57: Adapt Makefile to new ChangeLog file name, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex c541d75 20/57: Fix the names also in expert macros, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 93b1163 50/57: * ChangeLog-preview: Change encoding to UTF-8., Tassilo Horn, 2017/01/11
- [elpa] externals/auctex fb6333b 45/57: ; * doc/install.texi (Installation): Guard reference in "@ifclear rawfile"., Tassilo Horn, 2017/01/11
- [elpa] externals/auctex ea7f427 28/57: Improve multi-level script fontification, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex bdc5d0d 11/57: Add new style/mdframed.el, Tassilo Horn, 2017/01/11
- [elpa] externals/auctex 6c155cc 33/57: Refactor normal completion and completion at point a bit, Tassilo Horn, 2017/01/11