emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 2a35e54: Make whitespace-mode highlight missing newlines at the e


From: Lars Ingebrigtsen
Subject: master 2a35e54: Make whitespace-mode highlight missing newlines at the end of buffers
Date: Fri, 7 Aug 2020 03:28:25 -0400 (EDT)

branch: master
commit 2a35e54bd5644c52dad99dc2597aff2c4165e1e0
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 doc/emacs/display.texi |  4 ++++
 etc/NEWS               |  7 +++++++
 lisp/whitespace.el     | 19 +++++++++++++++++--
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index e96e43b..5778d95 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -1334,6 +1334,10 @@ customize the variable @code{whitespace-line-column}.
 @item newline
 Highlight newlines.
 
+@item missing-newline-at-eof
+Highlight the final character in a buffer unless it's a newline
+character.
+
 @item empty
 Highlight empty lines at the beginning and/or end of the buffer.
 
diff --git a/etc/NEWS b/etc/NEWS
index 81d07c9..ff3aa84 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -451,6 +451,13 @@ to substitute spaces in regexp search.
 *** The default value of 'hi-lock-highlight-range' was enlarged.
 The new default value is 2000000 (2 megabytes).
 
+** Whitespace mode
+
+*** A new style has been added: 'missing-newline-at-eof'
+If present in 'whitespace-style' (and it is now by default), the final
+character in the buffer will be highlighted unless it's a newline
+character.
+
 ** Texinfo
 
 ---
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 47434bf..fb5f28c 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)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]