Subject: [PATCH] Highlight fill-column-indicator when current line is longer than `fill-column'

From: Elijah Gabe Pérez <[email-masked]>
Date: Sat, 22 Feb 2025 22:21:02 -0600

Tags: patch

This patch allow warn to user if current line exceeds
display-fill-column-indicator-column.

When current line exceeds display-fill-column-indicator-column ...
                                           |
(print "......................................")
                                           |
... fill-column indicator face will change ^
temporarily to a noticeable face to warn the user that the current
column is getting too long.

I also wanted to do the same for indicator character but I couldn't find
a way to implement it.

(I hope this feature has been understood)

>From 4f608bb7dbb23b812284fada179a38485e660a9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= <[email-masked]>
Date: Sat, 22 Feb 2025 12:19:07 -0600
Subject: [PATCH] Highlight fill-column-indicator when current line is longer
 than ...

... `fill-column'

* lisp/display-fill-column-indicator.el
(display-fill-column-indicator-warning): New use-option.
(display-fill-column-indicator-warning-face): New face.
(display-fill-column-indicator-mode):
Add `display-fill-column-indicator-warning'.
---
 lisp/display-fill-column-indicator.el | 29 ++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/lisp/display-fill-column-indicator.el b/lisp/display-fill-column-indicator.el
index c55a03533bd..ca4b51fab2a 100644
--- a/lisp/display-fill-column-indicator.el
+++ b/lisp/display-fill-column-indicator.el
@@ -42,6 +42,15 @@ display-fill-column-indicator
   :group 'display
   :link '(info-link "(emacs)Displaying Boundaries"))
 
+(defcustom display-fill-column-indicator-warning nil
+  "Highlight fill-column-indicator when cursor is above `fill-column'.
+Non-nil means highlight fill-column-indicator when cursor is
+above `fill-column'."
+  :type 'boolean)
+
+(defface display-fill-column-indicator-warning-face
+  '((t :inherit error :stipple nil))
+  "Face used to highlight fill-column-indicator when the line is too long.")
 
 ;;;###autoload
 (define-minor-mode display-fill-column-indicator-mode
@@ -68,7 +77,25 @@ display-fill-column-indicator-mode
                              (eq (aref (query-font (car (internal-char-font nil ?\u2502))) 0)
                                  (face-font 'default))))
                     ?\u2502
-                  ?|))))
+                  ?|)))
+
+        (if display-fill-column-indicator-warning
+            (add-hook
+             'post-command-hook
+             (lambda ()
+               (if-let* ((column (if (numberp display-fill-column-indicator-column)
+                                     display-fill-column-indicator-column
+                                   fill-column))
+                         ((> (save-excursion (end-of-line) (current-column))
+                             column)))
+                   (progn
+                     (face-remap-set-base
+                      'fill-column-indicator
+                      'display-fill-column-indicator-warning-face))
+                 (face-remap-reset-base 'fill-column-indicator)))
+             nil t)
+          )
+        )
     (setq display-fill-column-indicator nil)))
 
 (defun display-fill-column-indicator--turn-on ()
-- 
2.48.1

-- 
                                                   - E.G via GNU Emacs.