Function: LaTeX-completion-documentclass-usepackage
LaTeX-completion-documentclass-usepackage is a byte-compiled function
defined in latex.el.
Signature
(LaTeX-completion-documentclass-usepackage ENTRY)
Documentation
Return completion candidates for \usepackage and \documentclass arguments.
ENTRY is the value returned by LaTeX-what-macro. This function
provides completion for class/package names if point is inside
the mandatory argument and class/package options if inside the
first optional argument. The completion for class/package names
is provided only if the value of TeX-arg-input-file-search is
set to t.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-completion-documentclass-usepackage (entry)
"Return completion candidates for \\usepackage and \\documentclass arguments.
ENTRY is the value returned by `LaTeX-what-macro'. This function
provides completion for class/package names if point is inside
the mandatory argument and class/package options if inside the
first optional argument. The completion for class/package names
is provided only if the value of `TeX-arg-input-file-search' is
set to t."
(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))))