bug-auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#35074: 12.1.2; TeX-complete-symbol doesn't work in math mode for use


From: Arash Esbati
Subject: bug#35074: 12.1.2; TeX-complete-symbol doesn't work in math mode for user-defined command
Date: Wed, 03 Apr 2019 11:55:39 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50

Andrea Greselin <address@hidden> writes:

> I can't find a way to make AUCTeX complete user-defined commands in math mode.
>
> As an example, in the document below TeX-complete-symbol works outside
> of math mode, but if I prepend a dollar sign to the command name it
> doesn't complete it, returning `TeX-complete-symbol: Can’t find
> completion for "\rnd".`
>
> -------------------------------------------
> \documentclass{article}
>
> \newcommand{\rndvar}{X}
>
> \begin{document}
>
> \rnd%      TeX-complete-symbol works here
> $\rnd$%    but not here,
> $\rnd%     nor here.
>
> \end{document}
> -------------------------------------------
>
> I have posted a question on TeX.SE and I refer to the answer at
> https://tex.stackexchange.com/a/482631/35903 for a full (and better
> formatted) explanation of the faulty behaviour, which is the same as
> in my system. Basically, it is `LaTeX-math-list` not being updated
> with the name of the new command that appears to cause the issue.

Hi Andrea,

I've answered your question there.  But looking at the bug, here is how
to reproduce it.  Open this file, do `M-x toggle-debug-on-error RET',
eval the setq-form, then put point after `\rnd' and hit `C-M-i':

    \documentclass{article}
    \begin{document}
    \begin{verbatim}
    (setq LaTeX-math-list '((nil "rndvar" nil nil)))
    \end{verbatim}
    $\rnd$
    \end{document}

Emacs does the completion and throws this:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument stringp (if 
TeX-insert-braces "{}"))
  regexp-quote((if TeX-insert-braces "{}"))
  TeX-complete-symbol()
  funcall-interactively(TeX-complete-symbol)
  call-interactively(TeX-complete-symbol nil nil)
  command-execute(TeX-complete-symbol)
--8<---------------cut here---------------end--------------->8---

The issue is in the function `TeX-complete-symbol' which doesn't handle
functions passed as the fourth element of `TeX-complete-list' The
following patch should fix it:

--8<---------------cut here---------------start------------->8---
diff --git a/tex.el b/tex.el
index 3c3f1769..6cf2e487 100644
--- a/tex.el
+++ b/tex.el
@@ -3109,7 +3109,11 @@ Or alternatively:
     (when entry
       (if (numberp (nth 1 entry))
          (let* ((sub (nth 1 entry))
-                (close (nth 3 entry))
+                (close (if (and (nth 3 entry)
+                                 (listp (nth 3 entry))
+                                 (symbolp (car (nth 3 entry))))
+                            (eval (nth 3 entry))
+                          (nth 3 entry)))
                 (begin (match-beginning sub))
                 (end (match-end sub))
                 (pattern (TeX-match-buffer 0))
--8<---------------cut here---------------end--------------->8---

Can you please try it?  Here the complete function which you can eval
and then run the completion again.

--8<---------------cut here---------------start------------->8---
(defun TeX-complete-symbol ()
  "Perform completion on TeX/LaTeX symbol preceding point."
  (interactive "*")
  (let ((entry (TeX--complete-find-entry)))
    (when entry
      (if (numberp (nth 1 entry))
          (let* ((sub (nth 1 entry))
                 (close (if (and (nth 3 entry)
                                 (listp (nth 3 entry))
                                 (symbolp (car (nth 3 entry))))
                            (eval (nth 3 entry))
                          (nth 3 entry)))
                 (begin (match-beginning sub))
                 (end (match-end sub))
                 (pattern (TeX-match-buffer 0))
                 (symbol (buffer-substring begin end))
                 (list (funcall (nth 2 entry)))
                 (completion (try-completion symbol list))
                 (buf-name "*Completions*"))
            (cond ((eq completion t)
                   (and close
                        (not (looking-at (regexp-quote close)))
                        (insert close))
                   (let ((window (get-buffer-window buf-name)))
                     (when window (delete-window window))))
                  ((null completion)
                   (error "Can't find completion for \"%s\"" pattern))
                  ((not (string-equal symbol completion))
                   (delete-region begin end)
                   (insert completion)
                   (and close
                        (eq (try-completion completion list) t)
                        (not (looking-at (regexp-quote close)))
                        (insert close))
                   (let ((window (get-buffer-window buf-name)))
                     (when window (delete-window window))))
                  (t
                   (if (fboundp 'completion-in-region)
                       (completion-in-region begin end
                                             (all-completions symbol list nil))
                     (message "Making completion list...")
                     (let ((list (all-completions symbol list nil)))
                       (with-output-to-temp-buffer buf-name
                         (display-completion-list list)))
                     (set-window-dedicated-p (get-buffer-window buf-name) 'soft)
                     (message "Making completion list...done")))))
        (funcall (nth 1 entry))))))
--8<---------------cut here---------------end--------------->8---

Best, Arash





reply via email to

[Prev in Thread] Current Thread [Next in Thread]