GNU bug report logs - #63345
28.2; provided-mode-derived-p doesn't work when passed an alias in MODES

Previous Next

Package: emacs;

Reported by: Damien Cassou <damien <at> cassou.me>

Date: Sun, 7 May 2023 09:50:02 UTC

Severity: normal

Found in version 28.2

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 63345 in the body.
You can then email your comments to 63345 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#63345; Package emacs. (Sun, 07 May 2023 09:50:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Damien Cassou <damien <at> cassou.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 07 May 2023 09:50:02 GMT) Full text and rfc822 format available.

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

From: Damien Cassou <damien <at> cassou.me>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.2; provided-mode-derived-p doesn't work when passed an alias in
 MODES
Date: Sun, 07 May 2023 11:49:37 +0200
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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63345; Package emacs. (Sun, 07 May 2023 10:52:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Damien Cassou <damien <at> cassou.me>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 63345 <at> debbugs.gnu.org
Subject: Re: bug#63345: 28.2;
 provided-mode-derived-p doesn't work when passed an alias in MODES
Date: Sun, 07 May 2023 13:52:26 +0300
> From: Damien Cassou <damien <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63345; Package emacs. (Sun, 07 May 2023 14:24:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Damien Cassou <damien <at> cassou.me>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 63345 <at> debbugs.gnu.org
Subject: Re: bug#63345: 28.2; provided-mode-derived-p doesn't work when
 passed an alias in MODES
Date: Sun, 07 May 2023 10:23:22 -0400
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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63345; Package emacs. (Sun, 07 May 2023 14:36:02 GMT) Full text and rfc822 format available.

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

From: Damien Cassou <damien <at> cassou.me>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 63345 <at> debbugs.gnu.org
Subject: Re: bug#63345: 28.2; provided-mode-derived-p doesn't work when
 passed an alias in MODES
Date: Sun, 07 May 2023 16:35:38 +0200
Stefan Monnier <monnier <at> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63345; Package emacs. (Sun, 07 May 2023 21:47:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Damien Cassou <damien <at> cassou.me>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 63345 <at> debbugs.gnu.org
Subject: Re: bug#63345: 28.2; provided-mode-derived-p doesn't work when
 passed an alias in MODES
Date: Sun, 07 May 2023 17:45:55 -0400
Damien Cassou [2023-05-07 16:35:38] wrote:
> Stefan Monnier <monnier <at> 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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#63345; Package emacs. (Mon, 08 May 2023 04:57:01 GMT) Full text and rfc822 format available.

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

From: Damien Cassou <damien <at> cassou.me>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 63345 <at> debbugs.gnu.org
Subject: Re: bug#63345: 28.2; provided-mode-derived-p doesn't work when
 passed an alias in MODES
Date: Mon, 08 May 2023 06:56:05 +0200
Stefan Monnier <monnier <at> 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




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Mon, 08 May 2023 11:31:02 GMT) Full text and rfc822 format available.

Notification sent to Damien Cassou <damien <at> cassou.me>:
bug acknowledged by developer. (Mon, 08 May 2023 11:31:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Damien Cassou <damien <at> cassou.me>
Cc: monnier <at> iro.umontreal.ca, 63345-done <at> debbugs.gnu.org
Subject: Re: bug#63345: 28.2; provided-mode-derived-p doesn't work when
 passed an alias in MODES
Date: Mon, 08 May 2023 14:31:43 +0300
> From: Damien Cassou <damien <at> cassou.me>
> Cc: 63345 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
> Date: Mon, 08 May 2023 06:56:05 +0200
> 
> Stefan Monnier <monnier <at> 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.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 06 Jun 2023 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 297 days ago.

Previous Next


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