[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex e0bc78a500 23/39: Support in-buffer completion f
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex e0bc78a500 23/39: Support in-buffer completion for class/package names/options |
Date: |
Thu, 20 Jul 2023 04:21:50 -0400 (EDT) |
branch: externals/auctex
commit e0bc78a500c43ba3c9f6eb04ee104ab64f6d90bb
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>
Support in-buffer completion for class/package names/options
* latex.el (LaTeX-completion-documentclass-usepackage): New
function providing in-buffer completion for class/package names
and options.
(LaTeX--arguments-completion-at-point): Use function accordingly.
---
latex.el | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 92 insertions(+), 1 deletion(-)
diff --git a/latex.el b/latex.el
index cf2518b2d0..b287604e33 100644
--- a/latex.el
+++ b/latex.el
@@ -7597,6 +7597,91 @@ COLLECTION is an list of strings."
(lambda (_)
collection)))))
+(defun LaTeX-completion-documentclass-usepackage (entry)
+ "Return completion candidates for arguments of \\usepackage macro.
+ENTRY is the value returned by `LaTeX-what-macro'. This function
+provides completion for package names if point is inside the
+mandatory argument and package options if inside the first
+optional argument."
+ (let ((cls-or-sty (if (member (car entry) '("usepackage" "RequirePackage"
+ "RequirePackageWithOptions"))
+ 'sty
+ 'cls)))
+ (cond ((and (eq (nth 3 entry) 'mandatory)
+ (eq TeX-arg-input-file-search t))
+ (if (eq cls-or-sty 'cls)
+ (progn
+ (unless LaTeX-global-class-files
+ (let ((TeX-file-extensions '("cls")))
+ (message "Searching for LaTeX classes...")
+ (setq LaTeX-global-class-files
+ (mapcar #'list (TeX-search-files-by-type 'texinputs
'global t t)))
+ (message "Searching for LaTeX classes...done")))
+ (LaTeX-completion-candidates-completing-read
+ LaTeX-global-class-files))
+ (unless LaTeX-global-package-files
+ (let ((TeX-file-extensions '("sty")))
+ (message "Searching for LaTeX packages...")
+ (setq LaTeX-global-package-files
+ (mapcar #'list (TeX-search-files-by-type 'texinputs
'global t t)))
+ (message "Searching for LaTeX packages...done")))
+ (LaTeX-completion-candidates-completing-read-multiple
+ LaTeX-global-package-files)))
+ ;; We have to be more careful for the optional argument
+ ;; since the macros can look like this:
+ ;; \usepackage[opt1]{mand}[opt2]. So we add an extra check
+ ;; if we are inside the first optional arg:
+ ((and (eq (nth 3 entry) 'optional)
+ (= (nth 2 entry) 1))
+ (let ((syntax (TeX-search-syntax-table ?\[ ?\]))
+ style style-opts)
+ ;; We have to find out about the package/class name:
+ (save-excursion
+ (with-syntax-table syntax
+ (condition-case nil
+ (let ((forward-sexp-function nil))
+ (up-list))
+ (error nil)))
+ (skip-chars-forward "^[:alnum:]")
+ (setq style (thing-at-point 'symbol t)))
+ ;; Load the style file; may fail but that's Ok for us
+ (TeX-load-style style)
+ ;; Now we have to find out how the options are available:
+ ;; This is usually a variable called
+ ;; `LaTeX-<class|package>-package-options'. If it is a
+ ;; function, then the options are stored either in a
+ ;; variable or a function called
+ ;; `LaTeX-<class|package>-package-options-list:'
+ (when (setq style-opts
+ (intern-soft (format
+ (concat "LaTeX-%s-"
+ (if (eq cls-or-sty 'cls)
+ "class"
+ "package")
+ "-options")
+ style)))
+ (cond ((and (boundp style-opts)
+ (symbol-value style-opts))
+ (LaTeX-completion-candidates-completing-read-multiple
+ (symbol-value style-opts)))
+ ((and (setq style-opts
+ (intern-soft (format
+ (concat "LaTeX-%s-"
+ (if (eq cls-or-sty 'cls)
+ "class"
+ "package")
+ "-options-list")
+ style)))
+ (boundp style-opts)
+ (symbol-value style-opts))
+ (LaTeX-completion-candidates-key-val
+ (symbol-value style-opts)))
+ ((fboundp style-opts)
+ (LaTeX-completion-candidates-key-val
+ (funcall style-opts)))
+ (t nil)))))
+ (t nil))))
+
(defun LaTeX-completion-parse-args (entry)
"Return the match of buffer position ENTRY with AUCTeX macro definitions.
ENTRY is generated by the function `LaTeX-what-macro'. This
@@ -7811,7 +7896,13 @@ function `TeX--completion-at-point' which should come
first in
(when (and (LaTeX-completion-find-argument-boundries)
(not (nth 4 (syntax-ppss))))
(let ((entry (LaTeX-what-macro)))
- (cond ((or (and entry
+ (cond ((and entry
+ (member (car entry) '("usepackage" "RequirePackage"
+ "RequirePackageWithOptions"
+ "documentclass" "LoadClass"
+ "LoadClassWithOptions")))
+ (LaTeX-completion-documentclass-usepackage entry))
+ ((or (and entry
(eq (nth 1 entry) 'mac)
(assoc (car entry) (TeX-symbol-list)))
(and entry
- [elpa] externals/auctex updated (9d47b0a1bd -> 1c3360b162), Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 11e9dbfdf3 30/39: Track last change for \newtheorem macro in styles, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex d6fb3c58ce 01/39: Be more resilient when parsing arguments, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 22ba857c53 06/39: Improve fontification within shortvrb delimiters, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 4bcad4772d 15/39: Simplify handling of package options, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex b4c27dd36b 02/39: Lift required GNU Emacs version to 26.1, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex e0bc78a500 23/39: Support in-buffer completion for class/package names/options,
Tassilo Horn <=
- [elpa] externals/auctex b55368f75f 38/39: Merge remote-tracking branch 'origin/master' into externals/auctex, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 2017d97b0e 09/39: Rewrite *-unload-hook to *-unload-function, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex c67f5d75b2 14/39: ; * Makefile.in (STYLESRC): Fix last change., Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 1c3360b162 39/39: Release GNU AUCTeX 13.2.1, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex cdd0cbf33a 03/39: Add new style/soul.el, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 6d34e1f1ae 34/39: Simplify implementation of style/paralist.el, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex fe42de7cf6 26/39: Obey buffer-local value of TeX-error-overview-open-after-TeX-run, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 38e729a75f 28/39: * latex.el (LaTeX-common-initialization): Replace `TeX-arg-eval'., Tassilo Horn, 2023/07/20
- [elpa] externals/auctex da28858e46 20/39: Improve handling of beamer class options, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 7a347cd394 10/39: Remove compatibility code for Emacs<26, Tassilo Horn, 2023/07/20