From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton Newsgroups: gmane.emacs.devel Subject: [PATCH v2] Font lock long Git commit summary lines Date: Sun, 04 Sep 2022 16:22:29 -0700 Message-ID: <871qsq2096.fsf@melete.silentflame.com> References: <20220903170308.301805-1-spwhitton@spwhitton.name> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7868"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 05 01:23:26 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oUyxY-0001rl-CV for ged-emacs-devel@m.gmane-mx.org; Mon, 05 Sep 2022 01:23:25 +0200 Original-Received: from localhost ([::1]:42678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUyxX-0003Rg-GL for ged-emacs-devel@m.gmane-mx.org; Sun, 04 Sep 2022 19:23:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUywl-0002lK-EQ for emacs-devel@gnu.org; Sun, 04 Sep 2022 19:22:35 -0400 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:36865) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUywj-00038D-1e for emacs-devel@gnu.org; Sun, 04 Sep 2022 19:22:35 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 44EB232002F9 for ; Sun, 4 Sep 2022 19:22:31 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 04 Sep 2022 19:22:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=spwhitton.name; h=cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1662333750; x=1662420150; bh=uOLvCrIEIb cUj+PIH40Hvouaq0fuqP+Wh2ZOjnFnJKA=; b=OT14MYMEFZBUHebSFVgVliHqyc aWDayHAugHlKiWAB4HW+She7QxiBb/KgUO1BBFIDFYECKLeO+Dh5DiuvH9NxRGl2 ey5+GNIx625S6OE59wy0zTgaDV6BYokuehf5BcaajnCKqA0PgP+s9M43ar3OM30m eqogpbwSs8x4D+NqRdE8I9ltV1Y+rpaRrJESTg6CNUIbeQ1BCCR/8apus/1xD9xa uQCBMZCQiAQdK6Kwc3QfZUUowE53JFRlMlqQivIfPIL9n34Gua1xNI+jYkomYJm0 Noq2LjBJcbBKj70MxwFimFPAI9rWZuoX+vRb6QPL0P4GDL7P6OZJvGoD+s/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1662333750; x=1662420150; bh=uOLvCrIEIbcUj+PIH40Hvouaq0fu qP+Wh2ZOjnFnJKA=; b=JZ3527oNCO7S5pGmw2ZxYYRbRWbXsepXOuGm5EarpNJR OQ0YpNz6HcrwyI649okyatbFVNpETHK/YBV0gS6Ge91SuMZ/ZB4LeFc1gSo3ywNH PoItSZal/FXeLTf4oew4aVNol7wIFskHOX9V0jVLP0l8Oh2lAmpUpfSbAq0p7jJB gpq6JdtaPlT56sZfWuLoHa0qATMbw0k5dsgWfbBxxK7RfifdkgfKPNR2KmL4eZvk Ouad+r3IxJf4FlGJeI9FZGOKKkRkZyiEfBnuvn9lgSo+4/UZaMu9zvVo5TynINEK +V/VzC1aQJcy+eFROZYcNbSZPlsZxN3Yww/fGT7yWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdelhedgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffujghffffkfgggtgesmhdttd ertdertdenucfhrhhomhepufgvrghnucghhhhithhtohhnuceoshhpfihhihhtthhonhes shhpfihhihhtthhonhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpeekveelffehteelhe etleduteejheefhefgteetfedttdejjeejvdevvefggefhheenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehsphifhhhithhtohhnsehsphifhh hithhtohhnrdhnrghmvg X-ME-Proxy: Feedback-ID: i23c04076:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 4 Sep 2022 19:22:30 -0400 (EDT) Original-Received: by melete.silentflame.com (Postfix, from userid 1000) id 9E61A7E9D3C; Sun, 4 Sep 2022 16:22:29 -0700 (MST) In-Reply-To: <20220903170308.301805-1-spwhitton@spwhitton.name> (Sean Whitton's message of "Sat, 3 Sep 2022 10:03:08 -0700") Received-SPF: pass client-ip=64.147.123.20; envelope-from=spwhitton@spwhitton.name; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:294714 Archived-At: --=-=-= Content-Type: text/plain Here is v2 of my patch. Thank you for the comments. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Font-lock-long-Git-commit-summary-lines.patch >From 142261030f7759428701afa6bc4e1e5ac72dc7b4 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 4 Sep 2022 16:20:15 -0700 Subject: [PATCH] Font lock long Git commit summary lines * lisp/vc/vc-git.el (vc-git-log-edit-summary-target) (vc-git-log-edit-summary-max): New defcustoms. (vc-git-log-edit-summary-warning, vc-git-log-edit-summary-error): New faces. (vc-git--log-edit-summary-check): New function. (vc-git-log-edit-mode): Add vc-git--log-edit-summary-check to log-edit-font-lock-keywords to font lock long Git commit summary lines. * .dir-locals.el: Set vc-git-log-edit-summary-target. --- .dir-locals.el | 3 ++- lisp/vc/vc-git.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/.dir-locals.el b/.dir-locals.el index 7812beb001..666d8019cc 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -5,7 +5,8 @@ (sentence-end-double-space . t) (fill-column . 70) (emacs-lisp-docstring-fill-column . 65) - (bug-reference-url-format . "https://debbugs.gnu.org/%s"))) + (bug-reference-url-format . "https://debbugs.gnu.org/%s") + (vc-git-log-edit-summary-target . 50))) (c-mode . ((c-file-style . "GNU") (c-noise-macro-names . ("INLINE" "ATTRIBUTE_NO_SANITIZE_UNDEFINED" "UNINIT" "CALLBACK" "ALIGN_STACK")) (electric-quote-comment . nil) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 7395253745..e7c04393de 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -858,6 +858,43 @@ vc-git-branches ;;; STATE-CHANGING FUNCTIONS +(defcustom vc-git-log-edit-summary-target nil + "Target length for Git commit summary lines. +If non-nil, characters in Summary: lines beyond this length are +displayed in the `vc-git-log-edit-summary-warning' face. + +By setting this to an integer around 50, you can improve the +compatibility of your commit messages with Git commands that +print the summary line in width-constrained contexts. However, +many commit summaries will need to exceed this length. + +See also `vc-git-log-edit-summary-max'." + :type '(choice (const :tag "No target" nil) + (natnum :tag "Target length")) + :safe (lambda (x) (or (not x) (integerp x)))) + +(defface vc-git-log-edit-summary-warning + '((t :inherit warning)) + "Face for Git commit summary lines beyond the target length.") + +(defcustom vc-git-log-edit-summary-max 68 + "Maximum length for Git commit summary lines. +If non-nil, characters in summary lines beyond this length are +displayed in the `vc-git-log-edit-summary-error' face. + +It is good practice to avoid writing summary lines longer than +this because otherwise the summary line will be truncated in many +contexts in which Git commands display summary lines. + +See also `vc-git-log-edit-summary-target'." + :type '(choice (const :tag "No target" nil) + (natnum :tag "Target length")) + :safe (lambda (x) (or (not x) (integerp x)))) + +(defface vc-git-log-edit-summary-error + '((t :inherit error)) + "Face for Git commit summary lines beyond the maximum length.") + (defun vc-git-create-repo () "Create a new Git repository." (vc-git-command nil 0 nil "init")) @@ -911,9 +948,32 @@ vc-git-log-edit-mode-map "C-c C-n" #'vc-git-log-edit-toggle-no-verify "C-c C-e" #'vc-git-log-edit-toggle-amend) +(defun vc-git--log-edit-summary-check (limit) + (and (re-search-forward "^Summary: " limit t) + (when-let ((regex + (cond ((and vc-git-log-edit-summary-max + vc-git-log-edit-summary-target) + (format ".\\{,%d\\}\\(.\\{,%d\\}\\)\\(.*\\)" + vc-git-log-edit-summary-target + (- vc-git-log-edit-summary-max + vc-git-log-edit-summary-target))) + (vc-git-log-edit-summary-max + (format ".\\{,%d\\}\\(?2:.*\\)" + vc-git-log-edit-summary-max)) + (vc-git-log-edit-summary-target + (format ".\\{,%d\\}\\(.*\\)" + vc-git-log-edit-summary-target))))) + (re-search-forward regex limit t)))) + (define-derived-mode vc-git-log-edit-mode log-edit-mode "Log-Edit/git" "Major mode for editing Git log messages. -It is based on `log-edit-mode', and has Git-specific extensions.") +It is based on `log-edit-mode', and has Git-specific extensions." + (setq-local + log-edit-font-lock-keywords + (append log-edit-font-lock-keywords + '((vc-git--log-edit-summary-check + (1 'vc-git-log-edit-summary-warning prepend t) + (2 'vc-git-log-edit-summary-error prepend t)))))) (defvar vc-git-patch-string nil) -- 2.30.2 --=-=-=--