unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias
@ 2018-09-25  4:09 andrew
  2018-09-26  5:10 ` bug#32832: Please close this bug Andrew Schwartzmeyer
  2018-09-29  7:01 ` bug#32795: bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: andrew @ 2018-09-25  4:09 UTC (permalink / raw)
  To: 32832

From: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>

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






^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#32832: Please close this bug
  2018-09-25  4:09 bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias andrew
@ 2018-09-26  5:10 ` Andrew Schwartzmeyer
  2018-09-26 12:18   ` Noam Postavsky
  2018-09-29  7:01 ` bug#32795: bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias Eli Zaretskii
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Schwartzmeyer @ 2018-09-26  5:10 UTC (permalink / raw)
  To: 32832

I'm sorry, this patch was meant for #32795, but I accidentally created a 
new bug. The patch has been successfully attached to the correct bug; 
that bug can be classified as "Patch Available" and this bug closed.

Thanks!





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32832: Please close this bug
  2018-09-26  5:10 ` bug#32832: Please close this bug Andrew Schwartzmeyer
@ 2018-09-26 12:18   ` Noam Postavsky
  0 siblings, 0 replies; 4+ messages in thread
From: Noam Postavsky @ 2018-09-26 12:18 UTC (permalink / raw)
  To: Andrew Schwartzmeyer; +Cc: 32832

close 32832
tags 32795 + patch
quit

Andrew Schwartzmeyer <andrew@schwartzmeyer.com> writes:

> I'm sorry, this patch was meant for #32795, but I accidentally created
> a new bug. The patch has been successfully attached to the correct
> bug; that bug can be classified as "Patch Available" and this bug
> closed.

Done.






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#32795: bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias
  2018-09-25  4:09 bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias andrew
  2018-09-26  5:10 ` bug#32832: Please close this bug Andrew Schwartzmeyer
@ 2018-09-29  7:01 ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2018-09-29  7:01 UTC (permalink / raw)
  To: andrew; +Cc: 32795-done

> From: andrew@schwartzmeyer.com
> Date: Mon, 24 Sep 2018 21:09:39 -0700
> 
> From: Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
> 
> 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.

Thanks, pushed.

In the future please either format your patches with "git
format-patch" or make sure the first line of the commit log message is
a single sentence followed by an empty line (this is explained in
CONTRIBUTE), to make the patch application easier.

Also, you don't seem to have a copyright assignment on file, and this
contribution comes close to exhausting the amount of changes we can
accept without such an assignment.  So I urge you to start your legal
paperwork rolling, to allow us to accept more contributions from you.
If you are interested, I will send you the assignment form off-list.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-09-29  7:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-25  4:09 bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias andrew
2018-09-26  5:10 ` bug#32832: Please close this bug Andrew Schwartzmeyer
2018-09-26 12:18   ` Noam Postavsky
2018-09-29  7:01 ` bug#32795: bug#32832: [PATCH] Fix 'provided-mode-derived-p' when the parent is an alias 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).