2016-01-30 18:53:20 +00:00
|
|
|
;;; packages.el --- Spacemacs Editing Visual Layer packages File
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
(setq spacemacs-editing-visual-packages
|
|
|
|
'(
|
|
|
|
;; default
|
|
|
|
adaptive-wrap
|
|
|
|
auto-highlight-symbol
|
|
|
|
highlight-indentation
|
|
|
|
highlight-numbers
|
|
|
|
highlight-parentheses
|
|
|
|
;; waiting for an overlay bug to be fixed
|
|
|
|
;; see https://github.com/syl20bnr/spacemacs/issues/2529
|
|
|
|
(hl-anything :excluded t)
|
|
|
|
indent-guide
|
|
|
|
linum-relative
|
|
|
|
rainbow-delimiters
|
|
|
|
volatile-highlights
|
|
|
|
))
|
|
|
|
|
|
|
|
;; Initialization of packages
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-adaptive-wrap ()
|
|
|
|
(use-package adaptive-wrap
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(add-hook 'visual-line-mode-hook 'adaptive-wrap-prefix-mode))))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-auto-highlight-symbol ()
|
|
|
|
(use-package auto-highlight-symbol
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(setq ahs-case-fold-search nil
|
|
|
|
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-idle-timer 0
|
|
|
|
ahs-idle-interval 0.25
|
|
|
|
ahs-inhibit-face-list nil)
|
|
|
|
|
2016-02-04 03:56:53 +00:00
|
|
|
;; since we are creating our own maps,
|
|
|
|
;; prevent the default keymap from getting created
|
|
|
|
(setq auto-highlight-symbol-mode-map (make-sparse-keymap))
|
|
|
|
|
2016-01-30 18:53:20 +00:00
|
|
|
(spacemacs|add-toggle automatic-symbol-highlight
|
|
|
|
:status (timerp ahs-idle-timer)
|
|
|
|
: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 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 ()
|
|
|
|
"Go to the last known occurrence of the last symbol searched with
|
|
|
|
`auto-highlight-symbol'."
|
|
|
|
(interactive)
|
|
|
|
(if spacemacs-last-ahs-highlight-p
|
|
|
|
(progn (goto-char (nth 1 spacemacs-last-ahs-highlight-p))
|
|
|
|
(spacemacs/ahs-highlight-now-wrapper)
|
|
|
|
(spacemacs/symbol-highlight-transient-state/body))
|
|
|
|
(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) "\\>")
|
|
|
|
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
|
|
|
|
;; this, but it would break the user's current
|
|
|
|
;; sensitivity settings. We could save the setting,
|
|
|
|
;; then next time the user starts a search we could
|
|
|
|
;; restore the setting.
|
|
|
|
;;(setq case-fold-search nil)
|
|
|
|
;; Place the search term into the search rings.
|
|
|
|
(isearch-update-ring isearch-string t)
|
|
|
|
(evil-push-search-history isearch-string forward)
|
|
|
|
;; 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))))
|
|
|
|
|
|
|
|
(defun spacemacs/ensure-ahs-enabled-locally ()
|
|
|
|
"Ensures ahs is enabled for the local buffer."
|
|
|
|
(unless
|
|
|
|
(bound-and-true-p ahs-mode-line)
|
|
|
|
(auto-highlight-symbol-mode)
|
|
|
|
))
|
|
|
|
|
|
|
|
(defun spacemacs/ahs-highlight-now-wrapper ()
|
|
|
|
"Safe wrapper for ahs-highlight-now"
|
|
|
|
(eval '(progn
|
|
|
|
(spacemacs/ensure-ahs-enabled-locally)
|
|
|
|
(ahs-highlight-now)) nil))
|
|
|
|
|
|
|
|
(defun spacemacs/enter-ahs-forward ()
|
|
|
|
"Go to the next occurrence of symbol under point with
|
|
|
|
`auto-highlight-symbol'"
|
|
|
|
(interactive)
|
|
|
|
(setq spacemacs--ahs-searching-forward t)
|
|
|
|
(spacemacs/quick-ahs-forward))
|
|
|
|
|
|
|
|
(defun spacemacs/enter-ahs-backward ()
|
|
|
|
"Go to the previous occurrence of symbol under point with
|
|
|
|
`auto-highlight-symbol'"
|
|
|
|
(interactive)
|
|
|
|
(setq spacemacs--ahs-searching-forward nil)
|
|
|
|
(spacemacs/quick-ahs-forward))
|
|
|
|
|
|
|
|
(defun spacemacs/quick-ahs-forward ()
|
|
|
|
"Go to the next occurrence of symbol under point with
|
|
|
|
`auto-highlight-symbol'"
|
|
|
|
(interactive)
|
|
|
|
(spacemacs//quick-ahs-move t))
|
|
|
|
|
|
|
|
(defun spacemacs/quick-ahs-backward ()
|
|
|
|
"Go to the previous occurrence of symbol under point with
|
|
|
|
`auto-highlight-symbol'"
|
|
|
|
(interactive)
|
|
|
|
(spacemacs//quick-ahs-move nil))
|
|
|
|
|
|
|
|
(defun spacemacs//quick-ahs-move (forward)
|
|
|
|
"Go to the next occurrence of symbol under point with
|
|
|
|
`auto-highlight-symbol'"
|
|
|
|
|
|
|
|
(if (eq forward spacemacs--ahs-searching-forward)
|
|
|
|
(progn
|
|
|
|
(spacemacs/integrate-evil-search t)
|
|
|
|
(spacemacs/ahs-highlight-now-wrapper)
|
2016-02-15 19:15:29 +00:00
|
|
|
(evil-set-jump)
|
2016-01-30 18:53:20 +00:00
|
|
|
(spacemacs/symbol-highlight-transient-state/body)
|
|
|
|
(ahs-forward))
|
|
|
|
(progn
|
|
|
|
(spacemacs/integrate-evil-search nil)
|
|
|
|
(spacemacs/ahs-highlight-now-wrapper)
|
2016-02-15 19:15:29 +00:00
|
|
|
(evil-set-jump)
|
2016-01-30 18:53:20 +00:00
|
|
|
(spacemacs/symbol-highlight-transient-state/body)
|
|
|
|
(ahs-backward))))
|
|
|
|
|
|
|
|
(with-eval-after-load 'evil
|
|
|
|
(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/symbol-highlight-transient-state/body)
|
|
|
|
(spacemacs/integrate-evil-search nil))
|
|
|
|
|
|
|
|
(defun spacemacs//ahs-ms-on-exit ()
|
|
|
|
;; Restore user search direction state as ahs has exitted in a state
|
|
|
|
;; good for <C-s>, but not for 'n' and 'N'"
|
|
|
|
(setq isearch-forward spacemacs--ahs-searching-forward))
|
|
|
|
|
|
|
|
(defun spacemacs/symbol-highlight-reset-range ()
|
|
|
|
"Reset the range for `auto-highlight-symbol'."
|
|
|
|
(interactive)
|
|
|
|
(ahs-change-range ahs-default-range))
|
|
|
|
|
|
|
|
(spacemacs/set-leader-keys
|
|
|
|
"sh" 'spacemacs/symbol-highlight
|
|
|
|
"sH" 'spacemacs/goto-last-searched-ahs-symbol)
|
|
|
|
|
|
|
|
;; micro-state to easily jump from a highlighted symbol to the others
|
|
|
|
(dolist (sym '(ahs-forward
|
|
|
|
ahs-forward-definition
|
|
|
|
ahs-backward
|
|
|
|
ahs-backward-definition
|
|
|
|
ahs-back-to-start
|
|
|
|
ahs-change-range))
|
|
|
|
(let* ((advice (intern (format "spacemacs/%s" (symbol-name sym)))))
|
|
|
|
(eval `(defadvice ,sym (around ,advice activate)
|
|
|
|
(spacemacs/ahs-highlight-now-wrapper)
|
|
|
|
ad-do-it
|
|
|
|
(spacemacs/ahs-highlight-now-wrapper)
|
|
|
|
(setq spacemacs-last-ahs-highlight-p (ahs-highlight-p))))))
|
|
|
|
|
|
|
|
(defun symbol-highlight-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" propplugin propx/y prophidden))))
|
|
|
|
|
|
|
|
(defun ahs-to-iedit ()
|
|
|
|
(interactive)
|
2016-02-17 04:00:40 +00:00
|
|
|
(cond
|
|
|
|
((and (not (eq dotspacemacs-editing-style 'emacs))
|
|
|
|
(configuration-layer/package-usedp 'evil-iedit-state))
|
|
|
|
(evil-iedit-state/iedit-mode))
|
|
|
|
((and (eq dotspacemacs-editing-style 'emacs)
|
|
|
|
(configuration-layer/package-usedp 'iedit))
|
|
|
|
(iedit-mode))
|
|
|
|
(t (ahs-edit-mode t))))
|
2016-01-30 18:53:20 +00:00
|
|
|
|
|
|
|
(spacemacs|define-transient-state symbol-highlight
|
|
|
|
:title "Symbol Highlight Transient State"
|
|
|
|
:doc "
|
2016-01-26 15:58:24 +00:00
|
|
|
%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"
|
2016-01-30 18:53:20 +00:00
|
|
|
:before-exit (spacemacs//ahs-ms-on-exit)
|
|
|
|
:bindings
|
|
|
|
("d" ahs-forward-definition)
|
|
|
|
("D" ahs-backward-definition)
|
|
|
|
("e" ahs-to-iedit :exit t)
|
|
|
|
("n" spacemacs/quick-ahs-forward)
|
|
|
|
("N" spacemacs/quick-ahs-backward)
|
|
|
|
("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/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/symbol-highlight-transient-state/body)
|
|
|
|
(spacemacs/integrate-evil-search nil)))))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-highlight-indentation ()
|
|
|
|
(use-package highlight-indentation
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(spacemacs|add-toggle highlight-indentation
|
|
|
|
:status highlight-indentation-mode
|
|
|
|
:on (highlight-indentation-mode)
|
|
|
|
:off (highlight-indentation-mode -1)
|
|
|
|
:documentation "Highlight indentation levels."
|
|
|
|
:evil-leader "thi")
|
|
|
|
(spacemacs|add-toggle highlight-indentation-current-column
|
|
|
|
:status highlight-indentation-current-column-mode
|
|
|
|
:on (highlight-indentation-current-column-mode)
|
|
|
|
:off (highlight-indentation-current-column-mode -1)
|
|
|
|
:documentation "Highlight indentation level at point."
|
|
|
|
:evil-leader "thc"))
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(spacemacs|diminish highlight-indentation-mode " ⓗi" " hi")
|
|
|
|
(spacemacs|diminish highlight-indentation-current-column-mode " ⓗc" " hc"))))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-highlight-numbers ()
|
|
|
|
(use-package highlight-numbers
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(add-hook 'prog-mode-hook 'highlight-numbers-mode)
|
|
|
|
(add-hook 'asm-mode-hook (lambda () (highlight-numbers-mode -1))))))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-highlight-parentheses ()
|
|
|
|
(use-package highlight-parentheses
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(when (member dotspacemacs-highlight-delimiters '(all current))
|
|
|
|
(add-hook 'prog-mode-hook #'highlight-parentheses-mode))
|
|
|
|
(setq hl-paren-delay 0.2)
|
|
|
|
(spacemacs/set-leader-keys "tCp" 'highlight-parentheses-mode)
|
|
|
|
(setq hl-paren-colors '("Springgreen3"
|
|
|
|
"IndianRed1"
|
|
|
|
"IndianRed3"
|
|
|
|
"IndianRed4")))
|
|
|
|
:config
|
|
|
|
(spacemacs|hide-lighter highlight-parentheses-mode)
|
|
|
|
(set-face-attribute 'hl-paren-face nil :weight 'ultra-bold)))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-hl-anything ()
|
|
|
|
(use-package hl-anything
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(hl-highlight-mode)
|
|
|
|
(setq-default hl-highlight-save-file
|
|
|
|
(concat spacemacs-cache-directory ".hl-save"))
|
|
|
|
(spacemacs/set-leader-keys
|
|
|
|
"hc" 'hl-unhighlight-all-local
|
|
|
|
"hC" 'hl-unhighlight-all-global
|
|
|
|
"hh" 'hl-highlight-thingatpt-local
|
|
|
|
"hH" 'hl-highlight-thingatpt-global
|
|
|
|
"hn" 'hl-find-next-thing
|
|
|
|
"hN" 'hl-find-prev-thing
|
|
|
|
"hr" 'hl-restore-highlights
|
|
|
|
"hs" 'hl-save-highlights))
|
|
|
|
:config (spacemacs|hide-lighter hl-highlight-mode)))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-indent-guide ()
|
|
|
|
(use-package indent-guide
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(setq indent-guide-delay 0.3)
|
|
|
|
(spacemacs|add-toggle indent-guide
|
|
|
|
:status indent-guide-mode
|
|
|
|
:on (indent-guide-mode)
|
|
|
|
:off (indent-guide-mode -1)
|
|
|
|
:documentation
|
|
|
|
"Highlight indentation level at point. (alternative to highlight-indentation)."
|
|
|
|
:evil-leader "ti")
|
|
|
|
(spacemacs|add-toggle indent-guide-globally
|
|
|
|
:status indent-guide-mode
|
|
|
|
:on (indent-guide-global-mode)
|
|
|
|
:off (indent-guide-global-mode -1)
|
|
|
|
:documentation
|
|
|
|
"Highlight indentation level at point globally. (alternative to highlight-indentation)."
|
|
|
|
:evil-leader "t TAB"))
|
|
|
|
:config
|
|
|
|
(spacemacs|diminish indent-guide-mode " ⓘ" " i")))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-linum-relative ()
|
|
|
|
(use-package linum-relative
|
|
|
|
:commands (linum-relative-toggle linum-relative-on)
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(when (eq dotspacemacs-line-numbers 'relative)
|
|
|
|
(linum-relative-on))
|
|
|
|
(spacemacs/set-leader-keys "tr" 'linum-relative-toggle))
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(setq linum-relative-current-symbol ""))))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-rainbow-delimiters ()
|
|
|
|
(use-package rainbow-delimiters
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(spacemacs/set-leader-keys "tCd" 'rainbow-delimiters-mode)
|
|
|
|
(when (member dotspacemacs-highlight-delimiters '(any all))
|
|
|
|
(spacemacs/add-to-hooks 'rainbow-delimiters-mode '(prog-mode-hook))))))
|
|
|
|
|
|
|
|
(defun spacemacs-editing-visual/init-volatile-highlights ()
|
|
|
|
(use-package volatile-highlights
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(volatile-highlights-mode t)
|
|
|
|
(spacemacs|hide-lighter volatile-highlights-mode))))
|
|
|
|
|