>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