summaryrefslogtreecommitdiff
path: root/lisp/whitespace.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-08-07 09:28:14 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-08-07 09:28:14 +0200
commit2a35e54bd5644c52dad99dc2597aff2c4165e1e0 (patch)
tree5e79f5e97320d7ba9594cb8f8f38763addd2d0c2 /lisp/whitespace.el
parent74606481c2859b843ebf3f744c215447458becc2 (diff)
downloademacs-2a35e54bd5644c52dad99dc2597aff2c4165e1e0.tar.gz
Make whitespace-mode highlight missing newlines at the end of buffers
* lisp/whitespace.el (whitespace-missing-newline-at-eof): New face (bug#34952). (whitespace-report-region): Add a test for end-of-buffer-without-newline. (whitespace-color-on): Ditto. * doc/emacs/display.texi (Useless Whitespace): Document it.
Diffstat (limited to 'lisp/whitespace.el')
-rw-r--r--lisp/whitespace.el19
1 files changed, 17 insertions, 2 deletions
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 47434bf3d2e..fb5f28c0029 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -283,7 +283,8 @@
'(face
tabs spaces trailing lines space-before-tab newline
indentation empty space-after-tab
- space-mark tab-mark newline-mark)
+ space-mark tab-mark newline-mark
+ missing-newline-at-eof)
"Specify which kind of blank is visualized.
It's a list containing some or all of the following values:
@@ -326,6 +327,11 @@ It's a list containing some or all of the following values:
It has effect only if `face' (see above)
is present in `whitespace-style'.
+ missing-newline-at-eof Missing newline at the end of the file is
+ visualized via faces.
+ It has effect only if `face' (see above)
+ is present in `whitespace-style'.
+
empty empty lines at beginning and/or end of buffer
are visualized via faces.
It has effect only if `face' (see above)
@@ -586,6 +592,10 @@ line. Used when `whitespace-style' includes the value `indentation'.")
"Face used to visualize big indentation."
:group 'whitespace)
+(defface whitespace-missing-newline-at-eof
+ '((((class mono)) :inverse-video t :weight bold :underline t)
+ (t :background "red" :foreground "firebrick"))
+ "Face used to visualize missing newline at the end of the file.")
(defvar whitespace-empty 'whitespace-empty
"Symbol face used to visualize empty lines at beginning and/or end of buffer.
@@ -1700,6 +1710,8 @@ cleaning up these problems."
(whitespace-space-after-tab-regexp 'tab))
((eq (car option) 'space-after-tab::space)
(whitespace-space-after-tab-regexp 'space))
+ ((eq (car option) 'missing-newline-at-eof)
+ "[^\n]\\'")
(t
(cdr option)))))
(when (re-search-forward regexp rend t)
@@ -2122,7 +2134,10 @@ resultant list will be returned."
((memq 'space-after-tab::space whitespace-active-style)
;; Show SPACEs after TAB (TABs).
(whitespace-space-after-tab-regexp 'space)))
- 1 whitespace-space-after-tab t)))))
+ 1 whitespace-space-after-tab t)))
+ ,@(when (memq 'missing-newline-at-eof whitespace-active-style)
+ ;; Show missing newline.
+ `(("[^\n]\\'" 0 'whitespace-missing-newline-at-eof t)))))
(font-lock-add-keywords nil whitespace-font-lock-keywords t)
(font-lock-flush)))