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.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Damien Cassou <damien <at> cassou.me>
Subject: bug#63345: closed (Re: bug#63345: 28.2; provided-mode-derived-p
 doesn't work when passed an alias in MODES)
Date: Mon, 08 May 2023 11:31:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#63345: 28.2; provided-mode-derived-p doesn't work when passed an alias in MODES

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 63345 <at> debbugs.gnu.org.

-- 
63345: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63345
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
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.

[Message part 3 (message/rfc822, inline)]
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



This bug report was last modified 2 years and 72 days ago.

Previous Next


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