completion: move hjkl function to layers and treat ivy as a package

This commit is contained in:
syl20bnr 2016-01-09 15:29:37 -05:00
parent 53d55d3da6
commit ea333f7282
4 changed files with 48 additions and 59 deletions

View File

@ -344,9 +344,9 @@ 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//helm-hjkl-navigation (&optional arg)
(defun spacemacs//hjkl-completion-navigation (&optional arg)
"Set navigation in helm on `jklh'.
ARG non nil means that the editing style is `vim'."
ARG non nil means Vim like movements."
(cond
(arg
;; better navigation on homerow
@ -365,7 +365,8 @@ ARG non nil means that the editing style is `vim'."
(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)
(spacemacs//hjkl-completion-navigation
(member dotspacemacs-editing-style '(vim hybrid)))
(defun spacemacs/helm-edit ()
"Switch in edit mode depending on the current helm buffer."

View File

@ -14,12 +14,13 @@
'(counsel
flx
hydra
;; hack since ivy is part for swiper but I like to
;; treat it as a stand-alone package
(ivy :location built-in)
(ivy-spacemacs-help :location local)
smex
swiper))
;; Initialization of packages
(defun spacemacs-ivy/init-counsel ()
(defvar spacemacs--counsel-commands
'(("ag" . "ag --vimgrep %S .")
@ -225,26 +226,46 @@ not been implemented for the spacemacs-ivy layer yet."
smex-save-file (concat spacemacs-cache-directory
".smex-items")))))
(defun spacemacs-ivy/init-swiper ()
(defun spacemacs-ivy/init-ivy ()
(use-package ivy
:config
(spacemacs/set-leader-keys
"fr" 'ivy-recentf
"ir" 'ivy-resume
"bb" 'ivy-switch-buffer)
(setq ivy-height 15)
(with-eval-after-load 'recentf
;; merge recentf and bookmarks into buffer switching. If we set this
;; before recentf loads, then ivy-mode loads recentf for us, which messes
;; up the spacemacs version of recentf.
(setq ivy-use-virtual-buffers t))
(when (configuration-layer/package-usedp 'projectile)
(setq projectile-completion-system 'ivy))
(ivy-mode 1)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(spacemacs//hjkl-completion-navigation))
(progn
(spacemacs/set-leader-keys
"fr" 'ivy-recentf
"ir" 'ivy-resume
"bb" 'ivy-switch-buffer)
(setq ivy-height 15)
(with-eval-after-load 'recentf
;; merge recentf and bookmarks into buffer switching. If we set this
;; before recentf loads, then ivy-mode loads recentf for us, which messes
;; up the spacemacs version of recentf.
(setq ivy-use-virtual-buffers t))
(when (configuration-layer/package-usedp 'projectile)
(setq projectile-completion-system 'ivy))
(ivy-mode 1)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(defun spacemacs//hjkl-completion-navigation (&optional arg)
"Set navigation on `jklh'. ARG non nil means Vim like movements."
(cond
(arg
;; better navigation on homerow
;; rebind `describe-key' for convenience
(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"))
(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
(member dotspacemacs-editing-style '(vim hybrid))))))
(defun spacemacs-ivy/init-swiper ()
(use-package swiper
:config
(defun spacemacs/swiper-region-or-symbol ()

View File

@ -906,36 +906,3 @@ current major mode."
(when (and (integerp shift-width)
(< 0 shift-width))
(setq-local evil-shift-width shift-width))))
(defun spacemacs//hjkl-completion-navigation ()
(cond
((and (configuration-layer/layer-usedp 'spacemacs-helm)
(member dotspacemacs-editing-style '(vim hybrid)))
;; better navigation on homerow
;; rebind `describe-key' for convenience
(define-key helm-map (kbd "C-j") 'helm-next-line)
(define-key helm-map (kbd "C-k") 'helm-previous-line)
(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)))
((configuration-layer/layer-usedp 'spacemacs-helm)
(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))
((and (configuration-layer/layer-usedp 'spacemacs-ivy)
(member dotspacemacs-editing-style '(vim hybrid)))
(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"))
(define-key ivy-minibuffer-map (kbd "C-l") 'ivy-alt-done)
(define-key ivy-minibuffer-map (kbd "<escape>") 'minibuffer-keyboard-quit))
((configuration-layer/layer-usedp 'spacemacs-ivy)
(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))))

View File

@ -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//helm-hjkl-navigation)
(spacemacs//helm-hjkl-navigation nil)))
(when (fboundp 'spacemacs//helm-hjkl-navigation)
(spacemacs//helm-hjkl-navigation t))
(when (fboundp 'spacemacs//hjkl-completion-navigation)
(spacemacs//hjkl-completion-navigation nil)))
(when (fboundp 'spacemacs//hjkl-completion-navigation)
(spacemacs//hjkl-completion-navigation t))
(dolist (mode holy-mode-modes-to-disable-alist)
(when (boundp (car mode))
(funcall (car mode) (cdr mode))))))