helm/ivy: Use hook to update hjkl navigation
Introduce hjkl-completion-navigation-functions to hold the functions to disable and enable hjkl navigation for ivy and/or helm. The hook is run with args to indicate whether to enable or disable.
This commit is contained in:
parent
cf90c8ee07
commit
f6b82ee90d
|
@ -386,7 +386,7 @@ Removes the automatic guessing of the initial value based on thing at point. "
|
||||||
(add-hook 'helm-mode-hook 'simpler-helm-bookmark-keybindings)
|
(add-hook 'helm-mode-hook 'simpler-helm-bookmark-keybindings)
|
||||||
|
|
||||||
;; helm navigation on hjkl
|
;; helm navigation on hjkl
|
||||||
(defun spacemacs//hjkl-completion-navigation (&optional arg)
|
(defun spacemacs//helm-hjkl-navigation (&optional arg)
|
||||||
"Set navigation in helm on `jklh'.
|
"Set navigation in helm on `jklh'.
|
||||||
ARG non nil means Vim like movements."
|
ARG non nil means Vim like movements."
|
||||||
(cond
|
(cond
|
||||||
|
@ -398,18 +398,21 @@ ARG non nil means Vim like movements."
|
||||||
(define-key helm-map (kbd "C-h") 'helm-next-source)
|
(define-key helm-map (kbd "C-h") 'helm-next-source)
|
||||||
(define-key helm-map (kbd "C-S-h") 'describe-key)
|
(define-key helm-map (kbd "C-S-h") 'describe-key)
|
||||||
(define-key helm-map (kbd "C-l") (kbd "RET"))
|
(define-key helm-map (kbd "C-l") (kbd "RET"))
|
||||||
(dolist (keymap (list helm-find-files-map helm-read-file-map))
|
(with-eval-after-load 'helm-files
|
||||||
(define-key keymap (kbd "C-l") 'helm-execute-persistent-action)
|
(dolist (keymap (list helm-find-files-map helm-read-file-map))
|
||||||
(define-key keymap (kbd "C-h") 'helm-find-files-up-one-level)
|
(define-key keymap (kbd "C-l") 'helm-execute-persistent-action)
|
||||||
(define-key keymap (kbd "C-S-h") 'describe-key)))
|
(define-key keymap (kbd "C-h") 'helm-find-files-up-one-level)
|
||||||
|
(define-key keymap (kbd "C-S-h") 'describe-key))))
|
||||||
(t
|
(t
|
||||||
(define-key helm-map (kbd "C-j") 'helm-execute-persistent-action)
|
(define-key helm-map (kbd "C-j") 'helm-execute-persistent-action)
|
||||||
(define-key helm-map (kbd "C-k") 'helm-delete-minibuffer-contents)
|
(define-key helm-map (kbd "C-k") 'helm-delete-minibuffer-contents)
|
||||||
(define-key helm-map (kbd "C-h") nil)
|
(define-key helm-map (kbd "C-h") nil)
|
||||||
(define-key helm-map
|
(define-key helm-map
|
||||||
(kbd "C-l") 'helm-recenter-top-bottom-other-window))))
|
(kbd "C-l") 'helm-recenter-top-bottom-other-window))))
|
||||||
(spacemacs//hjkl-completion-navigation
|
(add-hook 'spacemacs--hjkl-completion-navigation-functions
|
||||||
(member dotspacemacs-editing-style '(vim hybrid)))
|
'spacemacs//helm-hjkl-navigation)
|
||||||
|
(run-hook-with-args 'spacemacs--hjkl-completion-navigation-functions
|
||||||
|
(member dotspacemacs-editing-style '(vim hybrid)))
|
||||||
|
|
||||||
(defun spacemacs/helm-edit ()
|
(defun spacemacs/helm-edit ()
|
||||||
"Switch in edit mode depending on the current helm buffer."
|
"Switch in edit mode depending on the current helm buffer."
|
||||||
|
|
|
@ -335,26 +335,28 @@ Helm hack."
|
||||||
(require (car repl))
|
(require (car repl))
|
||||||
(call-interactively (cdr repl))))))
|
(call-interactively (cdr repl))))))
|
||||||
|
|
||||||
(defun spacemacs//hjkl-completion-navigation (&optional arg)
|
(defun spacemacs//ivy-hjkl-navigation (&optional arg)
|
||||||
"Set navigation on `jklh'. ARG non nil means Vim like movements."
|
"Set navigation on \"hjkl\" for ivy. ARG non nil means
|
||||||
(cond
|
vim like movements."
|
||||||
(arg
|
(if arg
|
||||||
;; better navigation on homerow
|
(progn
|
||||||
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-next-line)
|
;; better navigation on homerow
|
||||||
(define-key ivy-minibuffer-map (kbd "C-k") 'ivy-previous-line)
|
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-next-line)
|
||||||
(define-key ivy-minibuffer-map (kbd "C-h") (kbd "DEL"))
|
(define-key ivy-minibuffer-map (kbd "C-k") 'ivy-previous-line)
|
||||||
;; Move C-h to C-S-h
|
(define-key ivy-minibuffer-map (kbd "C-h") (kbd "DEL"))
|
||||||
(define-key ivy-minibuffer-map (kbd "C-S-h") help-map)
|
;; Move C-h to C-S-h
|
||||||
(define-key ivy-minibuffer-map (kbd "C-l") 'ivy-alt-done)
|
(define-key ivy-minibuffer-map (kbd "C-S-h") help-map)
|
||||||
(define-key ivy-minibuffer-map (kbd "<escape>")
|
(define-key ivy-minibuffer-map (kbd "C-l") 'ivy-alt-done)
|
||||||
'minibuffer-keyboard-quit))
|
(define-key ivy-minibuffer-map (kbd "<escape>")
|
||||||
(t
|
'minibuffer-keyboard-quit))
|
||||||
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-alt-done)
|
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-alt-done)
|
||||||
(define-key ivy-minibuffer-map (kbd "C-k") 'ivy-kill-line)
|
(define-key ivy-minibuffer-map (kbd "C-k") 'ivy-kill-line)
|
||||||
(define-key ivy-minibuffer-map (kbd "C-h") nil)
|
(define-key ivy-minibuffer-map (kbd "C-h") nil)
|
||||||
(define-key ivy-minibuffer-map (kbd "C-l") nil))))
|
(define-key ivy-minibuffer-map (kbd "C-l") nil)))
|
||||||
(spacemacs//hjkl-completion-navigation
|
(add-hook 'spacemacs--hjkl-completion-navigation-functions
|
||||||
(member dotspacemacs-editing-style '(vim hybrid)))
|
'spacemacs//ivy-hjkl-navigation)
|
||||||
|
(run-hook-with-args 'spacemacs--hjkl-completion-navigation-functions
|
||||||
|
(member dotspacemacs-editing-style '(vim hybrid)))
|
||||||
|
|
||||||
(defun spacemacs/counsel-up-directory-no-error ()
|
(defun spacemacs/counsel-up-directory-no-error ()
|
||||||
"`counsel-up-directory' ignoring errors."
|
"`counsel-up-directory' ignoring errors."
|
||||||
|
|
|
@ -367,6 +367,13 @@
|
||||||
(evil-define-key 'insert comint-mode-map [up] 'comint-previous-input)
|
(evil-define-key 'insert comint-mode-map [up] 'comint-previous-input)
|
||||||
(evil-define-key 'insert comint-mode-map [down] 'comint-next-input))
|
(evil-define-key 'insert comint-mode-map [down] 'comint-next-input))
|
||||||
|
|
||||||
|
;; ivy/helm keys --------------------------------------------------------------
|
||||||
|
|
||||||
|
(defvar spacemacs--hjkl-completion-navigation-functions nil
|
||||||
|
"Hook to adjust hjkl keys for completion (helm/ivy) navigation.
|
||||||
|
Each function in the hook is run with a single argument, which
|
||||||
|
when true should disable the hjkl keys.")
|
||||||
|
|
||||||
;; ---------------------------------------------------------------------------
|
;; ---------------------------------------------------------------------------
|
||||||
;; Transient-states
|
;; Transient-states
|
||||||
;; ---------------------------------------------------------------------------
|
;; ---------------------------------------------------------------------------
|
||||||
|
|
|
@ -51,10 +51,10 @@ before it was disabled.")
|
||||||
(when (boundp (car mode)) (funcall (car mode) -1)))
|
(when (boundp (car mode)) (funcall (car mode) -1)))
|
||||||
(setq cursor-type 'box)
|
(setq cursor-type 'box)
|
||||||
(set-cursor-color "SkyBlue2")
|
(set-cursor-color "SkyBlue2")
|
||||||
(when (fboundp 'spacemacs//hjkl-completion-navigation)
|
(run-hook-with-args 'spacemacs--hjkl-completion-navigation-functions
|
||||||
(spacemacs//hjkl-completion-navigation nil)))
|
nil))
|
||||||
(when (fboundp 'spacemacs//hjkl-completion-navigation)
|
(run-hook-with-args 'spacemacs--hjkl-completion-navigation-functions
|
||||||
(spacemacs//hjkl-completion-navigation t))
|
t)
|
||||||
(dolist (mode holy-mode-modes-to-disable-alist)
|
(dolist (mode holy-mode-modes-to-disable-alist)
|
||||||
(when (boundp (car mode))
|
(when (boundp (car mode))
|
||||||
(funcall (car mode) (cdr mode))))))
|
(funcall (car mode) (cdr mode))))))
|
||||||
|
|
Loading…
Reference in a new issue