all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
To: 32795@debbugs.gnu.org
Subject: bug#32795: Acknowledgement (26.1; provided-mode-derived-p does not support parent modes set with defalias)
Date: Mon, 24 Sep 2018 21:15:28 -0700	[thread overview]
Message-ID: <6ab54491416605d957ece9ee6154a6a5@posteo.net> (raw)
In-Reply-To: <handler.32795.B.153754328012273.ack@debbugs.gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]

Patch with tests attached. Please let me know if I missed anything, or 
if the code could be improved. I read through CONTRIBUTE and may have 
accidentally sent this patch in as a new bug report, sorry!

This was generated from 'emacs-26' where the bug occurs, and will merge 
just fine into 'master'. The bug also exists on 'emacs-25' but the code 
is slightly different ('provided-mode-derived-p' had not been extracted 
yet from 'derived-mode-p'). I can supply a back-ported patch as well.

Thanks,

Andy

On 09/21/2018 8:22 am, help-debbugs@gnu.org wrote:
> Thank you for filing a new bug report with debbugs.gnu.org.
> 
> This is an automatically generated reply to let you know your message
> has been received.
> 
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
> 
> Your message has been sent to the package maintainer(s):
>  bug-gnu-emacs@gnu.org
> 
> If you wish to submit further information on this problem, please
> send it to 32795@debbugs.gnu.org.
> 
> Please do not send mail to help-debbugs@gnu.org unless you wish
> to report a problem with the Bug-tracking system.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-provided-mode-derived-p-when-the-parent-is-an-al.patch --]
[-- Type: text/x-diff; name=0001-Fix-provided-mode-derived-p-when-the-parent-is-an-al.patch, Size: 2833 bytes --]

From f39d7f2b5e92e085927918cf4f9da4ba8df8f366 Mon Sep 17 00:00:00 2001
From: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
Date: Fri, 21 Sep 2018 00:10:47 -0700
Subject: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias

Authors of Emacs packages often derive from an alias of a mode instead
of the mode directly.  This is especially the case when deriving from
'prog-mode' as it is relatively new.  Unfortunately, using
'derived-mode-p' to check if some mode is derived from an alias of
'prog-mode' does not work as expected.  The bug is that
'provided-mode-derived-p' should not only return non-nil when MODE is
one of MODES, but also when MODE is an alias of one of MODES.
* lisp/subr.el (provided-mode-derived-p):
Return non-nil when MODE is an alias of any of MODES (Bug#32795).
* test/lisp/subr-tests.el: Add tests for the above.
---
 lisp/subr.el            |  9 +++++++--
 test/lisp/subr-tests.el | 12 ++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 7582b6cdb..6c625b40d 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1919,9 +1919,14 @@ delay-mode-hooks
 (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.
+Non-nil even if MODE is derived from an alias of any of MODES.
 If you just want to check `major-mode', use `derived-mode-p'."
-  (while (and (not (memq mode modes))
-              (setq mode (get mode 'derived-mode-parent))))
+  (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)
 
 (defun derived-mode-p (&rest modes)
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 430d71903..a9f72c26d 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -62,6 +62,18 @@
                      (quote
                       (0 font-lock-keyword-face))))))))
 
+(ert-deftest provided-mode-derived-p ()
+  ;; base case: `derived-mode' directly derives `prog-mode'
+  (should (progn
+            (define-derived-mode derived-mode prog-mode "test")
+            (provided-mode-derived-p 'derived-mode 'prog-mode)))
+  ;; edge case: `derived-mode' derives an alias of `prog-mode'
+  (should (progn
+            (defalias 'parent-mode
+              (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
+            (define-derived-mode derived-mode parent-mode "test")
+            (provided-mode-derived-p 'derived-mode 'prog-mode))))
+
 (ert-deftest number-sequence-test ()
   (should (= (length
               (number-sequence (1- most-positive-fixnum) most-positive-fixnum))
-- 
2.19.0


  parent reply	other threads:[~2018-09-25  4:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-21  7:20 bug#32795: 26.1; provided-mode-derived-p does not support parent modes set with defalias Andrew Schwartzmeyer
     [not found] ` <handler.32795.B.153754328012273.ack@debbugs.gnu.org>
2018-09-25  2:36   ` bug#32795: Acknowledgement (26.1; provided-mode-derived-p does not support parent modes set with defalias) Andrew Schwartzmeyer
2018-09-25  4:15   ` Andrew Schwartzmeyer [this message]
2018-09-25  5:22     ` 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=6ab54491416605d957ece9ee6154a6a5@posteo.net \
    --to=andrew@schwartzmeyer.com \
    --cc=32795@debbugs.gnu.org \
    /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.