Subject: Re: bug#22077: Possible bug in `reftex-what-index-tag'

From: Mosè Giordano <[email-masked]>
Date: Wed, 2 Dec 2015 23:48:06 +0100

Hi Arash,

2015-12-02 22:33 GMT+01:00 Arash Esbati <[email-masked]>:
> Hi all,
>
> please consider the following example:
>
> --8<---------------cut here---------------start------------->8---
> \documentclass{article}
>
> \usepackage{index}
> \newindex{aut}{adx}{and}{Name Index}
>
> \begin{document}
> `C-c C-m index RET aut RET' enters `\index[aut]' in buffer
> and exits with `(wrong-type-argument integer-or-marker-p nil)'.
> \end{document}
> --8<---------------cut here---------------end--------------->8---
>
> Debugger says:
>
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
>   reftex-what-index-tag()
>   TeX-arg-index(nil)
>   TeX-parse-argument(nil TeX-arg-index)
>   TeX-parse-arguments(([TeX-arg-index-tag] TeX-arg-index))
>   TeX-parse-macro("index" ([TeX-arg-index-tag] TeX-arg-index))
>   TeX-insert-macro("index")
>   call-interactively(TeX-insert-macro nil nil)
>   command-execute(TeX-insert-macro)
> --8<---------------cut here---------------end--------------->8---
>
> If I get this correctly, the problem is in `(match-end 1)' part of
> `reftex-what-index-tag' defined in `reftex-auc.el':
>
> --8<---------------cut here---------------start------------->8---
> (defun reftex-what-index-tag ()
>   ;; Look backward to find out what index the macro at point belongs to
>   (let ((macro (save-excursion
>                  (and (re-search-backward "\\\\[a-zA-Z*]+" nil t)
>                       (match-string 0))))
>         tag entry)
>     (when (and macro
>                (setq entry (assoc macro reftex-index-macro-alist)))
>       (setq tag (nth 1 entry))
>       (cond
>        ((stringp tag) tag)
>        ((integerp tag)
>         (save-excursion
>           (goto-char (match-end 1))
>           (or (reftex-nth-arg tag (nth 6 entry)) "idx")))
>        (t "idx")))))
> --8<---------------cut here---------------end--------------->8---
>
> I think it should be `(match-end 0)' since the last search had no
> parenthesized expression in regexp.  In short:
>
> --8<---------------cut here---------------start------------->8---
> diff --git a/lisp/textmodes/reftex-auc.el b/lisp/textmodes/reftex-auc.el
> index bbad065..151be59 100644
> --- a/lisp/textmodes/reftex-auc.el
> +++ b/lisp/textmodes/reftex-auc.el
> @@ -137,7 +137,7 @@ reftex-what-index-tag
>         ((stringp tag) tag)
>         ((integerp tag)
>          (save-excursion
> -          (goto-char (match-end 1))
> +          (goto-char (match-end 0))
>            (or (reftex-nth-arg tag (nth 6 entry)) "idx")))
>         (t "idx")))))
> --8<---------------cut here---------------end--------------->8---
>
> Any comments?  I could make a proper patch for this.

Yes, you're right, `goto-char' is called with nil argument.  And yes,
a proper patch would be useful, even if it's a one-liner change.  BTW,
you signed the copyright paper only for AUCTeX, should you want to
provide more substantial contributions for RefTeX you have to sign the
copyright paper for Emacs as well.

Bye,
Mosè