emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] feature/mhtml-mode 60be4b7 06/11: change viper to use deri


From: Tom Tromey
Subject: [Emacs-diffs] feature/mhtml-mode 60be4b7 06/11: change viper to use derived-mode-p
Date: Thu, 23 Mar 2017 23:15:04 -0400 (EDT)

branch: feature/mhtml-mode
commit 60be4b78aedea0286465bf7604f15538490f45a2
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>

    change viper to use derived-mode-p
    
    * lisp/subr.el (provided-mode-derived-p): New function.
    (derived-mode-p): Use it.
    * lisp/emulation/viper.el (viper-mode): Use derived-mode-p.
    (this-major-mode-requires-vi-state): Use provided-mode-derived-p.
    (set-viper-state-in-major-mode): Use derived-mode-p.
---
 lisp/emulation/viper.el | 25 ++++++++++++++++---------
 lisp/subr.el            | 13 +++++++++----
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index b03af9b..81acedb 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -592,8 +592,10 @@ This startup message appears whenever you load Viper, 
unless you type `y' now."
                    ))
              (viper-set-expert-level 'dont-change-unless)))
 
-       (or (memq major-mode viper-emacs-state-mode-list) ; don't switch to Vi
-           (memq major-mode viper-insert-state-mode-list) ; don't switch
+       (or (cl-member-if #'derived-mode-p
+                          viper-emacs-state-mode-list) ; don't switch to Vi
+           (cl-member-if #'derived-mode-p
+                          viper-insert-state-mode-list) ; don't switch
            (viper-change-state-to-vi))
        ))
 
@@ -605,11 +607,15 @@ This startup message appears whenever you load Viper, 
unless you type `y' now."
 ;; Apply a little heuristic to invoke vi state on major-modes
 ;; that are not listed in viper-vi-state-mode-list
 (defun this-major-mode-requires-vi-state (mode)
-  (cond ((memq mode viper-vi-state-mode-list) t)
-       ((memq mode viper-emacs-state-mode-list) nil)
-       ((memq mode viper-insert-state-mode-list) nil)
-       (t (and (eq (key-binding "a") 'self-insert-command)
-               (eq (key-binding " ") 'self-insert-command)))))
+  (let ((check (lambda (one-mode)
+                 (provided-mode-derived-p mode one-mode))))
+    (cond ((cl-member-if check viper-vi-state-mode-list) t)
+          ((cl-member-if check viper-emacs-state-mode-list)
+           nil)
+          ((cl-member-if check viper-insert-state-mode-list)
+           nil)
+          (t (and (eq (key-binding "a") 'self-insert-command)
+                  (eq (key-binding " ") 'self-insert-command))))))
 
 
 ;; This hook designed to enable Vi-style editing in comint-based modes."
@@ -802,13 +808,14 @@ It also can't undo some Viper settings."
           (cond ((and (this-major-mode-requires-vi-state major-mode)
                       (eq viper-current-state 'emacs-state))
                  (viper-mode))
-                ((memq major-mode viper-emacs-state-mode-list)
+                ((cl-member-if #'derived-mode-p viper-emacs-state-mode-list)
                  ;; not checking (eq viper-current-state 'emacs-state)
                  ;; because viper-current-state could have gotten it by
                  ;; default.  We need viper-change-state-to-emacs here to have
                  ;; the keymaps take effect.
                  (viper-change-state-to-emacs))
-                ((and (memq major-mode viper-insert-state-mode-list)
+                ((and (cl-member-if #'derived-mode-p
+                                     viper-insert-state-mode-list)
                       (not (eq viper-current-state 'insert-state)))
                  (viper-change-state-to-insert))
                 )) ; with-current-buffer
diff --git a/lisp/subr.el b/lisp/subr.el
index 6b04038..13567d8 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1872,13 +1872,18 @@ Only affects hooks run in the current buffer."
 
 ;; PUBLIC: find if the current mode derives from another.
 
+(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'."
+  (while (and (not (memq mode modes))
+              (setq mode (get mode 'derived-mode-parent))))
+  mode)
+
 (defun derived-mode-p (&rest modes)
   "Non-nil if the current major mode is derived from one of MODES.
 Uses the `derived-mode-parent' property of the symbol to trace backwards."
-  (let ((parent major-mode))
-    (while (and (not (memq parent modes))
-               (setq parent (get parent 'derived-mode-parent))))
-    parent))
+  (apply #'provided-mode-derived-p major-mode modes))
 
 ;;;; Minor modes.
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]