-
Notifications
You must be signed in to change notification settings - Fork 3
/
erc-better-scroll.el
78 lines (73 loc) · 3.06 KB
/
erc-better-scroll.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
;; erc-better-scroll.el
;; this code comes from Deniz Dogan, who attached it to a message to
;; the bug-gnu-emacs mailing list
;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2012-06/msg00360.html
;; he gets full credit
;; probably gpl3 license
(defun erc-display-line-1 (string buffer)
"Display STRING in `erc-mode' BUFFER.
Auxiliary function used in `erc-display-line'. The line gets filtered to
interpret the control characters. Then, `erc-insert-pre-hook' gets called.
If `erc-insert-this' is still t, STRING gets inserted into the buffer.
Afterwards, `erc-insert-modify' and `erc-insert-post-hook' get called.
If STRING is nil, the function does nothing."
(when string
(with-current-buffer (or buffer (process-buffer erc-server-process))
(let ((insert-position (or (marker-position erc-insert-marker)
(point-max))))
(let ((string string) ;; FIXME! Can this be removed?
(buffer-undo-list t)
(inhibit-read-only t))
(unless (string-match "\n$" string)
(setq string (concat string "\n"))
(when (erc-string-invisible-p string)
(erc-put-text-properties 0 (length string)
'(invisible intangible) string)))
(erc-log (concat "erc-display-line: " string
(format "(%S)" string) " in buffer "
(format "%s" buffer)))
(setq erc-insert-this t)
(run-hook-with-args 'erc-insert-pre-hook string)
(if (null erc-insert-this)
;; Leave erc-insert-this set to t as much as possible. Fran
;; Litterio <franl> has seen erc-insert-this set to nil while
;; erc-send-pre-hook is running, which should never happen. This
;; may cure it.
(setq erc-insert-this t)
(save-excursion ;; to restore point in the new buffer
(save-restriction
(widen)
(goto-char insert-position)
(insert-before-markers string)
;; run insertion hook, with point at restored location
(save-restriction
(narrow-to-region insert-position (point))
(run-hooks 'erc-insert-modify-hook)
(run-hooks 'erc-insert-post-hook)
(when erc-remove-parsed-property
(remove-text-properties (point-min) (point-max)
'(erc-parsed nil))))))))
(erc-update-undo-list (- (or (marker-position erc-insert-marker)
(point-max))
insert-position)))
(run-hooks 'erc-display-post-hook)))) ;;; this line and only this line was added
(defvar erc-display-post-hook nil
"New hook!")
(defun damd-erc-display-post-hook ()
(let ((windows (get-buffer-window-list (current-buffer) nil 'visible)))
(dolist (w windows)
(when (>= (point) erc-input-marker)
(with-selected-window w
(recenter -1))))))
(add-hook 'erc-display-post-hook 'damd-erc-display-post-hook)
(defun damd-erc-send-post-hook ()
(when (>= (point) erc-input-marker)
(goto-char (point-max))
(widen)
(recenter -1)))
(add-hook 'erc-send-post-hook 'damd-erc-send-post-hook)
(defun damd-window-configuration-change-hook ()
(when (and (eq major-mode 'erc-mode)
(>= (point) erc-input-marker))
(recenter -1)))
(add-hook 'window-configuration-change-hook 'damd-window-configuration-change-hook)