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

[PATCH] git.el: Don't use font-lock-compile-keywords

From
Lawrence Mitchell <wence@gmx.li>
Date
Feb 4, 2011, 10:59 UTC
Message-ID
<m3oc501rja.fsf@e4300lm.epcc.ed.ac.uk>

If font-lock is disabled, font-lock-compile-keywords complains. Really what we want to do is to replace log-edit's font-lock definitions with our own, so define a major mode deriving from log-edit and set up font-lock-defaults there. We then use the optional MODE argument to log-edit to set up the major mode of the commit buffer appropriately.

Signed-Off-By: Lawrence Mitchell <wence@gmx.li>
---
I sent this before, in response to Johnathan's message of 4th Feb
(http://thread.gmane.org/gmane.comp.version-control.git/36088/focus=166038),
but it's possible it got lost in the noise.  So here it is
again.  The originally proposed patch from Debian is to use
font-lock-add-keywords rather than font-lock-compile-keywords.
However, it doesn't exist in XEmacs, if one is looking to
maintain compatibility, I believe this patch is the right thing
to do.
 contrib/emacs/git.el |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 214930a..65c95d9 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1310,6 +1310,13 @@ The FILES list must be sorted."
       (when sign-off (git-append-sign-off committer-name committer-email)))
     buffer))
 
+(define-derived-mode git-log-edit-mode log-edit-mode "Git-Log-Edit"
+  "Major mode for editing git log messages.
+
+Set up git-specific `font-lock-keywords' for `log-edit-mode'."
+  (set (make-local-variable 'font-lock-defaults)
+       '(git-log-edit-font-lock-keywords t t)))
+
 (defun git-commit-file ()
   "Commit the marked file(s), asking for a commit message."
   (interactive)
@@ -1335,9 +1342,9 @@ The FILES list must be sorted."
         (git-setup-log-buffer buffer (git-get-merge-heads) author-name author-email subject date))
       (if (boundp 'log-edit-diff-function)
 	  (log-edit 'git-do-commit nil '((log-edit-listfun . git-log-edit-files)
-					 (log-edit-diff-function . git-log-edit-diff)) buffer)
-	(log-edit 'git-do-commit nil 'git-log-edit-files buffer))
-      (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
+					 (log-edit-diff-function . git-log-edit-diff)) buffer 'git-log-edit-mode)
+	(log-edit 'git-do-commit nil 'git-log-edit-files buffer
+                  'git-log-edit-mode))
       (setq paragraph-separate (concat (regexp-quote git-log-msg-separator) "$\\|Author: \\|Date: \\|Merge: \\|Signed-off-by: \\|\f\\|[ 	]*$"))
       (setq buffer-file-coding-system coding-system)
       (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t))))
-- 
1.7.4.rc2.18.gb20e9
Next: Jonathan Nieder
Message 1 of 6 in “git.el: Don't use font-lock-compile-keywords”
  1. git.el: Don't use font-lock-compile-keywordsLawrence Mitchell, Feb 4, 2011
  2. Jonathan NiederApr 3, 2011
  3. Alexandre JulliardApr 3, 2011
  4. Jonathan NiederApr 3, 2011
  5. Junio C HamanoApr 3, 2011
  6. Kevin RydeApr 4, 2011

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.