unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* 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

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).