diff --git a/layers/+completion/spacemacs-helm/packages.el b/layers/+completion/spacemacs-helm/packages.el index fabcf8a86..d1b900fc6 100644 --- a/layers/+completion/spacemacs-helm/packages.el +++ b/layers/+completion/spacemacs-helm/packages.el @@ -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,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-S-h") 'describe-key) (define-key helm-map (kbd "C-l") (kbd "RET")) - (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))) + (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)))) (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 - (member dotspacemacs-editing-style '(vim hybrid))) + (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 () "Switch in edit mode depending on the current helm buffer." diff --git a/layers/+completion/spacemacs-ivy/packages.el b/layers/+completion/spacemacs-ivy/packages.el index db12dc7f0..63b1a24e1 100644 --- a/layers/+completion/spacemacs-ivy/packages.el +++ b/layers/+completion/spacemacs-ivy/packages.el @@ -335,26 +335,28 @@ 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 - ;; 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) - (define-key ivy-minibuffer-map (kbd "C-h") (kbd "DEL")) - ;; Move C-h to C-S-h - (define-key ivy-minibuffer-map (kbd "C-S-h") help-map) - (define-key ivy-minibuffer-map (kbd "C-l") 'ivy-alt-done) - (define-key ivy-minibuffer-map (kbd "") - 'minibuffer-keyboard-quit)) - (t + (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) + (define-key ivy-minibuffer-map (kbd "C-h") (kbd "DEL")) + ;; Move C-h to C-S-h + (define-key ivy-minibuffer-map (kbd "C-S-h") help-map) + (define-key ivy-minibuffer-map (kbd "C-l") 'ivy-alt-done) + (define-key ivy-minibuffer-map (kbd "") + 'minibuffer-keyboard-quit)) (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 - (member dotspacemacs-editing-style '(vim hybrid))) + (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 () "`counsel-up-directory' ignoring errors." diff --git a/layers/+distribution/spacemacs-base/keybindings.el b/layers/+distribution/spacemacs-base/keybindings.el index 1914bb33d..95d5dae88 100644 --- a/layers/+distribution/spacemacs-base/keybindings.el +++ b/layers/+distribution/spacemacs-base/keybindings.el @@ -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 ;; --------------------------------------------------------------------------- diff --git a/layers/+distribution/spacemacs-base/local/holy-mode/holy-mode.el b/layers/+distribution/spacemacs-base/local/holy-mode/holy-mode.el index d72dac60f..eff8e04b5 100644 --- a/layers/+distribution/spacemacs-base/local/holy-mode/holy-mode.el +++ b/layers/+distribution/spacemacs-base/local/holy-mode/holy-mode.el @@ -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))))))