aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Whitton2022-09-04 16:20:15 -0700
committerSean Whitton2022-09-05 11:12:23 -0700
commit21c725dfe0c8fc3d4df32edb4995346df1ea9b97 (patch)
tree46df487a95bdce737da851f793360df8688279f9
parent3f1efe33d68b4a09246e0d2d6e5fb0e3def26060 (diff)
downloademacs-21c725dfe0c8fc3d4df32edb4995346df1ea9b97.tar.gz
emacs-21c725dfe0c8fc3d4df32edb4995346df1ea9b97.zip
Font lock long Git commit summary lines
* lisp/vc/vc-git.el (vc-git-log-edit-summary-target-len) (vc-git-log-edit-summary-max-len): New defcustoms. (vc-git-log-edit-summary-target-warning) (vc-git-log-edit-summary-max-warning): 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. * etc/NEWS (VC): Document the change. * .dir-locals.el: Set vc-git-log-edit-summary-target-len.
-rw-r--r--.dir-locals.el3
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/vc/vc-git.el64
3 files changed, 71 insertions, 2 deletions
diff --git a/.dir-locals.el b/.dir-locals.el
index 7812beb001c..1c90ddcf567 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -17,7 +17,8 @@
17 (electric-quote-string . nil) 17 (electric-quote-string . nil)
18 (mode . bug-reference-prog))) 18 (mode . bug-reference-prog)))
19 (log-edit-mode . ((log-edit-font-lock-gnu-style . t) 19 (log-edit-mode . ((log-edit-font-lock-gnu-style . t)
20 (log-edit-setup-add-author . t))) 20 (log-edit-setup-add-author . t)
21 (vc-git-log-edit-summary-target-len . 50)))
21 (change-log-mode . ((add-log-time-zone-rule . t) 22 (change-log-mode . ((add-log-time-zone-rule . t)
22 (fill-column . 74) 23 (fill-column . 74)
23 (mode . bug-reference))) 24 (mode . bug-reference)))
diff --git a/etc/NEWS b/etc/NEWS
index 476cd7ba6c1..1ee5958bcee 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1644,6 +1644,12 @@ directory in "~/foo/bar", using 'C-x v v' on a new, unregistered file
1644in the Git repository in "~/foo/bar". This makes this command 1644in the Git repository in "~/foo/bar". This makes this command
1645consistent with 'vc-responsible-backend'. 1645consistent with 'vc-responsible-backend'.
1646 1646
1647---
1648*** Log Edit now font locks long Git commit summary lines.
1649Writing shorter summary lines avoids truncation in contexts in which
1650Git commands display summary lines. See the two new variables
1651'vc-git-log-edit-summary-target-len' and 'vc-git-log-edit-summary-max-len'.
1652
1647** Message 1653** Message
1648 1654
1649--- 1655---
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 7395253745e..573622b71e1 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -858,6 +858,45 @@ The car of the list is the current branch."
858 858
859;;; STATE-CHANGING FUNCTIONS 859;;; STATE-CHANGING FUNCTIONS
860 860
861(defcustom vc-git-log-edit-summary-target-len nil
862 "Target length for Git commit summary lines.
863If a number, characters in Summary: lines beyond this length are
864displayed in the `vc-git-log-edit-summary-target-warning' face.
865
866By setting this to an integer around 50, you can improve the
867compatibility of your commit messages with Git commands that
868print the summary line in width-constrained contexts. However,
869many commit summaries will need to exceed this length.
870
871See also `vc-git-log-edit-summary-max-len'."
872 :type '(choice (const :tag "No target" nil)
873 (natnum :tag "Target length"))
874 :safe (lambda (x) (or (not x) (natnump x))))
875
876(defface vc-git-log-edit-summary-target-warning
877 '((t :inherit warning))
878 "Face for Git commit summary lines beyond the target length.
879See `vc-git-log-edit-summary-target-len'.")
880
881(defcustom vc-git-log-edit-summary-max-len 68
882 "Maximum length for Git commit summary lines.
883If a number, characters in summary lines beyond this length are
884displayed in the `vc-git-log-edit-summary-max-warning' face.
885
886It is good practice to avoid writing summary lines longer than
887this because otherwise the summary line will be truncated in many
888contexts in which Git commands display summary lines.
889
890See also `vc-git-log-edit-summary-target-len'."
891 :type '(choice (const :tag "No target" nil)
892 (natnum :tag "Target length"))
893 :safe (lambda (x) (or (not x) (natnump x))))
894
895(defface vc-git-log-edit-summary-max-warning
896 '((t :inherit error))
897 "Face for Git commit summary lines beyond the maximum length.
898See `vc-git-log-edit-summary-max-len'.")
899
861(defun vc-git-create-repo () 900(defun vc-git-create-repo ()
862 "Create a new Git repository." 901 "Create a new Git repository."
863 (vc-git-command nil 0 nil "init")) 902 (vc-git-command nil 0 nil "init"))
@@ -911,9 +950,32 @@ If toggling on, also insert its message into the buffer."
911 "C-c C-n" #'vc-git-log-edit-toggle-no-verify 950 "C-c C-n" #'vc-git-log-edit-toggle-no-verify
912 "C-c C-e" #'vc-git-log-edit-toggle-amend) 951 "C-c C-e" #'vc-git-log-edit-toggle-amend)
913 952
953(defun vc-git--log-edit-summary-check (limit)
954 (and (re-search-forward "^Summary: " limit t)
955 (when-let ((regex
956 (cond ((and (natnump vc-git-log-edit-summary-max-len)
957 (natnump vc-git-log-edit-summary-target-len))
958 (format ".\\{,%d\\}\\(.\\{,%d\\}\\)\\(.*\\)"
959 vc-git-log-edit-summary-target-len
960 (- vc-git-log-edit-summary-max-len
961 vc-git-log-edit-summary-target-len)))
962 ((natnump vc-git-log-edit-summary-max-len)
963 (format ".\\{,%d\\}\\(?2:.*\\)"
964 vc-git-log-edit-summary-max-len))
965 ((natnump vc-git-log-edit-summary-target-len)
966 (format ".\\{,%d\\}\\(.*\\)"
967 vc-git-log-edit-summary-target-len)))))
968 (re-search-forward regex limit t))))
969
914(define-derived-mode vc-git-log-edit-mode log-edit-mode "Log-Edit/git" 970(define-derived-mode vc-git-log-edit-mode log-edit-mode "Log-Edit/git"
915 "Major mode for editing Git log messages. 971 "Major mode for editing Git log messages.
916It is based on `log-edit-mode', and has Git-specific extensions.") 972It is based on `log-edit-mode', and has Git-specific extensions."
973 (setq-local
974 log-edit-font-lock-keywords
975 (append log-edit-font-lock-keywords
976 '((vc-git--log-edit-summary-check
977 (1 'vc-git-log-edit-summary-target-warning prepend t)
978 (2 'vc-git-log-edit-summary-max-warning prepend t))))))
917 979
918(defvar vc-git-patch-string nil) 980(defvar vc-git-patch-string nil)
919 981