Update automatic highlight of symbol toggle

This commit is contained in:
syl20bnr 2015-09-28 22:12:08 -04:00
parent 3e5c98d880
commit afa537d341
2 changed files with 62 additions and 55 deletions

View File

@ -1022,31 +1022,31 @@ toggle them.
Some toggle have two flavors: local and global. The global version of the toggle
can be reached using the =control= key.
| Key Binding | Unicode | ASCII | Mode |
|-------------+---------+-------+---------------------------------------------|
| ~SPC t -~ | =⊝= | - | [[http://emacswiki.org/emacs/centered-cursor-mode.el][centered-cursor]] mode |
| ~SPC t C--~ | =⊝= | | global centered cursor |
| ~SPC t a~ | =ⓐ= | a | auto-completion |
| ~SPC t c~ | =ⓒ= | c | camel case motion with subword mode |
| =none= | =ⓔ= | e | [[https://github.com/edwtjo/evil-org-mode][evil-org]] mode |
| ~SPC t E e~ | =Ⓔe= | Ee | emacs editing style (holy mode) |
| ~SPC t E h~ | =Ⓔh= | Eh | hybrid editing style (hybrid mode) |
| ~SPC t f~ | | | fill-column-indicator mode |
| ~SPC t F~ | =Ⓕ= | F | auto-fill mode |
| ~SPC t g~ | =ⓖ= | g | [[https://github.com/roman/golden-ratio.el][golden-ratio]] mode |
| ~SPC t h i~ | =ⓗi= | h | toggle highlight indentation levels |
| ~SPC t h c~ | =ⓗc= | hc | toggle highlight indentation current column |
| ~SPC t i~ | =ⓘ= | i | indentation guide |
| ~SPC t C-i~ | =ⓘ= | i | global indentation guide |
| ~SPC t I~ | =Ⓘ= | I | aggressive indent mode |
| ~SPC t K~ | =Ⓚ= | K | which-key mode |
| ~SPC t p~ | =ⓟ= | p | [[https://github.com/Fuco1/smartparens][smartparens]] mode |
| ~SPC t C-p~ | =ⓟ= | | global smartparens |
| ~SPC t s~ | =ⓢ= | s | syntax checking (flycheck) |
| ~SPC t S~ | =Ⓢ= | S | spell checking (flyspell) |
| ~SPC t w~ | =ⓦ= | w | whitespace mode |
| ~SPC t C-w~ | =Ⓦ= | W | global whitespace |
| ~SPC t y~ | =ⓨ= | y | [[https://github.com/capitaomorte/yasnippet][yasnippet]] mode |
| Key Binding | Unicode | ASCII | Mode |
|-------------+---------+-------+--------------------------------------------------|
| ~SPC t -~ | =⊝= | - | [[http://emacswiki.org/emacs/centered-cursor-mode.el][centered-cursor]] mode |
| ~SPC t C--~ | =⊝= | | global centered cursor |
| ~SPC t a~ | =ⓐ= | a | auto-completion |
| ~SPC t c~ | =ⓒ= | c | camel case motion with subword mode |
| =none= | =ⓔ= | e | [[https://github.com/edwtjo/evil-org-mode][evil-org]] mode |
| ~SPC t E e~ | =Ⓔe= | Ee | emacs editing style (holy mode) |
| ~SPC t E h~ | =Ⓔh= | Eh | hybrid editing style (hybrid mode) |
| ~SPC t f~ | | | fill-column-indicator mode |
| ~SPC t F~ | =Ⓕ= | F | auto-fill mode |
| ~SPC t g~ | =ⓖ= | g | [[https://github.com/roman/golden-ratio.el][golden-ratio]] mode |
| ~SPC t h i~ | =ⓗi= | hi | toggle highlight indentation levels |
| ~SPC t h c~ | =ⓗc= | hc | toggle highlight indentation current column |
| ~SPC t i~ | =ⓘ= | i | indentation guide |
| ~SPC t C-i~ | =ⓘ= | i | global indentation guide |
| ~SPC t I~ | =Ⓘ= | I | aggressive indent mode |
| ~SPC t K~ | =Ⓚ= | K | which-key mode |
| ~SPC t p~ | =ⓟ= | p | [[https://github.com/Fuco1/smartparens][smartparens]] mode |
| ~SPC t C-p~ | =ⓟ= | | global smartparens |
| ~SPC t s~ | =ⓢ= | s | syntax checking (flycheck) |
| ~SPC t S~ | =Ⓢ= | S | spell checking (flyspell) |
| ~SPC t w~ | =ⓦ= | w | whitespace mode |
| ~SPC t C-w~ | =Ⓦ= | W | global whitespace |
| ~SPC t y~ | =ⓨ= | y | [[https://github.com/capitaomorte/yasnippet][yasnippet]] mode |
**** Customizing the mode-line
The mode-line consists of a number of /segments/ arranged on the left and right
@ -1937,14 +1937,14 @@ To initiate the highlighting of the current symbol under point press ~SPC s h~.
Navigation between the highlighted symbols can be done with the commands:
| Key Binding | Description |
|-------------+------------------------------------------------------------------------------|
| ~/~ | initiate navigation micro-state on current symbol and jump forwards |
| ~#~ | initiate navigation micro-state on current symbol and jump backwards |
| ~SPC s e~ | edit all occurrences of the current symbol(/) |
| ~SPC s h~ | highlight the current symbol and all its occurrence within the current range |
| ~SPC s H~ | go to the last searched occurrence of the last highlighted symbol |
| ~SPC s R~ | change range to default (=whole buffer=) |
| Key Binding | Description |
|-------------+------------------------------------------------------------------------------------|
| ~/~ | initiate navigation micro-state on current symbol and jump forwards |
| ~#~ | initiate navigation micro-state on current symbol and jump backwards |
| ~SPC s e~ | edit all occurrences of the current symbol(/) |
| ~SPC s h~ | highlight the current symbol and all its occurrence within the current range |
| ~SPC s H~ | go to the last searched occurrence of the last highlighted symbol |
| ~SPC t h a~ | toggle automatic highlight of symbol under point after =ahs-idle-interval= seconds |
In 'Spacemacs' highlight symbol micro-state:

View File

@ -185,25 +185,30 @@
ahs-default-range 'ahs-range-whole-buffer
;; by default disable auto-highlight of symbol
;; current symbol can always be highlighted with <SPC> s h
ahs-start-timer nil
ahs-idle-interval 1
ahs-idle-timer 0
ahs-idle-interval 0.25
ahs-inhibit-face-list nil)
(spacemacs|add-toggle automatic-symbol-highlight-globally
(spacemacs|add-toggle automatic-symbol-highlight
:status (timerp ahs-idle-timer)
:on (setq ahs-idle-timer (run-with-idle-timer ahs-idle-interval t
'ahs-idle-function))
:on (progn
(auto-highlight-symbol-mode)
(setq ahs-idle-timer
(run-with-idle-timer ahs-idle-interval t
'ahs-idle-function)))
:off (when (timerp ahs-idle-timer)
(auto-highlight-symbol-mode)
(cancel-timer ahs-idle-timer)
(setq ahs-idle-timer nil))
(setq ahs-idle-timer 0))
:documentation "Automatic highlight of current symbol."
:evil-leader "tha")
(spacemacs/add-to-hooks 'auto-highlight-symbol-mode '(prog-mode-hook
markdown-mode-hook)))
:config
(progn
(spacemacs|hide-lighter auto-highlight-symbol-mode)
(defvar-local spacemacs-last-ahs-highlight-p nil
"Info on the last searched highlighted symbol.")
(defvar-local spacemacs--ahs-searching-forward t)
(defun spacemacs/goto-last-searched-ahs-symbol ()
@ -212,14 +217,17 @@
(interactive)
(if spacemacs-last-ahs-highlight-p
(progn (goto-char (nth 1 spacemacs-last-ahs-highlight-p))
(eval '(progn (spacemacs/ahs-highlight-now-wrapper) (ahs-back-to-start)) nil))
(spacemacs/ahs-highlight-now-wrapper)
(spacemacs/symbol-highlight-micro-state))
(message "No symbol has been searched for now.")))
(defun spacemacs/integrate-evil-search (forward)
;; isearch-string is last searched item. Next time
;; "n" is hit we will use this.
(setq isearch-string (concat "\\<" (evil-find-thing forward 'symbol) "\\>"))
(setq isearch-regexp (concat "\\<" (evil-find-thing forward 'symbol) "\\>"))
(setq isearch-string
(concat "\\<" (evil-find-thing forward 'symbol) "\\>")
isearch-regexp
(concat "\\<" (evil-find-thing forward 'symbol) "\\>"))
;; Next time "n" is hit, go the correct direction.
(setq isearch-forward forward)
;; ahs does a case sensitive search. We could set
@ -234,8 +242,8 @@
;; Use this search term for empty pattern "%s//replacement/"
;; Append case sensitivity
(setq evil-ex-last-was-search nil
evil-ex-substitute-pattern `(,(concat isearch-string "\\C") nil (0 0)))
)
evil-ex-substitute-pattern `(,(concat isearch-string "\\C")
nil (0 0))))
(defun spacemacs/ensure-ahs-enabled-locally ()
"Ensures ahs is enabled for the local buffer."
@ -286,7 +294,7 @@
(spacemacs/ahs-highlight-now-wrapper)
(when (configuration-layer/package-usedp 'evil-jumper)
(evil-set-jump))
(spacemacs/highlight-symbol-micro-state)
(spacemacs/symbol-highlight-micro-state)
(ahs-forward)
)
(progn
@ -294,21 +302,23 @@
(spacemacs/ahs-highlight-now-wrapper)
(when (configuration-layer/package-usedp 'evil-jumper)
(evil-set-jump))
(spacemacs/highlight-symbol-micro-state)
(spacemacs/symbol-highlight-micro-state)
(ahs-backward)
)))
(eval-after-load 'evil
'(progn
(define-key evil-motion-state-map (kbd "*") 'spacemacs/enter-ahs-forward)
(define-key evil-motion-state-map (kbd "#") 'spacemacs/enter-ahs-backward)))
(define-key evil-motion-state-map (kbd "*")
'spacemacs/enter-ahs-forward)
(define-key evil-motion-state-map (kbd "#")
'spacemacs/enter-ahs-backward)))
(defun spacemacs/symbol-highlight ()
"Highlight the symbol under point with `auto-highlight-symbol'."
(interactive)
(spacemacs/ahs-highlight-now-wrapper)
(setq spacemacs-last-ahs-highlight-p (ahs-highlight-p))
(spacemacs/highlight-symbol-micro-state)
(spacemacs/symbol-highlight-micro-state)
(spacemacs/integrate-evil-search nil))
(defun spacemacs//ahs-ms-on-exit ()
@ -323,10 +333,7 @@
(evil-leader/set-key
"sh" 'spacemacs/symbol-highlight
"sH" 'spacemacs/goto-last-searched-ahs-symbol
"sR" 'spacemacs/symbol-highlight-reset-range)
(spacemacs|hide-lighter auto-highlight-symbol-mode)
"sH" 'spacemacs/goto-last-searched-ahs-symbol)
;; micro-state to easily jump from a highlighted symbol to the others
(dolist (sym '(ahs-forward
@ -342,7 +349,7 @@
(spacemacs/ahs-highlight-now-wrapper)
(setq spacemacs-last-ahs-highlight-p (ahs-highlight-p))))))
(spacemacs|define-micro-state highlight-symbol
(spacemacs|define-micro-state symbol-highlight
:doc (let* ((i 0)
(overlay-count (length ahs-overlay-list))
(overlay (format "%s" (nth i ahs-overlay-list)))