threads / patch / 6252

patchgit.el: Avoid setting font lock keywords before entering log-edit mode.

Subject: [PATCH] git.el: Avoid setting font lock keywords before entering log-edit mode.

## tl;dr

3 messages between Jan 6, 2007 and Feb 4, 2011. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Alexandre Julliard· Jan 6, 2007, 13:46 UTC · lore

Instead, reinitialize the keywords after the fact. This avoids conflicts with other users of log-edit mode, like pcl-cvs.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 contrib/emacs/git.el |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
Show changes to contrib/emacs/git.el +11 −8
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 38915e5..ede3ab2 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -49,6 +49,7 @@
 
 (eval-when-compile (require 'cl))
 (require 'ewoc)
+(require 'log-edit)
 
 
 ;;;; Customizations
@@ -147,6 +148,13 @@ if there is already one that displays the same directory."
 
 (defconst git-log-msg-separator "--- log message follows this line ---")
 
+(defvar git-log-edit-font-lock-keywords
+  `(("^\\(Author:\\|Date:\\|Parent:\\|Signed-off-by:\\)\\(.*\\)$"
+     (1 font-lock-keyword-face)
+     (2 font-lock-function-name-face))
+    (,(concat "^\\(" (regexp-quote git-log-msg-separator) "\\)$")
+     (1 font-lock-comment-face))))
+
 (defun git-get-env-strings (env)
   "Build a list of NAME=VALUE strings from a list of environment strings."
   (mapcar (lambda (entry) (concat (car entry) "=" (cdr entry))) env))
@@ -894,14 +902,9 @@ and returns the process output as a string."
               (sign-off
                (insert (format "\n\nSigned-off-by: %s <%s>\n"
                                (git-get-committer-name) (git-get-committer-email)))))))
-    (let ((log-edit-font-lock-keywords
-           `(("^\\(Author:\\|Date:\\|Parent:\\|Signed-off-by:\\)\\(.*\\)"
-              (1 font-lock-keyword-face)
-              (2 font-lock-function-name-face))
-             (,(concat "^\\(" (regexp-quote git-log-msg-separator) "\\)$")
-              (1 font-lock-comment-face)))))
-      (log-edit #'git-do-commit nil #'git-log-edit-files buffer)
-      (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t))))
+    (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))
+    (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t)))
 
 (defun git-find-file ()
   "Visit the current file in its own buffer."
-- 
1.5.0.rc0.g5a8e

-- 
Alexandre Julliard
julliard@winehq.org
Jonathan Nieder· Feb 4, 2011, 00:10 UTC · re: Alexandre Julliard · lore

[BUG?] git.el: M-x git-commit-file produces error if font lock is disabled

Hi,
Kevin Ryde reports[1]:
Show 14 quoted lines
> If font lock is disabled, M-x git-commit-file gets an error when setting
> up the log message edit buffer.
>
>     M-: (global-font-lock-mode 0)
>     M-x git-status
>     /some/git/directory
>     c         <- on a modified file
>
>     => Font-lock trying to use keywords before setting them up
>
> I suppose font-lock-compile-keywords should not be used if font lock is
> not enabled.  I suspect font-lock-add-keywords might be the right thing
> instead.  It seems to work for me (the code is supposed to replace the
> normal log-edit-mode keywords is it?).
and suggests a patch[2].  Does it make sense?

Ignorantly, Jonathan

[1] http://bugs.debian.org/577834 from a while ago. Sorry for the long delay. [2]

 contrib/emacs/git.el |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to contrib/emacs/git.el +1 −1
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 214930a..0c93ef1 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1337,7 +1337,7 @@ The FILES list must be sorted."
 	  (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))
+      (font-lock-add-keywords nil git-log-edit-font-lock-keywords 'set)
       (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
Lawrence Mitchell· Feb 4, 2011, 11:40 UTC · re: Jonathan Nieder · lore

Re: [BUG?] git.el: M-x git-commit-file produces error if font lock is disabled

Jonathan Nieder wrote:
> Hi,
> Kevin Ryde reports[1]:
[...] bug in git.el
> and suggests a patch[2].  Does it make sense?

font-lock-add-keywords isn't supported in the stable Xemacs version (21.4). But really, we don't want to /add/ keywords, but set up our own, so we should define a major mode appropriately and use that in log-edit. Something like the patch below, I think.

>From 6333cd09f1a921757680f1376eeb0a6389d75449 Mon Sep 17 00:00:00 2001
From: Lawrence Mitchell <wence@gmx.li>
Date: Fri, 4 Feb 2011 10:59:18 +0000
Subject: [PATCH] git.el: Don't use font-lock-compile-keywords

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 option MODE argument to log-edit to set up the major mode of the commit buffer appropriately.

Signed-Off-By: Lawrence Mitchell <wence@gmx.li>
---
 contrib/emacs/git.el |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
Show changes to contrib/emacs/git.el +10 −3
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

← back to recent threads