From a0a1738ff67b129e08f1a9ccd12b25ec8f936f09 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Mon, 14 Oct 2024 21:38:33 -0700 Subject: [PATCH] Some more changes --- elisp/latex-help.el | 30 +++++++++++++++++++++++------- init.el | 15 ++++++--------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/elisp/latex-help.el b/elisp/latex-help.el index ee7b9c6..555939b 100644 --- a/elisp/latex-help.el +++ b/elisp/latex-help.el @@ -564,8 +564,7 @@ which to use. If NODE is non-nil, use that instead." ;;;###autoload (defun latex-help-texdoc (name) "Lookup NAME in the texdoc cache. -When used interactively, prompt for NAME. If DIR is nil, it will be looked up -in the texdoc cache." +When used interactively, prompt for NAME." (interactive (list (latex-help--prompt-texdoc-entry))) (latex-help--maybe-init-caches) (when-let ((file (latex-help--texdoc-prompt-for-entry-file name))) @@ -634,22 +633,39 @@ documentation for that thing." "Get help with LaTeX. Prompt the user for an info topic or texdoc file, then open that thing." (interactive) - (let ((prompts)) + (let ((prompts) + (tap (latex-help--get-thing-at-point)) + (def-entry nil) + (def-name nil)) (latex-help--maybe-init-caches) (cl-flet ((add-cache-for-type (type) (dolist (entry (latex-help--get-cache-for-type type)) (push (format "(Info) %s - %s" (capitalize (symbol-name type)) (car entry)) - prompts)))) + prompts) + (when (and (eq type (cdr tap)) + (equal (car entry) (car tap))) + (setq def-entry (car prompts) + def-name (car entry)))))) (add-cache-for-type 'command) (add-cache-for-type 'package) (add-cache-for-type 'class) (add-cache-for-type 'environment) (dolist (entry latex-help--texdoc-cache) - (push (format "(Texdoc) %s" entry) prompts)) - (when-let ((ans (completing-read "LaTeX Help: " prompts - nil t nil 'latex-help--general-history)) + (push (format "(Texdoc) %s" entry) prompts) + (when (and (member (cdr tap) '(class package environment)) + (equal entry (car tap))) + (setq def-entry (car prompts) + def-name entry))) + (when-let ((ans (completing-read (format "LaTeX Help%s: " + (if def-name + (format " (default %s)" + def-name) + "")) + prompts + nil t nil 'latex-help--general-history + def-entry)) ((not (zerop (length ans))))) (if (string-prefix-p "(Texdoc) " ans) (latex-help-texdoc (seq-subseq ans (length "(Texdoc) "))) diff --git a/init.el b/init.el index 9862584..2bf3659 100644 --- a/init.el +++ b/init.el @@ -1119,7 +1119,7 @@ otherwise, call `bibtex-find-text'." (LaTeX-mode . LaTeX-math-mode) (LaTeX-mode . my/-setup-LaTeX-mode)) :bind (:map TeX-mode-map - ("C-c ?" . latex-help-texdoc)) + ("C-c ?" . latex-help)) :init (add-to-list 'major-mode-remap-alist '(plain-tex-mode . plain-TeX-mode)) (add-to-list 'major-mode-remap-alist '(latex-mode . LaTeX-mode)) @@ -1130,14 +1130,11 @@ otherwise, call `bibtex-find-text'." (add-to-list 'auto-mode-alist '("/\\.latexmkrc\\'" . perl-mode)) :config (defun my/-auctex-texdoc-setup-env (oldfun &rest args) - (let ((process-environment)) - (if (display-graphic-p) - (progn (setenv "MDVIEWER_texdoc" "emacsclient") - (setenv "PDFVIEWER_texdoc" "emacsclient") - (setenv "PAGER_texdoc" "emacsclient")) - (setenv "MDVIEWER_texdoc" "emacsclient -nw") - (setenv "PDFVIEWER_texdoc" "evince") - (setenv "PAGER_texdoc" "emacsclient -nw")) + (let ((process-environment process-environment) + (emacs-cmd (concat "emacsclient" (and (not (display-graphic-p)) " -nw")))) + (setenv "PDFVIEWER_texdoc" "evince") + (setenv "MDVIEWER_texdoc" emacs-cmd) + (setenv "PAGER_texdoc" emacs-cmd) (apply oldfun args))) (advice-add 'TeX-documentation-texdoc :around 'my/-auctex-texdoc-setup-env) (defun my/-setup-LaTeX-mode ()