read-only mode bindings

This commit is contained in:
condy 2020-11-12 02:26:48 +08:00 committed by Pierre Neidhardt
parent 6f0ac579aa
commit 04110f090f
3 changed files with 18 additions and 6 deletions

View File

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

View File

@ -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

View File

@ -256,11 +256,12 @@ more.
with ~<f3>~ and ~<f4>~.
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.