From 04110f090ff2951df2da35ec9c4bd3b265f49c50 Mon Sep 17 00:00:00 2001 From: condy Date: Thu, 12 Nov 2020 02:26:48 +0800 Subject: [PATCH] read-only mode bindings --- evil-collection.el | 11 +++++++++++ modes/simple/evil-collection-simple.el | 2 +- readme.org | 11 ++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/evil-collection.el b/evil-collection.el index 062a52e..7b720ee 100644 --- a/evil-collection.el +++ b/evil-collection.el @@ -392,6 +392,17 @@ This is particularly useful for read-only modes." [remap evil-shift-right] #'ignore [remap evil-invert-char] #'ignore)) +(defun evil-collection-set-readonly-bindings (map-sym) + "Unmap insertion keys from normal state. Additionally q can `quit-window'. +This is particularly useful for read-only modes. Make sure it's +called before setting up other evil bindings so that it can be +overriden." + (evil-collection-inhibit-insert-state map-sym) + (evil-collection-define-key 'normal map-sym + "q" #'quit-window + "ZZ" #'quit-window + "ZQ" #'evil-quit)) + (defun evil-collection--binding-lessp (a b) "Comparison function used to sort bindings of the form (state key def)." (let ((a-state (symbol-name (nth 0 a))) diff --git a/modes/simple/evil-collection-simple.el b/modes/simple/evil-collection-simple.el index 7fda02c..1e90ec4 100644 --- a/modes/simple/evil-collection-simple.el +++ b/modes/simple/evil-collection-simple.el @@ -37,7 +37,7 @@ ;;;###autoload (defun evil-collection-simple-setup () "Set up `evil' bindings for `simple'." - + (evil-collection-set-readonly-bindings 'special-mode-map) (evil-collection-define-key nil 'special-mode-map "g" nil "gr" 'revert-buffer diff --git a/readme.org b/readme.org index 9f03fe8..c4d8043 100644 --- a/readme.org +++ b/readme.org @@ -256,11 +256,12 @@ more. with ~~ and ~~. A good rule of thumb would be: - - - Always bind ~ZZ~ and ~ZQ~ to the quitting function(s), ~evil-quit~ if nothing - else makes sense. - - - Bind ~q~ to ~evil-quit~ if macros don't make sense in current mode. + + - Always bind ~q~, ~ZZ~ and ~ZQ~ to the mode specific quitting functions. If there is none, + + - Bind ~q~ and ~ZZ~ to ~quit-window~ + + - Bind ~ZQ~ to ~evil-quit~ - If macros don't make sense in current mode, then ~@~ is available.