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)
|
||||
|
||||
;; helm navigation on hjkl
|
||||
(defun spacemacs//hjkl-completion-navigation (&optional arg)
|
||||
(defun spacemacs//helm-hjkl-navigation (&optional arg)
|
||||
"Set navigation in helm on `jklh'.
|
||||
ARG non nil means Vim like movements."
|
||||
(cond
|
||||
|
@ -398,17 +398,20 @@ ARG non nil means Vim like movements."
|
|||
(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-l") (kbd "RET"))
|
||||
(with-eval-after-load 'helm-files
|
||||
(dolist (keymap (list helm-find-files-map helm-read-file-map))
|
||||
(define-key keymap (kbd "C-l") 'helm-execute-persistent-action)
|
||||
(define-key keymap (kbd "C-h") 'helm-find-files-up-one-level)
|
||||
(define-key keymap (kbd "C-S-h") 'describe-key)))
|
||||
(define-key keymap (kbd "C-S-h") 'describe-key))))
|
||||
(t
|
||||
(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-h") nil)
|
||||
(define-key helm-map
|
||||
(kbd "C-l") 'helm-recenter-top-bottom-other-window))))
|
||||
(spacemacs//hjkl-completion-navigation
|
||||
(add-hook 'spacemacs--hjkl-completion-navigation-functions
|
||||
'spacemacs//helm-hjkl-navigation)
|
||||
(run-hook-with-args 'spacemacs--hjkl-completion-navigation-functions
|
||||
(member dotspacemacs-editing-style '(vim hybrid)))
|
||||
|
||||
(defun spacemacs/helm-edit ()
|
||||
|
|
|
@ -335,10 +335,11 @@ Helm hack."
|
|||
(require (car repl))
|
||||
(call-interactively (cdr repl))))))
|
||||
|
||||
(defun spacemacs//hjkl-completion-navigation (&optional arg)
|
||||
"Set navigation on `jklh'. ARG non nil means Vim like movements."
|
||||
(cond
|
||||
(arg
|
||||
(defun spacemacs//ivy-hjkl-navigation (&optional arg)
|
||||
"Set navigation on \"hjkl\" for ivy. ARG non nil means
|
||||
vim like movements."
|
||||
(if arg
|
||||
(progn
|
||||
;; better navigation on homerow
|
||||
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-next-line)
|
||||
(define-key ivy-minibuffer-map (kbd "C-k") 'ivy-previous-line)
|
||||
|
@ -348,12 +349,13 @@ Helm hack."
|
|||
(define-key ivy-minibuffer-map (kbd "C-l") 'ivy-alt-done)
|
||||
(define-key ivy-minibuffer-map (kbd "<escape>")
|
||||
'minibuffer-keyboard-quit))
|
||||
(t
|
||||
(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-h") nil)
|
||||
(define-key ivy-minibuffer-map (kbd "C-l") nil))))
|
||||
(spacemacs//hjkl-completion-navigation
|
||||
(define-key ivy-minibuffer-map (kbd "C-l") nil)))
|
||||
(add-hook 'spacemacs--hjkl-completion-navigation-functions
|
||||
'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 ()
|
||||
|
|
|
@ -367,6 +367,13 @@
|
|||
(evil-define-key 'insert comint-mode-map [up] 'comint-previous-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
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
|
|
@ -51,10 +51,10 @@ before it was disabled.")
|
|||
(when (boundp (car mode)) (funcall (car mode) -1)))
|
||||
(setq cursor-type 'box)
|
||||
(set-cursor-color "SkyBlue2")
|
||||
(when (fboundp 'spacemacs//hjkl-completion-navigation)
|
||||
(spacemacs//hjkl-completion-navigation nil)))
|
||||
(when (fboundp 'spacemacs//hjkl-completion-navigation)
|
||||
(spacemacs//hjkl-completion-navigation t))
|
||||
(run-hook-with-args 'spacemacs--hjkl-completion-navigation-functions
|
||||
nil))
|
||||
(run-hook-with-args 'spacemacs--hjkl-completion-navigation-functions
|
||||
t)
|
||||
(dolist (mode holy-mode-modes-to-disable-alist)
|
||||
(when (boundp (car mode))
|
||||
(funcall (car mode) (cdr mode))))))
|
||||
|
|
Loading…
Reference in a new issue