Subject: 29.0.50; [PATCH] whitespace.el: New whitespace style `lines-char'

From: [email-masked]
Date: Tue, 14 Jun 2022 21:08:54 +0200

Please see the attached patch which adds a new whitespace style to
highlight only the first character over the whitespace-line-column
limit.

Best regards.

From d1c341e46206e7ce1615105cf6a0e70aebbc72e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <[email-masked]>
Date: Tue, 14 Jun 2022 21:02:22 +0200
Subject: [PATCH] whitespace.el: New whitespace style `lines-char'

* lisp/whitespace.el (whitespace-style):
(whitespace-style-value-list):
(whitespace-toggle-option-alist):
(global-whitespace-toggle-options):
(whitespace-help-text):
(whitespace-interactive-char):
(whitespace-style-face-p):
(whitespace-color-on):
(whitespace-lines-regexp): New whitespace style `lines-char', which
highlights only the first character over the whitespace-line-column
limit.
---
 lisp/whitespace.el | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 610d670ac9..a974336ace 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -295,8 +295,8 @@ whitespace-style
                         `whitespace-line-column' are highlighted via
                         faces.
                         Whole line is highlighted.
-                        It has precedence over `lines-tail' (see
-                        below).
+                        It has precedence over `lines-tail' and
+                        `lines-char' (see below).
                         It has effect only if `face' (see above)
                         is present in `whitespace-style'.
 
@@ -310,6 +310,17 @@ whitespace-style
                         and if `face' (see above) is present in
                         `whitespace-style'.
 
+   lines-char           lines which have columns beyond
+                        `whitespace-line-column' are highlighted via
+                        faces.
+                        But only the first character which goes
+                        beyond `whitespace-line-column' column.
+                        It has effect only if `lines' or
+                        `lines-tail' (see above)
+                        is not present in `whitespace-style'
+                        and if `face' (see above) is present in
+                        `whitespace-style'.
+
    newline              NEWLINEs are visualized via faces.
                         It has effect only if `face' (see above)
                         is present in `whitespace-style'.
@@ -431,6 +442,7 @@ whitespace-style
               (const :tag "(Face) SPACEs and HARD SPACEs" spaces)
               (const :tag "(Face) Lines" lines)
               (const :tag "(Face) Lines, only overlong part" lines-tail)
+              (const :tag "(Face) Lines, only first character" lines-char)
               (const :tag "(Face) NEWLINEs" newline)
               (const :tag "(Face) Missing newlines at EOB"
                      missing-newline-at-eof)
@@ -772,7 +784,8 @@ whitespace-line-column
 It must be an integer or nil.  If nil, the `fill-column' variable value is
 used.
 
-Used when `whitespace-style' includes `lines' or `lines-tail'."
+Used when `whitespace-style' includes `lines', `lines-tail' or
+`lines-char'."
   :type '(choice :tag "Line Length Limit"
 		 (integer :tag "Line Length")
 		 (const :tag "Use fill-column" nil))
@@ -1058,6 +1071,7 @@ whitespace-style-value-list
     trailing
     lines
     lines-tail
+    lines-char
     newline
     empty
     indentation
@@ -1085,6 +1099,7 @@ whitespace-toggle-option-alist
     (?r    . trailing)
     (?l    . lines)
     (?L    . lines-tail)
+    (?\C-l . lines-char)
     (?n    . newline)
     (?e    . empty)
     (?\C-i . indentation)
@@ -1244,6 +1259,7 @@ global-whitespace-toggle-options
    r	toggle trailing blanks visualization
    l	toggle \"long lines\" visualization
    L	toggle \"long lines\" tail visualization
+   C-l	toggle \"long lines\" one character visualization
    n	toggle NEWLINE visualization
    e	toggle empty line at bob and/or eob visualization
    C-i	toggle indentation SPACEs visualization (via `indent-tabs-mode')
@@ -1274,6 +1290,7 @@ global-whitespace-toggle-options
    trailing		toggle trailing blanks visualization
    lines		toggle \"long lines\" visualization
    lines-tail		toggle \"long lines\" tail visualization
+   lines-char		toggle \"long lines\" one character visualization
    newline		toggle NEWLINE visualization
    empty		toggle empty line at bob and/or eob visualization
    indentation		toggle indentation SPACEs visualization
@@ -1770,6 +1787,7 @@ whitespace-help-text
  []  r   - toggle trailing blanks visualization
  []  l   - toggle \"long lines\" visualization
  []  L   - toggle \"long lines\" tail visualization
+ []  C-l - toggle \"long lines\" one character visualization
  []  n   - toggle NEWLINE visualization
  []  e   - toggle empty line at bob and/or eob visualization
  []  C-i - toggle indentation SPACEs visualization (via `indent-tabs-mode')
@@ -1892,6 +1910,7 @@ whitespace-interactive-char
    r	toggle trailing blanks visualization
    l	toggle \"long lines\" visualization
    L	toggle \"long lines\" tail visualization
+   C-l	toggle \"long lines\" one character visualization
    n	toggle NEWLINE visualization
    e	toggle empty line at bob and/or eob visualization
    C-i	toggle indentation SPACEs visualization (via `indent-tabs-mode')
@@ -2020,6 +2039,7 @@ whitespace-style-face-p
 	   (memq 'trailing                whitespace-active-style)
 	   (memq 'lines                   whitespace-active-style)
 	   (memq 'lines-tail              whitespace-active-style)
+	   (memq 'lines-char              whitespace-active-style)
 	   (memq 'newline                 whitespace-active-style)
 	   (memq 'empty                   whitespace-active-style)
 	   (memq 'indentation             whitespace-active-style)
@@ -2066,12 +2086,17 @@ whitespace-color-on
            ;; Show trailing blanks.
            `((,#'whitespace-trailing-regexp 1 whitespace-trailing t)))
        ,@(when (or (memq 'lines      whitespace-active-style)
-                   (memq 'lines-tail whitespace-active-style))
+                   (memq 'lines-tail whitespace-active-style)
+                   (memq 'lines-char whitespace-active-style))
            ;; Show "long" lines.
            `((,#'whitespace-lines-regexp
-              ,(if (memq 'lines whitespace-active-style)
-                   0                    ; whole line
-                 2)                     ; line tail
+              ,(cond
+                ;; whole line
+                ((memq 'lines whitespace-active-style) 0)
+                ;; line tail
+                ((memq 'lines-tail whitespace-active-style) 2)
+                ;; first overflowing character
+                ((memq 'lines-char whitespace-active-style) 3))
               whitespace-line prepend)))
        ,@(when (or (memq 'space-before-tab whitespace-active-style)
                    (memq 'space-before-tab::tab whitespace-active-style)
@@ -2182,7 +2207,7 @@ whitespace-lines-regexp
   (re-search-forward
    (let ((line-column (or whitespace-line-column fill-column)))
      (format
-      "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$"
+      "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(?2:\\(?3:.\\).*\\)$"
       tab-width
       (1- tab-width)
       (/ line-column tab-width)
-- 
2.36.0