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) (add-hook 'helm-mode-hook 'simpler-helm-bookmark-keybindings)
;; helm navigation on hjkl ;; helm navigation on hjkl
(defun spacemacs//helm-hjkl-navigation (&optional arg) (defun spacemacs//hjkl-completion-navigation (&optional arg)
"Set navigation in helm on `jklh'. "Set navigation in helm on `jklh'.
ARG non nil means that the editing style is `vim'." ARG non nil means Vim like movements."
(cond (cond
(arg (arg
;; better navigation on homerow ;; 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-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 (kbd "C-l") 'helm-recenter-top-bottom-other-window)))) (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 () (defun spacemacs/helm-edit ()
"Switch in edit mode depending on the current helm buffer." "Switch in edit mode depending on the current helm buffer."

View file

@ -14,12 +14,13 @@
'(counsel '(counsel
flx flx
hydra 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) (ivy-spacemacs-help :location local)
smex smex
swiper)) swiper))
;; Initialization of packages
(defun spacemacs-ivy/init-counsel () (defun spacemacs-ivy/init-counsel ()
(defvar spacemacs--counsel-commands (defvar spacemacs--counsel-commands
'(("ag" . "ag --vimgrep %S .") '(("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-save-file (concat spacemacs-cache-directory
".smex-items"))))) ".smex-items")))))
(defun spacemacs-ivy/init-swiper () (defun spacemacs-ivy/init-ivy ()
(use-package ivy (use-package ivy
:config :config
(spacemacs/set-leader-keys (progn
"fr" 'ivy-recentf (spacemacs/set-leader-keys
"ir" 'ivy-resume "fr" 'ivy-recentf
"bb" 'ivy-switch-buffer) "ir" 'ivy-resume
(setq ivy-height 15) "bb" 'ivy-switch-buffer)
(with-eval-after-load 'recentf (setq ivy-height 15)
;; merge recentf and bookmarks into buffer switching. If we set this (with-eval-after-load 'recentf
;; before recentf loads, then ivy-mode loads recentf for us, which messes ;; merge recentf and bookmarks into buffer switching. If we set this
;; up the spacemacs version of recentf. ;; before recentf loads, then ivy-mode loads recentf for us, which messes
(setq ivy-use-virtual-buffers t)) ;; up the spacemacs version of recentf.
(when (configuration-layer/package-usedp 'projectile) (setq ivy-use-virtual-buffers t))
(setq projectile-completion-system 'ivy)) (when (configuration-layer/package-usedp 'projectile)
(ivy-mode 1) (setq projectile-completion-system 'ivy))
(global-set-key (kbd "C-c C-r") 'ivy-resume) (ivy-mode 1)
(global-set-key (kbd "<f6>") 'ivy-resume) (global-set-key (kbd "C-c C-r") 'ivy-resume)
(spacemacs//hjkl-completion-navigation)) (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 (use-package swiper
:config :config
(defun spacemacs/swiper-region-or-symbol () (defun spacemacs/swiper-region-or-symbol ()

View file

@ -906,36 +906,3 @@ current major mode."
(when (and (integerp shift-width) (when (and (integerp shift-width)
(< 0 shift-width)) (< 0 shift-width))
(setq-local evil-shift-width 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))) (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//helm-hjkl-navigation) (when (fboundp 'spacemacs//hjkl-completion-navigation)
(spacemacs//helm-hjkl-navigation nil))) (spacemacs//hjkl-completion-navigation nil)))
(when (fboundp 'spacemacs//helm-hjkl-navigation) (when (fboundp 'spacemacs//hjkl-completion-navigation)
(spacemacs//helm-hjkl-navigation t)) (spacemacs//hjkl-completion-navigation 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))))))