about summary refs log tree commit diff stats
path: root/lisp/+pulse.el
blob: eefdd83bc62c57c59a4b30908de0f39e6224236b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;;; +pulse.el -*- lexical-binding: t; -*-

;;; Code:

(require 'pulse)

(defgroup +pulse nil
  "Extra customizations for `pulse'."
  :group 'pulse
  :prefix "+pulse-")

(defcustom +pulse-location-commands '(scroll-up-command
                                      scroll-down-command
                                      recenter-top-bottom
                                      other-window
                                      switch-to-buffer
                                      redraw-frame)
  "Commands to pulse the current line after.
Good for finding location."
  :type '(repeat function))

(defcustom +pulse-location-function '+pulse-line-current-window
  "What function to call after `+pulse-location-commands'."
  :type 'function)

;; XXX: this doesn't work yet.  I only want to pulse the line in the
;; active window, so when I have the same buffer viewed in multiple
;; windows I can still see where my cursor is.  To see the issue, C-x
;; 2 then C-x o a few times.
(defun +pulse-line-current-window (&rest _)
  "Pulse the current line, but only if this window is active."
  (pulse-momentary-highlight-one-line
   (window-point (selected-window))))

(defun +pulse--advice-remove (symbol where function &optional props)
  "Remove advice SYMBOL from FUNCTION.
This uses the same args as `advice-add' for easy toggling.
WHERE and PROPS are discarded."
  (ignore where props)
  (advice-remove symbol function))

(define-minor-mode +pulse-location-mode
  "After moving locations, pulse where we are."
  :global t
  :keymap nil
  (dolist (command +pulse-location-commands)
    (funcall
     (if +pulse-location-mode 'advice-add '+pulse--advice-remove)
     command :after +pulse-location-function)))

(provide '+pulse)
;;; +pulse.el ends here