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

From: Elijah Gabe Pérez <[email-masked]>
Date: Sun, 23 Feb 2025 01:11:43 -0600

Eli Zaretskii <[email-masked]> writes:

> I see your change adds a post-command-hook, but when and how is that
> hook removed?

The hook is removed when display-fill-column-indicator-mode is turn-off,
i forgot to remove the hook in the submitted patch, I've fixed it.

>> I also wanted to do the same for indicator character but I couldn't find
>> a way to implement it.
>
> What do you mean by "indicator character"?

i meant `display-fill-column-indicator-character', I wanted to
allow changing its character to a custom one.

example: use this `┃' character (or one chosen by the user)
instead default `│' when changing the fill-column-indicator face.

>> +(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)
>
> This lacks a :version tag.
>
> Also, what do you mean by "cursor is above `fill-column'"?  The
> "above" part confuses me.

I updated the patch to clarify this part.

>From bfba03d2fc242bf6ca1d6f2b3a964b27d72a8eda 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

* 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 | 30 ++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/lisp/display-fill-column-indicator.el b/lisp/display-fill-column-indicator.el
index c55a03533bd..e2395bb1f01 100644
--- a/lisp/display-fill-column-indicator.el
+++ b/lisp/display-fill-column-indicator.el
@@ -42,6 +42,30 @@ display-fill-column-indicator
   :group 'display
   :link '(info-link "(emacs)Displaying Boundaries"))
 
+(defcustom display-fill-column-indicator-warning nil
+  "Highlight fill-column-indicator when current column is too long.
+Non-nil means highlight fill-column-indicator when current column exceeds
+`display-fill-column-indicator-column'."
+  :type 'boolean
+  :version "31.1")
+
+(defface display-fill-column-indicator-warning-face
+  '((t :inherit error :stipple nil))
+  "Face used to highlight `display-fill-column-indicator' when column is too long."
+  :version "31.1")
+
+(defun fill-indicator--set-warning ()
+  "Set the warning face for the fill column indicator."
+  (if-let* ((column (if (integerp 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)))
 
 ;;;###autoload
 (define-minor-mode display-fill-column-indicator-mode
@@ -68,7 +92,11 @@ 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 #'fill-indicator--set-warning nil t)))
+    (if display-fill-column-indicator-warning
+        (remove-hook 'post-command-hook #'fill-indicator--set-warning t))
     (setq display-fill-column-indicator nil)))
 
 (defun display-fill-column-indicator--turn-on ()
-- 
2.48.1

-- 
                                                   - E.G via GNU Emacs.