-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheol-indicator.el
55 lines (50 loc) · 2.41 KB
/
eol-indicator.el
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
53
54
55
(defvar my-eol-ruler nil
"A horizontal ruler stretching from eol (end of line) to the window edge.")
(make-variable-buffer-local 'my-eol-ruler)
(defvar my-eol-pilcrow nil
"A pilcrow symbol placed at the end of every line except the current line.")
(make-variable-buffer-local 'my-eol-pilcrow)
(defsubst col-at-eovl ()
(save-excursion
(let ((movement-indicator (vertical-motion 1)))
(when (= movement-indicator 1)
(backward-char 1)))
(- (current-column) (progn (vertical-motion 0) (current-column)))))
(defun my-eol-ruler-function ()
(when (not (minibufferp (current-buffer)))
(when (or my-eol-ruler my-eol-pilcrow)
(dolist (description `(,my-eol-ruler ,my-eol-pilcrow))
(remove-overlays (point-min) (point-max) 'after-string description)))
(let* ((opoint-peol (line-end-position))
(window-width (window-width))
(window-start (window-start))
(window-end (window-end nil t))
(col-eovl (col-at-eovl))
(my-current-line-length (if (not (= opoint-peol (point-max)))
(- (- window-width col-eovl) 2)
(- (- window-width col-eovl) 1)))
(pilcrow
(propertize (char-to-string ?\u00B6)
'face '(:foreground "red")
'cursor t))
(pilcrow-underlined
(propertize (char-to-string ?\u00B6)
'face '(:foreground "RoyalBlue" :underline "blue")
'cursor t))
(underline (propertize (char-to-string ?\u2009)
'display `(space :width ,my-current-line-length)
'face '(:underline "blue")
'cursor t)))
(setq my-eol-ruler (if (not (= opoint-peol (point-max)))
(concat pilcrow-underlined underline)
underline))
(setq my-eol-pilcrow pilcrow)
(overlay-put (make-overlay opoint-peol opoint-peol) 'after-string my-eol-ruler)
(save-excursion
(goto-char window-end)
(while (re-search-backward "\n" window-start t)
(let ((peol (line-end-position)))
(when (not (= peol opoint-peol))
(overlay-put (make-overlay peol peol) 'after-string my-eol-pilcrow))))))))
(add-hook 'post-command-hook 'my-eol-ruler-function)
(provide 'eol-indicator)