[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-diffs] [elpa] externals/auctex 436371c 31/57: Add completion-at-
From: |
Tassilo Horn |
Subject: |
[AUCTeX-diffs] [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
enewc}' and then @address@hidden, it will expand to
address@hidden
enewcommand}'.
address@hidden
enewcommand}'. 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
- [AUCTeX-diffs] [elpa] externals/auctex 0766526 41/57: Don't use cl function copy-list, (continued)
- [AUCTeX-diffs] [elpa] externals/auctex 0766526 41/57: Don't use cl function copy-list, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex a181b14 55/57: ; make change-history-commit, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 61e56f2 40/57: Fix bug where font-latex-sub/superscript-face was not applied to ^_, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex bc47cb0 39/57: Fontify script characters with a new face, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex bef4873 22/57: Set `reftex-set-cite-format' to biblatex or natbib, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 1de2359 13/57: Add new style/titlesec.el, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 01da194 23/57: ; * style/titletoc.el ("titletoc"): Use `TeX-arg-length'., Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 69fc320 27/57: Add a newline only if \label is inserted, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 343ca9c 36/57: Fix script unfontification bug, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 0e54895 34/57: Improve completion docs, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 436371c 31/57: Add completion-at-point support,
Tassilo Horn <=
- [AUCTeX-diffs] [elpa] externals/auctex e9c4b68 35/57: ; * doc/auctex.texi (Completion): Use @defun and not @deffn., Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 93b1163 50/57: * ChangeLog-preview: Change encoding to UTF-8., Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 4ebbf90 56/57: Make gitlog-to-changelog ignore release-commit, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 5af3c8e 15/57: Add \switchcolumn to paragraph commands, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex bfc7e90 16/57: Fix fontification for natbib compat macros, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex ccec850 24/57: Remove multi-level/invisible feature of font-latex-fontify-script, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex c3a21f2 04/57: Print only first line of the message in error overview, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 890163e 26/57: Bring back multi-level script font-locking, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 00df9a5 37/57: Check new custom option before activating RefTeX cite format, Tassilo Horn, 2017/01/11
- [AUCTeX-diffs] [elpa] externals/auctex 7ef680c 52/57: Refresh RELEASE file, Tassilo Horn, 2017/01/11