branch: externals/auctex
commit 377a97a2434fab69bf9e91457de94ad33c09b548
Author: Tassilo Horn <[email protected]>
Commit: Tassilo Horn <[email protected]>
Completion for math macros
* latex.el (LaTeX--after-math-macro-prefix-p): New function.
(LaTeX-common-initialization): Use it for new TeX-complete-list entry.
* tex.el (TeX-complete-list): Also allow match-data setting predicates in
entries.
(TeX-complete-symbol,TeX--completion-at-point): Adapt to new possibility.
---
latex.el | 18 +++++++++++++++++-
tex.el | 14 ++++++++++----
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/latex.el b/latex.el
index e5601fb..6960749 100644
--- a/latex.el
+++ b/latex.el
@@ -5966,6 +5966,17 @@ i.e. you do _not_ have to cater for this yourself by
adding \\\\' or $."
:type '(repeat regexp)
:group 'TeX-command)
+(defun LaTeX--after-math-macro-prefix-p ()
+ "Return non-nil if point is after a macro prefix in math mode.
+Also sets `match-data' so that group 1 is the already typed
+prefix.
+
+For example, in $a + \a| - 17$ with | denoting point, the
+function would return non-nil and `(match-string 1)' would return
+\"a\" afterwards."
+ (and (texmathp)
+ (TeX-looking-at-backward "\\\\\\([a-zA-Z]*\\)")))
+
(defun LaTeX-common-initialization ()
"Common initialization for LaTeX derived modes."
(VirTeX-common-initialization)
@@ -6038,7 +6049,12 @@ i.e. you do _not_ have to cater for this yourself by
adding \\\\' or $."
("\\\\renewenvironment\\*?{\\([A-Za-z]*\\)"
1 LaTeX-environment-list-filtered "}")
("\\\\\\(this\\)?pagestyle{\\([A-Za-z]*\\)"
- 2 LaTeX-pagestyle-list "}"))
+ 2 LaTeX-pagestyle-list "}")
+ (LaTeX--after-math-macro-prefix-p
+ 1 (lambda ()
+ (append (mapcar #'cadr LaTeX-math-list)
+ (mapcar #'cadr LaTeX-math-default)))
+ (if TeX-insert-braces "{}")))
TeX-complete-list))
(LaTeX-add-environments
diff --git a/tex.el b/tex.el
index ac81b74..894e076 100644
--- a/tex.el
+++ b/tex.el
@@ -3143,8 +3143,10 @@ Expert %s are completed depending on
`TeX-complete-expert-commands'."
Each entry is a list with the following elements:
-0. Regexp matching the preceding text.
-1. A number indicating the subgroup in the regexp containing the text.
+0. Regexp matching the preceding text or a predicate of arity 0
+which checks its applicability and sets `match-data'.
+1. A number indicating the subgroup in the regexp containing the
+text.
2. A function returning an alist of possible completions.
3. Text to append after a succesful completion.
@@ -3161,7 +3163,9 @@ Or alternatively:
(while list
(setq entry (car list)
list (cdr list))
- (if (TeX-looking-at-backward (car entry) 250)
+ (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))
@@ -3210,7 +3214,9 @@ See `completion-at-point-functions'."
(while list
(setq entry (car list)
list (cdr list))
- (if (TeX-looking-at-backward (car entry) 250)
+ (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))