{"thread":{"id":"65112","subject":"[PATCH] git-gui: highlight comment lines in commit message","startedAt":"2026-03-01T21:57:37Z","lastAt":"2026-03-04T07:24:43Z","messageCount":4,"participants":["Wolfgang Faust","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"537483","messageId":"a72715e2-c3ae-4050-95e3-7fc7f9b74b5d@app.fastmail.com","threadId":"65112","inReplyTo":null,"subject":"[PATCH] git-gui: highlight comment lines in commit message","fromName":"Wolfgang Faust","fromEmail":"contrib-git@wolfgangfaust.com","sentAt":"2026-03-01T21:55:58Z","receivedAt":"2026-03-01T21:57:37Z","isPatch":true,"sender":{"key":"contrib-git@wolfgangfaust.com","avatar":null},"body":"These lines are stripped by wash_commit_message, but there is no indication\nin the UI that they are special and will be removed.\nAdd highlighting to make it clear these lines are special.\nSigned-off-by: Wolfgang Faust <contrib-git@wolfgangfaust.com>\n\n(I'm not very good with tcl, so I suspect this code could use some work.\nIn particular the regex being a mangled copy of the one in the wash\nprocedure seems like a code smell, though I'm not sure how to improve\nit.)  \n---\n git-gui/git-gui.sh | 19 +++++++++++++++++++\n 1 file changed, 19 insertions(+)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex d3d3aa14a9..3a0c08aa38 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -3900,6 +3900,25 @@ if {[winfo exists $ui_comm]} {\n\n     backup_commit_buffer\n\n+    # Grey out comment lines (which are stripped from the final\ncommit message by\n+    # wash_commit_message).\n+    $ui_comm tag configure commit_comment -foreground gray\n+    proc highlight_commit_comment_lines {} {\n+        global ui_comm comment_string\n+        $ui_comm tag remove commit_comment 0.0 end\n+        set text [$ui_comm get 1.0 end]\n+        # See also cmt_rx in wash_commit_message\n+        set cmt_rx [strcat {(?:^|\\n)(} [regsub -all {\\W}\n$comment_string {\\\\&}] {[^\\n]*)}]\n+        set ranges [regexp -all -indices -inline -- $cmt_rx $text]\n+        for {set i 1} {$i < [llength $ranges]} {incr i 2} {\n+            $ui_comm tag add commit_comment \\\n+                [$ui_comm index \"1.0 + [lindex [lindex $ranges $i] 0] chars\"] \\\n+                [$ui_comm index \"1.0 + [lindex [lindex $ranges $i] 0]\nchars lineend + 1 char\"]\n+        }\n+    }\n+    highlight_commit_comment_lines\n+    bind $ui_comm <<Modified>> { after idle highlight_commit_comment_lines }\n+\n     # -- If the user has aspell available we can drive it\n     #    in pipe mode to spellcheck the commit message.\n     #\n\nbase-commit: 7b2bccb0d58d4f24705bf985de1f4612e4cf06e5\n-- \n2.52.0\n"},{"id":"537502","messageId":"08da87b1-32c6-43c2-be1f-d60bc93ea135@kdbg.org","threadId":"65112","inReplyTo":"a72715e2-c3ae-4050-95e3-7fc7f9b74b5d@app.fastmail.com","subject":"Re: [PATCH] git-gui: highlight comment lines in commit message","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-03-02T11:30:51Z","receivedAt":"2026-03-02T11:31:01Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 01.03.26 um 22:55 schrieb Wolfgang Faust:\n> These lines are stripped by wash_commit_message, but there is no indication\n> in the UI that they are special and will be removed.\n> Add highlighting to make it clear these lines are special.\n> Signed-off-by: Wolfgang Faust <contrib-git@wolfgangfaust.com>\n\nI like this idea! But please don't call it highlight, because we\nactually want to do the opposite, dim or grey out the text.\n\nPlease leave a blank line above the sign-off trailer.\n\n> (I'm not very good with tcl, so I suspect this code could use some work.\n> In particular the regex being a mangled copy of the one in the wash\n> procedure seems like a code smell, though I'm not sure how to improve\n> it.)  \n\nThis text should go after the three-dashes, then it will be excluded\nfrom the commit message.\n\n> ---\n>  git-gui/git-gui.sh | 19 +++++++++++++++++++\n>  1 file changed, 19 insertions(+)\n> \n> diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\n> index d3d3aa14a9..3a0c08aa38 100755\n> --- a/git-gui/git-gui.sh\n> +++ b/git-gui/git-gui.sh\n> @@ -3900,6 +3900,25 @@ if {[winfo exists $ui_comm]} {\n> \n>      backup_commit_buffer\n> \n> +    # Grey out comment lines (which are stripped from the final\n> commit message by\n\nIt looks like you pasted this text into your webmail client, which\ndestroyed the formatting of the patch. (I was able to fix this up,\nbut...) If you have a Github account, you could use Gitgitgadget\nhttps://gitgitgadget.github.io/ for your submissions.\n\n> +    # wash_commit_message).\n> +    $ui_comm tag configure commit_comment -foreground gray\n> +    proc highlight_commit_comment_lines {} {\n> +        global ui_comm comment_string\n> +        $ui_comm tag remove commit_comment 0.0 end\n> +        set text [$ui_comm get 1.0 end]\n> +        # See also cmt_rx in wash_commit_message\n> +        set cmt_rx [strcat {(?:^|\\n)(} [regsub -all {\\W}\n> $comment_string {\\\\&}] {[^\\n]*)}]\n> +        set ranges [regexp -all -indices -inline -- $cmt_rx $text]\n\nThe regular expression can be simplified if we use -line matching. Then\nthe initial (?:^|\\n) can become just ^ (no parentheses), and since we do\nnot look at the end index, the trailing [^\\n]* isn't needed, either.\nNext, if we drop the capturing parentheses, only one pair of indexes is\nreported per match...\n\n> +        for {set i 1} {$i < [llength $ranges]} {incr i 2} {\n\n... and we can turn this into a simple foreach loop...\n\n> +            $ui_comm tag add commit_comment \\\n> +                [$ui_comm index \"1.0 + [lindex [lindex $ranges $i] 0] chars\"] \\\n\n... with just one level of indexing here. Also, we could stash away the\nindex computed here...\n\n> +                [$ui_comm index \"1.0 + [lindex [lindex $ranges $i] 0]\n> chars lineend + 1 char\"]\n\n... and reuse it here with just the \"lineend + 1char\" modifier. (I\nwonder why we need the +1char, though.)\n\n> +        }\n> +    }\n> +    highlight_commit_comment_lines\n> +    bind $ui_comm <<Modified>> { after idle highlight_commit_comment_lines }\n> +\n>      # -- If the user has aspell available we can drive it\n>      #    in pipe mode to spellcheck the commit message.\n>      #\n> \n> base-commit: 7b2bccb0d58d4f24705bf985de1f4612e4cf06e5\n\n-- Hannes\n\n"},{"id":"537743","messageId":"c2416342-dbb8-4003-b959-cb0ed2b00eeb@app.fastmail.com","threadId":"65112","inReplyTo":"08da87b1-32c6-43c2-be1f-d60bc93ea135@kdbg.org","subject":"Re: [PATCH] git-gui: highlight comment lines in commit message","fromName":"Wolfgang Faust","fromEmail":"contrib-git@wolfgangfaust.com","sentAt":"2026-03-04T01:30:52Z","receivedAt":"2026-03-04T01:30:53Z","isPatch":true,"sender":{"key":"contrib-git@wolfgangfaust.com","avatar":null},"body":"These lines are stripped by wash_commit_message, but there is no indication\nin the UI that they are special and will be removed.\nAdd highlighting to make it clear these lines are special.\n\nSigned-off-by: Wolfgang Faust <contrib-git@wolfgangfaust.com>\n---\nUpdated per your comments, plus a couple of other minor tweaks.\nThank you for bearing with me as I figure out how to properly\nsend patches :-)\n\n> please don't call it highlight, because we\n> actually want to do the opposite, dim or grey out the text.\n\nThank you, \"dim\" is a better term.\n\n> The regular expression can be simplified if we use -line matching.\n> ... and we can turn this into a simple foreach loop...\n\nDone, that looks much cleaner!\n\n> (I wonder why we need the +1char, though.)\n\nWithout it, putting the cursor at the end of a comment line and typing\ncauses the newly inserted text to flash black briefly. Adding +1 puts\nthe tag on the other side of the cursor, so the newly added text is dim.\n(The tradeoff is that putting the cursor at the end of the comment,\npressing enter, and typing causes the newly inserted text to be grey\nbriefly. I think this looks somewhat less bad than the other way around.)\n\n git-gui/git-gui.sh | 18 ++++++++++++++++++\n 1 file changed, 18 insertions(+)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex d3d3aa14a9..23fe76e498 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -3900,6 +3900,24 @@ if {[winfo exists $ui_comm]} {\n \n \tbackup_commit_buffer\n \n+\t# Grey out comment lines (which are stripped from the final commit message by\n+\t# wash_commit_message).\n+\t$ui_comm tag configure commit_comment -foreground gray\n+\tproc dim_commit_comment_lines {} {\n+\t\tglobal ui_comm comment_string\n+\t\t$ui_comm tag remove commit_comment 1.0 end\n+\t\tset text [$ui_comm get 1.0 end]\n+\t\t# See also cmt_rx in wash_commit_message\n+\t\tset cmt_rx [strcat {^} [regsub -all {\\W} $comment_string {\\\\&}]]\n+\t\tset ranges [regexp -all -indices -inline -line -- $cmt_rx $text]\n+\t\tforeach pair $ranges {\n+\t\t\tset idx \"1.0 + [lindex $pair 0] chars\"\n+\t\t\t$ui_comm tag add commit_comment $idx \"$idx lineend + 1 char\"\n+\t\t}\n+\t}\n+\tdim_commit_comment_lines\n+\tbind $ui_comm <<Modified>> { after idle dim_commit_comment_lines }\n+\n \t# -- If the user has aspell available we can drive it\n \t#    in pipe mode to spellcheck the commit message.\n \t#\n\nbase-commit: 7b2bccb0d58d4f24705bf985de1f4612e4cf06e5\n-- \n2.52.0\n"},{"id":"537753","messageId":"fd298e8c-462d-4309-a20c-ea3dcd00d09d@kdbg.org","threadId":"65112","inReplyTo":"c2416342-dbb8-4003-b959-cb0ed2b00eeb@app.fastmail.com","subject":"Re: [PATCH] git-gui: highlight comment lines in commit message","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-03-04T07:24:27Z","receivedAt":"2026-03-04T07:24:43Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 04.03.26 um 02:30 schrieb Wolfgang Faust:\n> Thank you, \"dim\" is a better term.\n\nYou forgot to update the commit message. I took the liberty to rewrite\nit like so:\n\n    git-gui: grey out comment lines in commit message\n\n    Comment lines are stripped by wash_commit_message, but there is no\n    indication in the UI that they are special and will be removed.\n    Grey these lines out to indicate that they will be removed.\n\n    Signed-off-by: Wolfgang Faust <contrib-git@wolfgangfaust.com>\n    Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n\n>> (I wonder why we need the +1char, though.)\n> \n> Without it, putting the cursor at the end of a comment line and typing\n> causes the newly inserted text to flash black briefly. Adding +1 puts\n> the tag on the other side of the cursor, so the newly added text is dim.\n> (The tradeoff is that putting the cursor at the end of the comment,\n> pressing enter, and typing causes the newly inserted text to be grey\n> briefly. I think this looks somewhat less bad than the other way around.)\n\nFair enough.\n\n> +\t# Grey out comment lines (which are stripped from the final commit message by\n> +\t# wash_commit_message).\n> +\t$ui_comm tag configure commit_comment -foreground gray\n> +\tproc dim_commit_comment_lines {} {\n> +\t\tglobal ui_comm comment_string\n> +\t\t$ui_comm tag remove commit_comment 1.0 end\n> +\t\tset text [$ui_comm get 1.0 end]\n> +\t\t# See also cmt_rx in wash_commit_message\n> +\t\tset cmt_rx [strcat {^} [regsub -all {\\W} $comment_string {\\\\&}]]\n> +\t\tset ranges [regexp -all -indices -inline -line -- $cmt_rx $text]\n> +\t\tforeach pair $ranges {\n> +\t\t\tset idx \"1.0 + [lindex $pair 0] chars\"\n> +\t\t\t$ui_comm tag add commit_comment $idx \"$idx lineend + 1 char\"\n> +\t\t}\n> +\t}\n> +\tdim_commit_comment_lines\n> +\tbind $ui_comm <<Modified>> { after idle dim_commit_comment_lines }\nNicely done! Queued.\n\nThanks,\n-- Hannes\n\n"}]}