git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-gui: highlight comment lines in commit message

From
WFWolfgang Faust <contrib-git@wolfgangfaust.com>
Date
Mar 4, 2026, 01:30 UTC
Message-ID
<c2416342-dbb8-4003-b959-cb0ed2b00eeb@app.fastmail.com>
In-Reply-To
<08da87b1-32c6-43c2-be1f-d60bc93ea135@kdbg.org>

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
Previous: Johannes SixtNext: Johannes Sixt
Message 3 of 4 in “git-gui: highlight comment lines in commit message”
  1. git-gui: highlight comment lines in commit messageWolfgang Faust, Mar 1, 2026
  2. Johannes SixtMar 2, 2026
  3. Wolfgang FaustMar 4, 2026
  4. Johannes SixtMar 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.