GNU bug report logs - #72080
imenu returns different lists in emacs-news-mode and emacs-news-view-mode

Previous Next

Package: emacs;

Reported by: Siyuan Chen <chansey97 <at> gmail.com>

Date: Fri, 12 Jul 2024 17:53:01 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 72080 in the body.
You can then email your comments to 72080 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#72080; Package emacs. (Fri, 12 Jul 2024 17:53:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Siyuan Chen <chansey97 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 12 Jul 2024 17:53:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Siyuan Chen <chansey97 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: imenu returns different lists in emacs-news-mode and
 emacs-news-view-mode
Date: Sat, 13 Jul 2024 01:52:11 +0800
[Message part 1 (text/plain, inline)]
Reproduce steps:

1 Clone Emacs source code from https://github.com/emacs-mirror/emacs

2. Emacs -Q (Emacs 29.3 on Windows)

3. Open etc/NEWS.30 from the Emacs source code (by default Emacs will use
emacs-news-mode)

4. M-x imenu and press TAB to complete

Emacs shows 515 possible completions.

6. M-x emacs-news-view-mode

7. M-x imenu and press TAB to complete

Emacs shows 202 possible completions.

This is the problem, i.e. emacs-news-mode and emacs-news-view-mode return
different imenu lists.

The Background:

I am reading Emacs NEWS and using the "imenu-list" package to display the
outline of the NEWS as a side window since NEWS are often very long. It
works well in emacs-news-mode, but lacks many entries in
emacs-news-view-mode. BTW the emacs-news-view-mode is nice because it
allows button click symbol references in the buffer..

In step 4 and step 7, you can do M-x eval-expression

```
(progn
  (require 'imenu)
  (setq message-log-max t)
  (let ((inhibit-read-only t))
    (with-current-buffer "*Messages*" (erase-buffer)))
  (pp (imenu--make-index-alist)))
```
and save the *Messages* buffer to two files respectively, e.g. news-mode.txt
and news-view-mode.txt. You will find that these two files are different.
The news-view-mode.txt lacks many imenu entries.

P.s. This issue only occurs for NEWS.30. It is OK for NEWS.29.

Thanks.

Best regards,
Siyuan Chen
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72080; Package emacs. (Sat, 13 Jul 2024 08:18:01 GMT) Full text and rfc822 format available.

Message #8 received at 72080 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Siyuan Chen <chansey97 <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 72080 <at> debbugs.gnu.org
Subject: Re: bug#72080: imenu returns different lists in emacs-news-mode and
 emacs-news-view-mode
Date: Sat, 13 Jul 2024 11:17:08 +0300



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72080; Package emacs. (Sat, 13 Jul 2024 09:12:02 GMT) Full text and rfc822 format available.

Message #11 received at 72080 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Siyuan Chen <chansey97 <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 72080 <at> debbugs.gnu.org
Subject: Re: bug#72080: imenu returns different lists in emacs-news-mode and
 emacs-news-view-mode
Date: Sat, 13 Jul 2024 12:08:53 +0300
> From: Siyuan Chen <chansey97 <at> gmail.com>
> Date: Sat, 13 Jul 2024 01:52:11 +0800
> 
> Reproduce steps:
> 
> 1 Clone Emacs source code from https://github.com/emacs-mirror/emacs 
> 
> 2. Emacs -Q (Emacs 29.3 on Windows)
> 
> 3. Open etc/NEWS.30 from the Emacs source code (by default Emacs will use emacs-news-mode)
> 
> 4. M-x imenu and press TAB to complete
> 
> Emacs shows 515 possible completions. 
> 
> 6. M-x emacs-news-view-mode
> 
> 7. M-x imenu and press TAB to complete
> 
> Emacs shows 202 possible completions. 
> 
> This is the problem, i.e. emacs-news-mode and emacs-news-view-mode return different imenu lists.

This happens because emacs-news-view-mode derives from special-mode,
and therefore has a different syntax table.  Which has the effect of
duping imenu--generic-function into thinking some of the NEWS entries
are in comments, and so it ignores them:

		  ;; Insert the item unless it is already present.
		  (unless (or (member item (cdr menu))
                              (and imenu-generic-skip-comments-and-strings
                                   (save-excursion
                                     (goto-char start) (nth 8 (syntax-ppss)))))
		    (setcdr menu
			    (cons item (cdr menu)))))

Note the call to syntax-ppss there: it returns nil in 8th entry in
emacs-news-mode when point is, e.g., on the final ^L in NEWS, but
non-nil in emacs-news-view-mode.

The simple and naïve change below seems to fix that.  The only problem
with it is that one cannot move through the buffer with SPC, DEL, '<'
etc.  For some reason I cannot get emacs-news-view-mode inherit the
keymap of special-mode, nor even use its own keymap I defined in a
defvar emacs-news-view-mode-map.  Stefan, any reason why a simple
definition of emacs-news-view-mode-map doesn't work, as the ELisp
manual promises it should (where it described define-derived-mode)?

Also, any idea why syntax-ppss thinks the final ^L in NEWS, here:

  ---
  *** Emacs on MS-Windows now supports the ':stipple' face attribute.

  ^L
  ----------------------------------------------------------------------
  This file is part of GNU Emacs.

is in a comment when emacs-news-view-mode inherits from special-mode?

Btw, I find our syntax-table introspection features not very helpful
in these situations.  Once I figured out that syntax-ppss produces
different results in these two modes, all the rest was pure guesswork,
with no real way of investigating the differences and their reason(s).
Do we have any ways of comparing two syntax tables and showing the
differences in human-readable form?  Do we have a way of showing the
source(s) f a syntax-table's information, like where it inherited from
another and where it was modified by explicit modify-syntax-entry
calls?  Do we have a way of making one mode use the syntax table of
another mode without having a variable which holds the latter?  I
needed all of these to investigate in this case, and was finally
forced to treat the issue as a kind of "black box", making
more-or-less random changes and looking at the results, which is very
frustrating and a terrible waste of time...


diff --git a/lisp/textmodes/emacs-news-mode.el b/lisp/textmodes/emacs-news-mode.el
index 1dd017a..c87e7fa 100644
--- a/lisp/textmodes/emacs-news-mode.el
+++ b/lisp/textmodes/emacs-news-mode.el
@@ -107,7 +107,7 @@ emacs-news-mode
   (emacs-news--mode-common))
 
 ;;;###autoload
-(define-derived-mode emacs-news-view-mode special-mode "NEWS"
+(define-derived-mode emacs-news-view-mode emacs-news-mode "NEWS"
   "Major mode for viewing the Emacs NEWS file."
   (setq buffer-read-only t)
   (emacs-news--buttonize)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72080; Package emacs. (Sat, 13 Jul 2024 13:34:02 GMT) Full text and rfc822 format available.

Message #14 received at 72080 <at> debbugs.gnu.org (full text, mbox):

From: Siyuan Chen <chansey97 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 72080 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#72080: imenu returns different lists in emacs-news-mode and
 emacs-news-view-mode
Date: Sat, 13 Jul 2024 21:33:01 +0800
[Message part 1 (text/plain, inline)]
I installed the patch and the bug was fixed.

Thanks.

On Sat, Jul 13, 2024 at 5:08 PM Eli Zaretskii <eliz <at> gnu.org> wrote:

> > From: Siyuan Chen <chansey97 <at> gmail.com>
> > Date: Sat, 13 Jul 2024 01:52:11 +0800
> >
> > Reproduce steps:
> >
> > 1 Clone Emacs source code from https://github.com/emacs-mirror/emacs
> >
> > 2. Emacs -Q (Emacs 29.3 on Windows)
> >
> > 3. Open etc/NEWS.30 from the Emacs source code (by default Emacs will
> use emacs-news-mode)
> >
> > 4. M-x imenu and press TAB to complete
> >
> > Emacs shows 515 possible completions.
> >
> > 6. M-x emacs-news-view-mode
> >
> > 7. M-x imenu and press TAB to complete
> >
> > Emacs shows 202 possible completions.
> >
> > This is the problem, i.e. emacs-news-mode and emacs-news-view-mode
> return different imenu lists.
>
> This happens because emacs-news-view-mode derives from special-mode,
> and therefore has a different syntax table.  Which has the effect of
> duping imenu--generic-function into thinking some of the NEWS entries
> are in comments, and so it ignores them:
>
>                   ;; Insert the item unless it is already present.
>                   (unless (or (member item (cdr menu))
>                               (and imenu-generic-skip-comments-and-strings
>                                    (save-excursion
>                                      (goto-char start) (nth 8
> (syntax-ppss)))))
>                     (setcdr menu
>                             (cons item (cdr menu)))))
>
> Note the call to syntax-ppss there: it returns nil in 8th entry in
> emacs-news-mode when point is, e.g., on the final ^L in NEWS, but
> non-nil in emacs-news-view-mode.
>
> The simple and naïve change below seems to fix that.  The only problem
> with it is that one cannot move through the buffer with SPC, DEL, '<'
> etc.  For some reason I cannot get emacs-news-view-mode inherit the
> keymap of special-mode, nor even use its own keymap I defined in a
> defvar emacs-news-view-mode-map.  Stefan, any reason why a simple
> definition of emacs-news-view-mode-map doesn't work, as the ELisp
> manual promises it should (where it described define-derived-mode)?
>
> Also, any idea why syntax-ppss thinks the final ^L in NEWS, here:
>
>   ---
>   *** Emacs on MS-Windows now supports the ':stipple' face attribute.
>
>   ^L
>   ----------------------------------------------------------------------
>   This file is part of GNU Emacs.
>
> is in a comment when emacs-news-view-mode inherits from special-mode?
>
> Btw, I find our syntax-table introspection features not very helpful
> in these situations.  Once I figured out that syntax-ppss produces
> different results in these two modes, all the rest was pure guesswork,
> with no real way of investigating the differences and their reason(s).
> Do we have any ways of comparing two syntax tables and showing the
> differences in human-readable form?  Do we have a way of showing the
> source(s) f a syntax-table's information, like where it inherited from
> another and where it was modified by explicit modify-syntax-entry
> calls?  Do we have a way of making one mode use the syntax table of
> another mode without having a variable which holds the latter?  I
> needed all of these to investigate in this case, and was finally
> forced to treat the issue as a kind of "black box", making
> more-or-less random changes and looking at the results, which is very
> frustrating and a terrible waste of time...
>
>
> diff --git a/lisp/textmodes/emacs-news-mode.el
> b/lisp/textmodes/emacs-news-mode.el
> index 1dd017a..c87e7fa 100644
> --- a/lisp/textmodes/emacs-news-mode.el
> +++ b/lisp/textmodes/emacs-news-mode.el
> @@ -107,7 +107,7 @@ emacs-news-mode
>    (emacs-news--mode-common))
>
>  ;;;###autoload
> -(define-derived-mode emacs-news-view-mode special-mode "NEWS"
> +(define-derived-mode emacs-news-view-mode emacs-news-mode "NEWS"
>    "Major mode for viewing the Emacs NEWS file."
>    (setq buffer-read-only t)
>    (emacs-news--buttonize)
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72080; Package emacs. (Sun, 14 Jul 2024 12:58:01 GMT) Full text and rfc822 format available.

Message #17 received at 72080 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 72080 <at> debbugs.gnu.org, Siyuan Chen <chansey97 <at> gmail.com>
Subject: Re: bug#72080: imenu returns different lists in emacs-news-mode and
 emacs-news-view-mode
Date: Sun, 14 Jul 2024 08:57:37 -0400
> For some reason I cannot get emacs-news-view-mode inherit the
> keymap of special-mode, nor even use its own keymap I defined in a
> defvar emacs-news-view-mode-map.  Stefan, any reason why a simple
> definition of emacs-news-view-mode-map doesn't work, as the ELisp
> manual promises it should (where it described define-derived-mode)?

Can't think of a reason, no.

> Also, any idea why syntax-ppss thinks the final ^L in NEWS, here:
>
>   ---
>   *** Emacs on MS-Windows now supports the ':stipple' face attribute.
>
>   ^L
>   ----------------------------------------------------------------------
>   This file is part of GNU Emacs.
>
> is in a comment when emacs-news-view-mode inherits from special-mode?

No, sorry.

> Do we have a way of making one mode use the syntax table of another
> mode without having a variable which holds the latter?

`C-h o` says:

    define-derived-mode is an autoloaded Lisp macro in ‘derived.el’.
    [...]
    KEYWORD-ARGS:
    [...]
               :syntax-table TABLE
                       Use TABLE instead of the default
                       (CHILD-syntax-table).  A nil value means to
                       simply use the same syntax-table as the parent.

so `:syntax-table` should be able to do that.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72080; Package emacs. (Sun, 14 Jul 2024 13:19:01 GMT) Full text and rfc822 format available.

Message #20 received at 72080 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 72080 <at> debbugs.gnu.org, chansey97 <at> gmail.com
Subject: Re: bug#72080: imenu returns different lists in emacs-news-mode and
 emacs-news-view-mode
Date: Sun, 14 Jul 2024 16:16:09 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Siyuan Chen <chansey97 <at> gmail.com>,  72080 <at> debbugs.gnu.org
> Date: Sun, 14 Jul 2024 08:57:37 -0400
> 
> > For some reason I cannot get emacs-news-view-mode inherit the
> > keymap of special-mode, nor even use its own keymap I defined in a
> > defvar emacs-news-view-mode-map.  Stefan, any reason why a simple
> > definition of emacs-news-view-mode-map doesn't work, as the ELisp
> > manual promises it should (where it described define-derived-mode)?
> 
> Can't think of a reason, no.

But it doesn't work.  I'm puzzled why.  Any suggestions where to look?

> > Do we have a way of making one mode use the syntax table of another
> > mode without having a variable which holds the latter?
> 
> `C-h o` says:
> 
>     define-derived-mode is an autoloaded Lisp macro in ‘derived.el’.
>     [...]
>     KEYWORD-ARGS:
>     [...]
>                :syntax-table TABLE
>                        Use TABLE instead of the default
>                        (CHILD-syntax-table).  A nil value means to
>                        simply use the same syntax-table as the parent.
> 
> so `:syntax-table` should be able to do that.

Sure, but TABLE should be a variable here.  What I wanted was to tell
define-derived-mode to use the syntax table of a given other mode
which has no such variable.  Would something like this:

  :syntax-table (with-temp-buffer
                  (emacs-news-mode)
		  (syntax-table))

have worked?




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 20 Jul 2024 09:36:01 GMT) Full text and rfc822 format available.

Notification sent to Siyuan Chen <chansey97 <at> gmail.com>:
bug acknowledged by developer. (Sat, 20 Jul 2024 09:36:02 GMT) Full text and rfc822 format available.

Message #25 received at 72080-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 72080-done <at> debbugs.gnu.org, chansey97 <at> gmail.com
Subject: Re: bug#72080: imenu returns different lists in emacs-news-mode and
 emacs-news-view-mode
Date: Sat, 20 Jul 2024 12:34:55 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Siyuan Chen <chansey97 <at> gmail.com>,  72080 <at> debbugs.gnu.org
> Date: Sun, 14 Jul 2024 08:57:37 -0400
> 
> > For some reason I cannot get emacs-news-view-mode inherit the
> > keymap of special-mode, nor even use its own keymap I defined in a
> > defvar emacs-news-view-mode-map.  Stefan, any reason why a simple
> > definition of emacs-news-view-mode-map doesn't work, as the ELisp
> > manual promises it should (where it described define-derived-mode)?
> 
> Can't think of a reason, no.
> 
> > Also, any idea why syntax-ppss thinks the final ^L in NEWS, here:
> >
> >   ---
> >   *** Emacs on MS-Windows now supports the ':stipple' face attribute.
> >
> >   ^L
> >   ----------------------------------------------------------------------
> >   This file is part of GNU Emacs.
> >
> > is in a comment when emacs-news-view-mode inherits from special-mode?
> 
> No, sorry.

OK, so I fixed that on the emacs-30 branch as best I could, and I'm
therefore closing this bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 17 Aug 2024 11:24:15 GMT) Full text and rfc822 format available.

This bug report was last modified 208 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.