all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Siyuan Chen <chansey97@gmail.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 72080@debbugs.gnu.org
Subject: bug#72080: imenu returns different lists in emacs-news-mode and emacs-news-view-mode
Date: Sat, 13 Jul 2024 12:08:53 +0300	[thread overview]
Message-ID: <864j8tlkuy.fsf@gnu.org> (raw)
In-Reply-To: <CAHWTsY=y_VbMn12-RV8AYqcdv4UdR+kRXmGDzN36gBkV7GcvXg@mail.gmail.com> (message from Siyuan Chen on Sat, 13 Jul 2024 01:52:11 +0800)

> From: Siyuan Chen <chansey97@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)





  parent reply	other threads:[~2024-07-13  9:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12 17:52 bug#72080: imenu returns different lists in emacs-news-mode and emacs-news-view-mode Siyuan Chen
2024-07-13  8:17 ` Eli Zaretskii
2024-07-13  9:08 ` Eli Zaretskii [this message]
2024-07-13 13:33   ` Siyuan Chen
2024-07-14 12:57   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-14 13:16     ` Eli Zaretskii
2024-07-20  9:34     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=864j8tlkuy.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=72080@debbugs.gnu.org \
    --cc=chansey97@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.