* bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES
@ 2023-05-07 9:49 Damien Cassou
2023-05-07 10:52 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Damien Cassou @ 2023-05-07 9:49 UTC (permalink / raw)
To: 63345
Hi,
The function `provided-mode-derived-p` (used by `derived-mode-p`) has
the code below. The first 3 lines of the function takes care of
converting the first argument MODE if it is an alias (as
`javascript-mode` is an alias for `js-mode`). This works great when
calling the function this way:
(provided-mode-derived-p 'javascript-mode 'prog-mode)
⇒ prog-mode
But if the second argument MODES contains an alias, the code has no
conversion mechanism and the line below returns nil even though I
expect it to return non-nil:
(provided-mode-derived-p 'javacript-mode 'javascript-mode)
⇒ nil
Is that a bug?
(defun provided-mode-derived-p (mode &rest modes)
"Non-nil if MODE is derived from one of MODES.
Uses the `derived-mode-parent' property of the symbol to trace backwards.
If you just want to check `major-mode', use `derived-mode-p'."
;; If MODE is an alias, then look up the real mode function first.
(when-let ((alias (symbol-function mode)))
(when (symbolp alias)
(setq mode alias)))
(while
(and
(not (memq mode modes))
(let* ((parent (get mode 'derived-mode-parent))
(parentfn (symbol-function parent)))
(setq mode (if (and parentfn (symbolp parentfn)) parentfn parent)))))
mode)
--
Damien Cassou
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES
2023-05-07 9:49 bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES Damien Cassou
@ 2023-05-07 10:52 ` Eli Zaretskii
2023-05-07 14:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-05-07 10:52 UTC (permalink / raw)
To: Damien Cassou, Stefan Monnier; +Cc: 63345
> From: Damien Cassou <damien@cassou.me>
> Date: Sun, 07 May 2023 11:49:37 +0200
>
> The function `provided-mode-derived-p` (used by `derived-mode-p`) has
> the code below. The first 3 lines of the function takes care of
> converting the first argument MODE if it is an alias (as
> `javascript-mode` is an alias for `js-mode`). This works great when
> calling the function this way:
>
> (provided-mode-derived-p 'javascript-mode 'prog-mode)
> ⇒ prog-mode
>
> But if the second argument MODES contains an alias, the code has no
> conversion mechanism and the line below returns nil even though I
> expect it to return non-nil:
>
> (provided-mode-derived-p 'javacript-mode 'javascript-mode)
> ⇒ nil
>
> Is that a bug?
Adding Stefan.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES
2023-05-07 10:52 ` Eli Zaretskii
@ 2023-05-07 14:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-07 14:35 ` Damien Cassou
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-05-07 14:23 UTC (permalink / raw)
To: Damien Cassou; +Cc: Eli Zaretskii, 63345
Hi Damien,
>> (provided-mode-derived-p 'javacript-mode 'javascript-mode)
>> ⇒ nil
>> Is that a bug?
I'd put it into "not a bug" because there really is a difference between
a mode and an alias to a mode (e.g. you can expect a mode to have
matching `<mode>-map`, `<mode>-hook`, ... vars).
But admittedly, this is a messy area.
What was the original scenario where you bumped into this problem?
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES
2023-05-07 14:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-05-07 14:35 ` Damien Cassou
2023-05-07 21:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 7+ messages in thread
From: Damien Cassou @ 2023-05-07 14:35 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Eli Zaretskii, 63345
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> What was the original scenario where you bumped into this problem?
The jinx package defines 'jinx-camel-modes [1], a list of major modes
for languages using camel case or pascal case. This variable is passed
to 'derived-mode-p. Before my PR #64 [2], this variable used to contain
'javascript-mode (the alias) instead of 'js-mode (the function). For a
file using 'js-mode, the equivalent of the code below was executed:
(derived-mode-p 'js-mode 'javascript-mode)
⇒ nil
I was expecting a non-nil value. My PR replaced 'javascript-mode with
'js-mode in 'jinx-camel-modes thus working around the problem.
[1] https://github.com/minad/jinx/blob/0.8/jinx.el#L96
[2] https://github.com/minad/jinx/pull/64
--
Damien Cassou
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES
2023-05-07 14:35 ` Damien Cassou
@ 2023-05-07 21:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-08 4:56 ` Damien Cassou
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-05-07 21:45 UTC (permalink / raw)
To: Damien Cassou; +Cc: Eli Zaretskii, 63345
Damien Cassou [2023-05-07 16:35:38] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> What was the original scenario where you bumped into this problem?
>
> The jinx package defines 'jinx-camel-modes [1], a list of major modes
> for languages using camel case or pascal case. This variable is passed
> to 'derived-mode-p. Before my PR #64 [2], this variable used to contain
> 'javascript-mode (the alias) instead of 'js-mode (the function). For a
> file using 'js-mode, the equivalent of the code below was executed:
>
> (derived-mode-p 'js-mode 'javascript-mode)
> ⇒ nil
I see, thanks.
> I was expecting a non-nil value. My PR replaced 'javascript-mode with
> 'js-mode in 'jinx-camel-modes thus working around the problem.
`js-mode` is the right value to use there, indeed.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES
2023-05-07 21:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-05-08 4:56 ` Damien Cassou
2023-05-08 11:31 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Damien Cassou @ 2023-05-08 4:56 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Eli Zaretskii, 63345
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> `js-mode` is the right value to use there, indeed.
Very good, thank you. In this case I would close the issue.
--
Damien Cassou
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES
2023-05-08 4:56 ` Damien Cassou
@ 2023-05-08 11:31 ` Eli Zaretskii
0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2023-05-08 11:31 UTC (permalink / raw)
To: Damien Cassou; +Cc: monnier, 63345-done
> From: Damien Cassou <damien@cassou.me>
> Cc: 63345@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>
> Date: Mon, 08 May 2023 06:56:05 +0200
>
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > `js-mode` is the right value to use there, indeed.
>
> Very good, thank you. In this case I would close the issue.
Thanks, done.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-05-08 11:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-07 9:49 bug#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES Damien Cassou
2023-05-07 10:52 ` Eli Zaretskii
2023-05-07 14:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-07 14:35 ` Damien Cassou
2023-05-07 21:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-08 4:56 ` Damien Cassou
2023-05-08 11:31 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).