ahs: move b, f and / key bindings to helm and ivy

Correctly augment the docstring based on the presence of b,f and /
bindings using dynamic hint.
b,f and / are not available if none of helm or ivy layers are used.
This commit is contained in:
syl20bnr 2016-06-09 22:50:24 -04:00
parent 2a07a7fd76
commit f5799ab1ec
4 changed files with 62 additions and 41 deletions

View File

@ -10,7 +10,9 @@
;;; License: GPLv3
(setq helm-packages
'(ace-jump-helm-line
'(
ace-jump-helm-line
auto-highlight-symbol
bookmark
helm
helm-ag
@ -21,7 +23,8 @@
helm-projectile
helm-swoop
helm-themes
(helm-spacemacs-help :location local)))
(helm-spacemacs-help :location local)
))
;; Initialization of packages
@ -32,6 +35,18 @@
(with-eval-after-load 'helm
(define-key helm-map (kbd "C-q") 'ace-jump-helm-line))))
(defun helm/pre-init-auto-highlight-symbol ()
(spacemacs|use-package-add-hook auto-highlight-symbol
:post-init
;; add some functions to ahs transient states
(setq spacemacs--symbol-highlight-transient-state-doc
(concat spacemacs--symbol-highlight-transient-state-doc
" [_b_] search buffers [_/_] search proj [_f_] search files")
spacemacs-symbol-highlight-transient-state-add-bindings
'(("/" spacemacs/helm-project-smart-do-search-region-or-symbol :exit t)
("b" spacemacs/helm-buffers-smart-do-search-region-or-symbol :exit t)
("f" spacemacs/helm-files-smart-do-search-region-or-symbol :exit t)))))
(defun helm/post-init-bookmark ()
(spacemacs/set-leader-keys "fb" 'helm-filtered-bookmarks))

View File

@ -246,28 +246,6 @@ To prevent this error we just wrap `describe-mode' to defeat the
(swiper--cleanup)
(swiper--add-overlays (ivy--regex ivy-text)))))))
;; Evil
(defun spacemacs/ivy-evil-registers ()
"Show evil registers"
(interactive)
(let ((ivy-height 24))
(ivy-read "Evil Registers:"
(cl-loop for (key . val) in (evil-register-list)
collect (eval `(format "%s : %s" (propertize ,(char-to-string key) 'face 'font-lock-builtin-face)
,(or (and val
(stringp val)
(replace-regexp-in-string "\n" "^J" val))
""))))
:action #'spacemacs/ivy-insert-evil-register)))
(defun spacemacs/ivy-insert-evil-register (candidate)
(insert (replace-regexp-in-string "\\^J" "\n"
(substring-no-properties candidate 4))))
;; Ivy
(defun spacemacs//ivy-command-not-implemented-yet (key)
@ -289,7 +267,24 @@ To prevent this error we just wrap `describe-mode' to defeat the
(require (car repl))
(call-interactively (cdr repl))))))
;; Evil
(defun spacemacs/ivy-evil-registers ()
"Show evil registers"
(interactive)
(let ((ivy-height 24))
(ivy-read "Evil Registers:"
(cl-loop for (key . val) in (evil-register-list)
collect (eval `(format "%s : %s" (propertize ,(char-to-string key) 'face 'font-lock-builtin-face)
,(or (and val
(stringp val)
(replace-regexp-in-string "\n" "^J" val))
""))))
:action #'spacemacs/ivy-insert-evil-register)))
(defun spacemacs/ivy-insert-evil-register (candidate)
(insert (replace-regexp-in-string "\\^J" "\n"
(substring-no-properties candidate 4))))
;; Layouts

View File

@ -10,7 +10,8 @@
;;; License: GPLv3
(setq ivy-packages
'(auto-highlight-symbol
'(
auto-highlight-symbol
counsel
(counsel-projectile :toggle (configuration-layer/package-usedp 'projectile))
evil
@ -23,15 +24,20 @@
projectile
smex
swiper
wgrep))
wgrep
))
(defun ivy/post-init-auto-highlight-symbol ()
(setq spacemacs-symbol-highlight-transient-state-remove-bindings
'("/" "b" "f"))
(setq spacemacs-symbol-highlight-transient-state-add-bindings
'(("/" spacemacs/search-project-auto-region-or-symbol :exit t)
("b" spacemacs/swiper-all-region-or-symbol :exit t)
("f" spacemacs/search-auto-region-or-symbol :exit t))))
(defun ivy/pre-init-auto-highlight-symbol ()
(spacemacs|use-package-add-hook auto-highlight-symbol
:post-init
;; add some functions to ahs transient states
(setq spacemacs--symbol-highlight-transient-state-doc
(concat spacemacs--symbol-highlight-transient-state-doc
" [_b_] search buffers [_/_] search proj [_f_] search files")
spacemacs-symbol-highlight-transient-state-add-bindings
'(("/" spacemacs/search-project-auto-region-or-symbol :exit t)
("b" spacemacs/swiper-all-region-or-symbol :exit t)
("f" spacemacs/search-auto-region-or-symbol :exit t)))))
(defun ivy/init-counsel ()
(use-package counsel

View File

@ -45,7 +45,11 @@
;; current symbol can always be highlighted with `SPC s h'
ahs-idle-timer 0
ahs-idle-interval 0.25
ahs-inhibit-face-list nil)
ahs-inhibit-face-list nil
spacemacs--symbol-highlight-transient-state-doc
"
%s [_n_] next [_N_/_p_] previous [_r_] change range [_R_] reset [_e_] iedit
%s [_d_/_D_] next/previous definition")
;; since we are creating our own maps,
;; prevent the default keymap from getting created
@ -243,12 +247,16 @@
(iedit-restrict-region (ahs-current-plugin-prop 'start)
(ahs-current-plugin-prop 'end)))
(t (ahs-edit-mode t))))
;; transient state
(defun spacemacs//symbol-highlight-ts-doc ()
(spacemacs//transient-state-make-doc
'symbol-highlight
(format spacemacs--symbol-highlight-transient-state-doc
(symbol-highlight-doc)
(make-string (length (symbol-highlight-doc)) 32))))
(spacemacs|define-transient-state symbol-highlight
:title "Symbol Highlight Transient State"
:doc "
%s(symbol-highlight-doc) [_n_/_N_/_p_] next/prev/prev [_R_] restart [_e_] iedit [_b_] search buffers
%s(make-string (length (symbol-highlight-doc)) 32) [_d_/_D_]^^ next/prev def'n [_r_] change range [_/_] search proj [_f_] search files"
:dynamic-hint (spacemacs//symbol-highlight-ts-doc)
:before-exit (spacemacs//ahs-ms-on-exit)
:bindings
("d" ahs-forward-definition)
@ -259,9 +267,6 @@
("p" spacemacs/quick-ahs-backward)
("R" ahs-back-to-start)
("r" ahs-change-range)
("/" spacemacs/helm-project-smart-do-search-region-or-symbol :exit t)
("b" spacemacs/helm-buffers-smart-do-search-region-or-symbol :exit t)
("f" spacemacs/helm-files-smart-do-search-region-or-symbol :exit t)
("q" nil :exit t)))))
(defun spacemacs-editing-visual/init-column-enforce-mode ()