Function: TeX-doc
TeX-doc is an interactive and byte-compiled function defined in
tex.el.
Signature
(TeX-doc &optional NAME)
Documentation
Display documentation for string NAME.
NAME may be a package, a command, or a document.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex.el
(defun TeX-doc (&optional name)
"Display documentation for string NAME.
NAME may be a package, a command, or a document."
(interactive)
(let (docs)
;; Build the lists of available documentation used for completion.
(dolist (elt TeX-doc-backend-alist)
(when (or (eq t (nth 1 elt))
(memq major-mode (nth 1 elt)))
(let ((completions (funcall (nth 2 elt))))
(unless (null completions)
(cl-pushnew (cons completions (nth 0 elt)) docs :test #'equal)))))
(if (null docs)
(progn
(if (executable-find "texdoc")
;; Fallback if we did not find anything via the backend list.
(let ((doc (read-from-minibuffer "Input for `texdoc': ")))
(when doc (call-process "texdoc" nil 0 nil "--view" doc)))
;; Give up.
(message "No documentation found")))
;; Ask the user about the package, command, or document.
(when (and (called-interactively-p 'any)
(or (not name) (string= name "")))
(let ((symbol (thing-at-point 'symbol))
contained completions)
;; Is the symbol at point contained in the lists of available
;; documentation?
(setq contained (catch 'found
(dolist (elt docs)
(when (member symbol (car elt))
(throw 'found t)))))
;; Setup completion list in a format suitable for `completing-read'.
(dolist (elt docs)
;; FIXME: Probably not needed!
(setq completions (nconc (mapcar #'list (car elt)) completions)))
;; Query user.
(setq name (completing-read
(if contained
(format-prompt "Package, command, or document"
symbol)
"Package, command, or document: ")
completions nil nil nil nil symbol))))
(if (not name)
(message "No documentation specified")
;; XXX: Provide way to choose in case a symbol can be found in
;; more than one backend.
(let* ((backend (catch 'found
(dolist (elt docs)
(when (member name (car elt))
(throw 'found (cdr elt)))))))
(if backend
(funcall (nth 3 (assoc backend TeX-doc-backend-alist)) name)
(message "Documentation not found")))))))