public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH] git-gui: highlight comment lines in commit message
@ 2026-03-01 21:55 Wolfgang Faust
  2026-03-02 11:30 ` Johannes Sixt
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Faust @ 2026-03-01 21:55 UTC (permalink / raw)
  To: git; +Cc: Johannes Sixt

These lines are stripped by wash_commit_message, but there is no indication
in the UI that they are special and will be removed.
Add highlighting to make it clear these lines are special.
Signed-off-by: Wolfgang Faust <contrib-git@wolfgangfaust•com>

(I'm not very good with tcl, so I suspect this code could use some work.
In particular the regex being a mangled copy of the one in the wash
procedure seems like a code smell, though I'm not sure how to improve
it.)  
---
 git-gui/git-gui.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index d3d3aa14a9..3a0c08aa38 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -3900,6 +3900,25 @@ if {[winfo exists $ui_comm]} {

     backup_commit_buffer

+    # Grey out comment lines (which are stripped from the final
commit message by
+    # wash_commit_message).
+    $ui_comm tag configure commit_comment -foreground gray
+    proc highlight_commit_comment_lines {} {
+        global ui_comm comment_string
+        $ui_comm tag remove commit_comment 0.0 end
+        set text [$ui_comm get 1.0 end]
+        # See also cmt_rx in wash_commit_message
+        set cmt_rx [strcat {(?:^|\n)(} [regsub -all {\W}
$comment_string {\\&}] {[^\n]*)}]
+        set ranges [regexp -all -indices -inline -- $cmt_rx $text]
+        for {set i 1} {$i < [llength $ranges]} {incr i 2} {
+            $ui_comm tag add commit_comment \
+                [$ui_comm index "1.0 + [lindex [lindex $ranges $i] 0] chars"] \
+                [$ui_comm index "1.0 + [lindex [lindex $ranges $i] 0]
chars lineend + 1 char"]
+        }
+    }
+    highlight_commit_comment_lines
+    bind $ui_comm <<Modified>> { after idle highlight_commit_comment_lines }
+
     # -- If the user has aspell available we can drive it
     #    in pipe mode to spellcheck the commit message.
     #

base-commit: 7b2bccb0d58d4f24705bf985de1f4612e4cf06e5
-- 
2.52.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-gui: highlight comment lines in commit message
  2026-03-01 21:55 [PATCH] git-gui: highlight comment lines in commit message Wolfgang Faust
@ 2026-03-02 11:30 ` Johannes Sixt
  2026-03-04  1:30   ` Wolfgang Faust
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2026-03-02 11:30 UTC (permalink / raw)
  To: Wolfgang Faust; +Cc: git

Am 01.03.26 um 22:55 schrieb Wolfgang Faust:
> These lines are stripped by wash_commit_message, but there is no indication
> in the UI that they are special and will be removed.
> Add highlighting to make it clear these lines are special.
> Signed-off-by: Wolfgang Faust <contrib-git@wolfgangfaust•com>

I like this idea! But please don't call it highlight, because we
actually want to do the opposite, dim or grey out the text.

Please leave a blank line above the sign-off trailer.

> (I'm not very good with tcl, so I suspect this code could use some work.
> In particular the regex being a mangled copy of the one in the wash
> procedure seems like a code smell, though I'm not sure how to improve
> it.)  

This text should go after the three-dashes, then it will be excluded
from the commit message.

> ---
>  git-gui/git-gui.sh | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
> index d3d3aa14a9..3a0c08aa38 100755
> --- a/git-gui/git-gui.sh
> +++ b/git-gui/git-gui.sh
> @@ -3900,6 +3900,25 @@ if {[winfo exists $ui_comm]} {
> 
>      backup_commit_buffer
> 
> +    # Grey out comment lines (which are stripped from the final
> commit message by

It looks like you pasted this text into your webmail client, which
destroyed the formatting of the patch. (I was able to fix this up,
but...) If you have a Github account, you could use Gitgitgadget
https://gitgitgadget.github.io/ for your submissions.

> +    # wash_commit_message).
> +    $ui_comm tag configure commit_comment -foreground gray
> +    proc highlight_commit_comment_lines {} {
> +        global ui_comm comment_string
> +        $ui_comm tag remove commit_comment 0.0 end
> +        set text [$ui_comm get 1.0 end]
> +        # See also cmt_rx in wash_commit_message
> +        set cmt_rx [strcat {(?:^|\n)(} [regsub -all {\W}
> $comment_string {\\&}] {[^\n]*)}]
> +        set ranges [regexp -all -indices -inline -- $cmt_rx $text]

The regular expression can be simplified if we use -line matching. Then
the initial (?:^|\n) can become just ^ (no parentheses), and since we do
not look at the end index, the trailing [^\n]* isn't needed, either.
Next, if we drop the capturing parentheses, only one pair of indexes is
reported per match...

> +        for {set i 1} {$i < [llength $ranges]} {incr i 2} {

... and we can turn this into a simple foreach loop...

> +            $ui_comm tag add commit_comment \
> +                [$ui_comm index "1.0 + [lindex [lindex $ranges $i] 0] chars"] \

... with just one level of indexing here. Also, we could stash away the
index computed here...

> +                [$ui_comm index "1.0 + [lindex [lindex $ranges $i] 0]
> chars lineend + 1 char"]

... and reuse it here with just the "lineend + 1char" modifier. (I
wonder why we need the +1char, though.)

> +        }
> +    }
> +    highlight_commit_comment_lines
> +    bind $ui_comm <<Modified>> { after idle highlight_commit_comment_lines }
> +
>      # -- If the user has aspell available we can drive it
>      #    in pipe mode to spellcheck the commit message.
>      #
> 
> base-commit: 7b2bccb0d58d4f24705bf985de1f4612e4cf06e5

-- Hannes


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-gui: highlight comment lines in commit message
  2026-03-02 11:30 ` Johannes Sixt
@ 2026-03-04  1:30   ` Wolfgang Faust
  2026-03-04  7:24     ` Johannes Sixt
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Faust @ 2026-03-04  1:30 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git

These lines are stripped by wash_commit_message, but there is no indication
in the UI that they are special and will be removed.
Add highlighting to make it clear these lines are special.

Signed-off-by: Wolfgang Faust <contrib-git@wolfgangfaust•com>
---
Updated per your comments, plus a couple of other minor tweaks.
Thank you for bearing with me as I figure out how to properly
send patches :-)

> please don't call it highlight, because we
> actually want to do the opposite, dim or grey out the text.

Thank you, "dim" is a better term.

> The regular expression can be simplified if we use -line matching.
> ... and we can turn this into a simple foreach loop...

Done, that looks much cleaner!

> (I wonder why we need the +1char, though.)

Without it, putting the cursor at the end of a comment line and typing
causes the newly inserted text to flash black briefly. Adding +1 puts
the tag on the other side of the cursor, so the newly added text is dim.
(The tradeoff is that putting the cursor at the end of the comment,
pressing enter, and typing causes the newly inserted text to be grey
briefly. I think this looks somewhat less bad than the other way around.)

 git-gui/git-gui.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index d3d3aa14a9..23fe76e498 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -3900,6 +3900,24 @@ if {[winfo exists $ui_comm]} {
 
 	backup_commit_buffer
 
+	# Grey out comment lines (which are stripped from the final commit message by
+	# wash_commit_message).
+	$ui_comm tag configure commit_comment -foreground gray
+	proc dim_commit_comment_lines {} {
+		global ui_comm comment_string
+		$ui_comm tag remove commit_comment 1.0 end
+		set text [$ui_comm get 1.0 end]
+		# See also cmt_rx in wash_commit_message
+		set cmt_rx [strcat {^} [regsub -all {\W} $comment_string {\\&}]]
+		set ranges [regexp -all -indices -inline -line -- $cmt_rx $text]
+		foreach pair $ranges {
+			set idx "1.0 + [lindex $pair 0] chars"
+			$ui_comm tag add commit_comment $idx "$idx lineend + 1 char"
+		}
+	}
+	dim_commit_comment_lines
+	bind $ui_comm <<Modified>> { after idle dim_commit_comment_lines }
+
 	# -- If the user has aspell available we can drive it
 	#    in pipe mode to spellcheck the commit message.
 	#

base-commit: 7b2bccb0d58d4f24705bf985de1f4612e4cf06e5
-- 
2.52.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-gui: highlight comment lines in commit message
  2026-03-04  1:30   ` Wolfgang Faust
@ 2026-03-04  7:24     ` Johannes Sixt
  0 siblings, 0 replies; 4+ messages in thread
From: Johannes Sixt @ 2026-03-04  7:24 UTC (permalink / raw)
  To: Wolfgang Faust; +Cc: git

Am 04.03.26 um 02:30 schrieb Wolfgang Faust:
> Thank you, "dim" is a better term.

You forgot to update the commit message. I took the liberty to rewrite
it like so:

    git-gui: grey out comment lines in commit message

    Comment lines are stripped by wash_commit_message, but there is no
    indication in the UI that they are special and will be removed.
    Grey these lines out to indicate that they will be removed.

    Signed-off-by: Wolfgang Faust <contrib-git@wolfgangfaust•com>
    Signed-off-by: Johannes Sixt <j6t@kdbg•org>

>> (I wonder why we need the +1char, though.)
> 
> Without it, putting the cursor at the end of a comment line and typing
> causes the newly inserted text to flash black briefly. Adding +1 puts
> the tag on the other side of the cursor, so the newly added text is dim.
> (The tradeoff is that putting the cursor at the end of the comment,
> pressing enter, and typing causes the newly inserted text to be grey
> briefly. I think this looks somewhat less bad than the other way around.)

Fair enough.

> +	# Grey out comment lines (which are stripped from the final commit message by
> +	# wash_commit_message).
> +	$ui_comm tag configure commit_comment -foreground gray
> +	proc dim_commit_comment_lines {} {
> +		global ui_comm comment_string
> +		$ui_comm tag remove commit_comment 1.0 end
> +		set text [$ui_comm get 1.0 end]
> +		# See also cmt_rx in wash_commit_message
> +		set cmt_rx [strcat {^} [regsub -all {\W} $comment_string {\\&}]]
> +		set ranges [regexp -all -indices -inline -line -- $cmt_rx $text]
> +		foreach pair $ranges {
> +			set idx "1.0 + [lindex $pair 0] chars"
> +			$ui_comm tag add commit_comment $idx "$idx lineend + 1 char"
> +		}
> +	}
> +	dim_commit_comment_lines
> +	bind $ui_comm <<Modified>> { after idle dim_commit_comment_lines }
Nicely done! Queued.

Thanks,
-- Hannes


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-04  7:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-01 21:55 [PATCH] git-gui: highlight comment lines in commit message Wolfgang Faust
2026-03-02 11:30 ` Johannes Sixt
2026-03-04  1:30   ` Wolfgang Faust
2026-03-04  7:24     ` Johannes Sixt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox