Use spacemacs micro state macro for ahs micro-state.

This is consistent with other micro-states.
This commit is contained in:
person808 2015-08-08 12:21:09 -10:00 committed by syl20bnr
parent a7f3981d97
commit 2c48ee32a5

View file

@ -304,8 +304,7 @@
"Safe wrapper for ahs-highlight-now"
(eval '(progn
(spacemacs/ensure-ahs-enabled-locally)
(ahs-highlight-now)
) nil))
(ahs-highlight-now)) nil))
(defun spacemacs/quick-ahs-forward ()
"Go to the next occurrence of symbol under point with
@ -338,9 +337,8 @@
(eval '(progn
(spacemacs/ahs-highlight-now-wrapper)
(setq spacemacs-last-ahs-highlight-p (ahs-highlight-p))
(spacemacs/auto-highlight-symbol-overlay-map)
(spacemacs/integrate-evil-search nil)
) nil))
(spacemacs/highlight-symbol-micro-state)
(spacemacs/integrate-evil-search nil)) nil))
(defun spacemacs/symbol-highlight-reset-range ()
"Reset the range for `auto-highlight-symbol'."
@ -348,11 +346,12 @@
(eval '(ahs-change-range ahs-default-range) nil))
(evil-leader/set-key
"sh" 'spacemacs/symbol-highlight
"sH" 'spacemacs/goto-last-searched-ahs-symbol
"sR" 'spacemacs/symbol-highlight-reset-range)
"sh" 'spacemacs/symbol-highlight
"sH" 'spacemacs/goto-last-searched-ahs-symbol
"sR" 'spacemacs/symbol-highlight-reset-range)
(spacemacs|hide-lighter auto-highlight-symbol-mode)
;; micro-state to easily jump from a highlighted symbol to the others
(dolist (sym '(ahs-forward
ahs-forward-definition
@ -363,50 +362,48 @@
(let* ((advice (intern (format "spacemacs/%s" (symbol-name sym)))))
(eval `(defadvice ,sym (after ,advice activate)
(spacemacs/ahs-highlight-now-wrapper)
(setq spacemacs-last-ahs-highlight-p (ahs-highlight-p))
(spacemacs/auto-highlight-symbol-overlay-map)))))
(defun spacemacs/auto-highlight-symbol-overlay-map ()
"Set a temporary overlay map to easily jump from highlighted symbols to
the nexts."
(interactive)
(set-temporary-overlay-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "d") 'ahs-forward-definition)
(define-key map (kbd "D") 'ahs-backward-definition)
(if (ht-contains? configuration-layer-all-packages 'evil-iedit-state)
(define-key map (kbd "e") 'evil-iedit-state/iedit-mode)
(define-key map (kbd "e") 'ahs-edit-mode))
(define-key map (kbd "n") 'ahs-forward)
(define-key map (kbd "N") 'ahs-backward)
(define-key map (kbd "R") 'ahs-back-to-start)
(define-key map (kbd "r") (lambda () (interactive)
(eval '(ahs-change-range) nil)))
(define-key map (kbd "/") 'spacemacs/helm-project-smart-do-search-region-or-symbol)
(define-key map (kbd "b") 'spacemacs/helm-buffers-smart-do-search-region-or-symbol)
(define-key map (kbd "f") 'spacemacs/helm-files-smart-do-search-region-or-symbol)
map) nil)
(let* ((i 0)
(overlay-count (length ahs-overlay-list))
(overlay (format "%s" (nth i ahs-overlay-list)))
(current-overlay (format "%s" ahs-current-overlay))
(st (ahs-stat))
(plighter (ahs-current-plugin-prop 'lighter))
(plugin (format " <%s> " (cond ((string= plighter "HS") "D")
((string= plighter "HSA") "B")
((string= plighter "HSD") "F"))))
(propplugin (propertize plugin 'face
`(:foreground "#ffffff"
:background ,(face-attribute
'ahs-plugin-defalt-face :foreground)))))
(while (not (string= overlay current-overlay))
(setq i (1+ i))
(setq overlay (format "%s" (nth i ahs-overlay-list))))
(let* ((x/y (format "[%s/%s]" (- overlay-count i) overlay-count))
(propx/y (propertize x/y 'face ahs-plugin-whole-buffer-face))
(hidden (if (< 0 (- overlay-count (nth 4 st))) "*" ""))
(prophidden (propertize hidden 'face '(:weight bold))))
(echo "%s %s%s (n/N) move, (e) edit, (r) range, (R) reset, (d/D) definition, (/) find in project, (f) find in files, (b) find in opened buffers"
propplugin propx/y prophidden)))))))
(setq spacemacs-last-ahs-highlight-p (ahs-highlight-p))))))
(spacemacs|define-micro-state highlight-symbol
:doc (let* ((i 0)
(overlay-count (length ahs-overlay-list))
(overlay (format "%s" (nth i ahs-overlay-list)))
(current-overlay (format "%s" ahs-current-overlay))
(st (ahs-stat))
(plighter (ahs-current-plugin-prop 'lighter))
(plugin (format " <%s> " (cond ((string= plighter "HS") "D")
((string= plighter "HSA") "B")
((string= plighter "HSD") "F"))))
(propplugin (propertize plugin 'face
`(:foreground "#ffffff"
:background ,(face-attribute
'ahs-plugin-defalt-face :foreground)))))
(while (not (string= overlay current-overlay))
(setq i (1+ i))
(setq overlay (format "%s" (nth i ahs-overlay-list))))
(let* ((x/y (format "(%s/%s)" (- overlay-count i) overlay-count))
(propx/y (propertize x/y 'face ahs-plugin-whole-buffer-face))
(hidden (if (< 0 (- overlay-count (nth 4 st))) "*" ""))
(prophidden (propertize hidden 'face '(:weight bold))))
(format "%s %s%s [n/N] move [e] edit [r] range [R] reset [d/D] definition [/] find in project [f] find in files [b] find in opened buffers [q] exit"
propplugin propx/y prophidden)))
:use-minibuffer t
:bindings
("d" ahs-forward-definition)
("D" ahs-backward-definition)
("e" nil
:post (if (configuration-layer/package-usedp 'evil-iedit-state)
(evil-iedit-state/iedit-mode)
(ahs-edit-mode))
:exit t)
("n" spacemacs/quick-ahs-forward)
("N" spacemacs/quick-ahs-backward)
("R" ahs-back-to-start)
("r" ahs-change-range)
("/" spacemacs/helm-project-smart-do-search-region-or-symbol)
("b" spacemacs/helm-buffers-smart-do-search-region-or-symbol)
("f" spacemacs/helm-files-smart-do-search-region-or-symbol)
("q" nil :exit t)))))
(defun spacemacs/init-avy ()
(use-package avy