Function: whitespace--update-bob-eob
whitespace--update-bob-eob is a byte-compiled function defined in
whitespace.el.gz.
Signature
(whitespace--update-bob-eob &optional BEG END &rest _)
Documentation
Update whitespace-bob-marker and whitespace-eob-marker.
Also apply font-lock-multiline text property. If BEG and END
are non-nil, assume that only characters in that range have
changed since the last call to this function (for optimization
purposes).
Source Code
;; Defined in /usr/src/emacs/lisp/whitespace.el.gz
(defun whitespace--update-bob-eob (&optional beg end &rest _)
"Update `whitespace-bob-marker' and `whitespace-eob-marker'.
Also apply `font-lock-multiline' text property. If BEG and END
are non-nil, assume that only characters in that range have
changed since the last call to this function (for optimization
purposes)."
(when (memq 'empty whitespace-active-style)
;; When a line is changed, `font-lock-mode' normally limits
;; re-processing to only the changed line. That behavior is
;; problematic for highlighting `empty' lines because adding or
;; deleting a character might affect lines before or after the
;; change. To address this, all `empty' lines are marked with a
;; non-nil `font-lock-multiline' text property. This forces
;; `font-lock-mode' to re-process all of the lines whenever
;; there's an edit within any one of them.
;;
;; The text property must be set on `empty' lines twice per
;; relevant change:
;;
;; 1. Before the change. This is necessary to ensure that
;; previously highlighted lines become un-highlighted if
;; necessary. The text property must be added after the
;; previous `font-lock-mode' run (the run in reaction to the
;; previous change) because `font-lock-mode' clears the text
;; property when it runs.
;;
;; 2. After the change, but before `font-lock-mode' reacts to
;; the change. This is necessary to ensure that new `empty'
;; lines become highlighted.
;;
;; This hook function is responsible for #2, while the
;; `whitespace--empty-at-bob-matcher' and
;; `whitespace--empty-at-eob-matcher' functions are responsible
;; for #1. (Those functions run after `font-lock-mode' clears the
;; text property and before the next change.)
(save-excursion
(save-restriction
(widen)
(let ((inhibit-read-only t))
(when (or (null beg)
(<= beg (save-excursion
(goto-char whitespace-bob-marker)
;; Any change in the first non-`empty'
;; line, even if it's not the first
;; character in the line, can potentially
;; cause subsequent lines to become
;; classified as `empty' (e.g., delete the
;; "x" from " x").
(forward-line 1)
(point))))
(goto-char 1)
(set-marker whitespace-bob-marker (point))
(save-match-data
(when (looking-at whitespace-empty-at-bob-regexp)
(set-marker whitespace-bob-marker (match-end 1))
(with-silent-modifications
(put-text-property (match-beginning 1) (match-end 1)
'font-lock-multiline t)))))
(when (or (null end)
(>= end (save-excursion
(goto-char whitespace-eob-marker)
;; See above comment for the BoB case.
(forward-line -1)
(point))))
(goto-char (1+ (buffer-size)))
(set-marker whitespace-eob-marker (point))
(save-match-data
(when (whitespace--looking-back
whitespace-empty-at-eob-regexp)
(set-marker whitespace-eob-marker (match-beginning 1))
(with-silent-modifications
(put-text-property (match-beginning 1) (match-end 1)
'font-lock-multiline t))))))))))