Add custom function for keyboard-quit
This version should also quit the minibuffer even if not selected. Found at https://with-emacs.com/posts/tips/quit-current-context/.
This commit is contained in:
parent
221f8f7fc3
commit
88e0a5021d
4
init.el
4
init.el
|
@ -215,6 +215,7 @@
|
||||||
(unbind-key "<kp-insert>" global-map)
|
(unbind-key "<kp-insert>" global-map)
|
||||||
(bind-key [remap fill-paragraph] #'endless/fill-or-unfill)
|
(bind-key [remap fill-paragraph] #'endless/fill-or-unfill)
|
||||||
(unbind-key "C-x C-c" global-map)
|
(unbind-key "C-x C-c" global-map)
|
||||||
|
(bind-key [remap keyboard-quit] #'keyboard-quit-context+)
|
||||||
|
|
||||||
;; Custom helm bindings
|
;; Custom helm bindings
|
||||||
|
|
||||||
|
@ -577,7 +578,8 @@
|
||||||
db/dired-from-shell-command
|
db/dired-from-shell-command
|
||||||
db/system-open
|
db/system-open
|
||||||
db/switch-to-dark-theme
|
db/switch-to-dark-theme
|
||||||
db/switch-to-light-theme))
|
db/switch-to-light-theme
|
||||||
|
keyboard-quit-context+))
|
||||||
|
|
||||||
(use-package db-hydras
|
(use-package db-hydras
|
||||||
:commands (hydra-toggle/body
|
:commands (hydra-toggle/body
|
||||||
|
|
|
@ -372,6 +372,40 @@ output, separated by \\n, when called with
|
||||||
(t
|
(t
|
||||||
(start-process "" nil "xdg-open" path))))
|
(start-process "" nil "xdg-open" path))))
|
||||||
|
|
||||||
|
(defun keyboard-quit-context+ ()
|
||||||
|
"Quit current context.
|
||||||
|
|
||||||
|
This function is a combination of `keyboard-quit' and
|
||||||
|
`keyboard-escape-quit' with some parts omitted and some custom
|
||||||
|
behavior added. When the minibuffer is active, quit it
|
||||||
|
regardless of the currently selected window."
|
||||||
|
;; https://with-emacs.com/posts/tips/quit-current-context/
|
||||||
|
(interactive)
|
||||||
|
(cond ((region-active-p)
|
||||||
|
;; Avoid adding the region to the window selection.
|
||||||
|
(setq saved-region-selection nil)
|
||||||
|
(let (select-active-regions)
|
||||||
|
(deactivate-mark)))
|
||||||
|
((eq last-command 'mode-exited) nil)
|
||||||
|
(current-prefix-arg
|
||||||
|
nil)
|
||||||
|
(defining-kbd-macro
|
||||||
|
(message
|
||||||
|
(substitute-command-keys
|
||||||
|
"Quit is ignored during macro defintion, use \\[kmacro-end-macro] if you want to stop macro definition"))
|
||||||
|
(cancel-kbd-macro-events))
|
||||||
|
((active-minibuffer-window)
|
||||||
|
(when (get-buffer-window "*Completions*")
|
||||||
|
;; hide completions first so point stays in active window when
|
||||||
|
;; outside the minibuffer
|
||||||
|
(minibuffer-hide-completions))
|
||||||
|
(abort-recursive-edit))
|
||||||
|
(t
|
||||||
|
(when completion-in-region-mode
|
||||||
|
(completion-in-region-mode -1))
|
||||||
|
(let ((debug-on-quit nil))
|
||||||
|
(signal 'quit nil)))))
|
||||||
|
|
||||||
|
|
||||||
;;; Extend Input Methods
|
;;; Extend Input Methods
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue