{"thread":{"id":"6252","subject":"[PATCH] git.el: Avoid setting font lock keywords before entering log-edit mode.","startedAt":"2007-01-06T13:46:47Z","lastAt":"2011-02-04T11:40:18Z","messageCount":3,"participants":["Alexandre Julliard","Jonathan Nieder","Lawrence Mitchell"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"30970","messageId":"87lkkgw9mg.fsf@wine.dyndns.org","threadId":"6252","inReplyTo":null,"subject":"[PATCH] git.el: Avoid setting font lock keywords before entering log-edit mode.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2007-01-06T13:46:47Z","receivedAt":"2007-01-06T13:46:47Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"Instead, reinitialize the keywords after the fact. This avoids\nconflicts with other users of log-edit mode, like pcl-cvs.\n\nSigned-off-by: Alexandre Julliard <julliard@winehq.org>\n---\n contrib/emacs/git.el |   19 +++++++++++--------\n 1 files changed, 11 insertions(+), 8 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex 38915e5..ede3ab2 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -49,6 +49,7 @@\n \n (eval-when-compile (require 'cl))\n (require 'ewoc)\n+(require 'log-edit)\n \n \n ;;;; Customizations\n@@ -147,6 +148,13 @@ if there is already one that displays the same directory.\"\n \n (defconst git-log-msg-separator \"--- log message follows this line ---\")\n \n+(defvar git-log-edit-font-lock-keywords\n+  `((\"^\\\\(Author:\\\\|Date:\\\\|Parent:\\\\|Signed-off-by:\\\\)\\\\(.*\\\\)$\"\n+     (1 font-lock-keyword-face)\n+     (2 font-lock-function-name-face))\n+    (,(concat \"^\\\\(\" (regexp-quote git-log-msg-separator) \"\\\\)$\")\n+     (1 font-lock-comment-face))))\n+\n (defun git-get-env-strings (env)\n   \"Build a list of NAME=VALUE strings from a list of environment strings.\"\n   (mapcar (lambda (entry) (concat (car entry) \"=\" (cdr entry))) env))\n@@ -894,14 +902,9 @@ and returns the process output as a string.\"\n               (sign-off\n                (insert (format \"\\n\\nSigned-off-by: %s <%s>\\n\"\n                                (git-get-committer-name) (git-get-committer-email)))))))\n-    (let ((log-edit-font-lock-keywords\n-           `((\"^\\\\(Author:\\\\|Date:\\\\|Parent:\\\\|Signed-off-by:\\\\)\\\\(.*\\\\)\"\n-              (1 font-lock-keyword-face)\n-              (2 font-lock-function-name-face))\n-             (,(concat \"^\\\\(\" (regexp-quote git-log-msg-separator) \"\\\\)$\")\n-              (1 font-lock-comment-face)))))\n-      (log-edit #'git-do-commit nil #'git-log-edit-files buffer)\n-      (re-search-forward (regexp-quote (concat git-log-msg-separator \"\\n\")) nil t))))\n+    (log-edit #'git-do-commit nil #'git-log-edit-files buffer)\n+    (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))\n+    (re-search-forward (regexp-quote (concat git-log-msg-separator \"\\n\")) nil t)))\n \n (defun git-find-file ()\n   \"Visit the current file in its own buffer.\"\n-- \n1.5.0.rc0.g5a8e\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"160366","messageId":"20110204001016.GC16688@elie","threadId":"6252","inReplyTo":"87lkkgw9mg.fsf@wine.dyndns.org","subject":"[BUG?] git.el: M-x git-commit-file produces error if font lock is disabled","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-04T00:10:16Z","receivedAt":"2011-02-04T00:10:16Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nKevin Ryde reports[1]:\n\n> If font lock is disabled, M-x git-commit-file gets an error when setting\n> up the log message edit buffer.\n>\n>     M-: (global-font-lock-mode 0)\n>     M-x git-status\n>     /some/git/directory\n>     c         <- on a modified file\n>\n>     => Font-lock trying to use keywords before setting them up\n>\n> I suppose font-lock-compile-keywords should not be used if font lock is\n> not enabled.  I suspect font-lock-add-keywords might be the right thing\n> instead.  It seems to work for me (the code is supposed to replace the\n> normal log-edit-mode keywords is it?).\n\nand suggests a patch[2].  Does it make sense?\n\nIgnorantly,\nJonathan\n\n[1] http://bugs.debian.org/577834 from a while ago.\nSorry for the long delay.\n[2]\n\n contrib/emacs/git.el |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex 214930a..0c93ef1 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -1337,7 +1337,7 @@ The FILES list must be sorted.\"\n \t  (log-edit 'git-do-commit nil '((log-edit-listfun . git-log-edit-files)\n \t\t\t\t\t (log-edit-diff-function . git-log-edit-diff)) buffer)\n \t(log-edit 'git-do-commit nil 'git-log-edit-files buffer))\n-      (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))\n+      (font-lock-add-keywords nil git-log-edit-font-lock-keywords 'set)\n       (setq paragraph-separate (concat (regexp-quote git-log-msg-separator) \"$\\\\|Author: \\\\|Date: \\\\|Merge: \\\\|Signed-off-by: \\\\|\\f\\\\|[ \t]*$\"))\n       (setq buffer-file-coding-system coding-system)\n       (re-search-forward (regexp-quote (concat git-log-msg-separator \"\\n\")) nil t))))\n-- \n1.7.4\n"},{"id":"160392","messageId":"pvhpbp2s58pp.fsf@gmx.li","threadId":"6252","inReplyTo":"20110204001016.GC16688@elie","subject":"Re: [BUG?] git.el: M-x git-commit-file produces error if font lock is disabled","fromName":"Lawrence Mitchell","fromEmail":"wence@gmx.li","sentAt":"2011-02-04T11:40:18Z","receivedAt":"2011-02-04T11:40:18Z","isPatch":false,"sender":{"key":"wence@gmx.li","avatar":"https://avatars.githubusercontent.com/u/1126981?v=4"},"body":"Jonathan Nieder wrote:\n> Hi,\n\n> Kevin Ryde reports[1]:\n\n[...] bug in git.el\n\n> and suggests a patch[2].  Does it make sense?\n\nfont-lock-add-keywords isn't supported in the stable Xemacs\nversion (21.4).  But really, we don't want to /add/ keywords, but\nset up our own, so we should define a major mode appropriately\nand use that in log-edit.  Something like the patch below, I think.\n\n\n>From 6333cd09f1a921757680f1376eeb0a6389d75449 Mon Sep 17 00:00:00 2001\nFrom: Lawrence Mitchell <wence@gmx.li>\nDate: Fri, 4 Feb 2011 10:59:18 +0000\nSubject: [PATCH] git.el: Don't use font-lock-compile-keywords\n\nIf font-lock is disabled, font-lock-compile-keywords complains.\nReally what we want to do is to replace log-edit's font-lock\ndefinitions with our own, so define a major mode deriving from\nlog-edit and set up font-lock-defaults there.  We then use the option\nMODE argument to log-edit to set up the major mode of the commit\nbuffer appropriately.\n\nSigned-Off-By: Lawrence Mitchell <wence@gmx.li>\n---\n contrib/emacs/git.el |   13 ++++++++++---\n 1 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/emacs/git.el b/contrib/emacs/git.el\nindex 214930a..65c95d9 100644\n--- a/contrib/emacs/git.el\n+++ b/contrib/emacs/git.el\n@@ -1310,6 +1310,13 @@ The FILES list must be sorted.\"\n       (when sign-off (git-append-sign-off committer-name committer-email)))\n     buffer))\n \n+(define-derived-mode git-log-edit-mode log-edit-mode \"Git-Log-Edit\"\n+  \"Major mode for editing git log messages.\n+\n+Set up git-specific `font-lock-keywords' for `log-edit-mode'.\"\n+  (set (make-local-variable 'font-lock-defaults)\n+       '(git-log-edit-font-lock-keywords t t)))\n+\n (defun git-commit-file ()\n   \"Commit the marked file(s), asking for a commit message.\"\n   (interactive)\n@@ -1335,9 +1342,9 @@ The FILES list must be sorted.\"\n         (git-setup-log-buffer buffer (git-get-merge-heads) author-name author-email subject date))\n       (if (boundp 'log-edit-diff-function)\n \t  (log-edit 'git-do-commit nil '((log-edit-listfun . git-log-edit-files)\n-\t\t\t\t\t (log-edit-diff-function . git-log-edit-diff)) buffer)\n-\t(log-edit 'git-do-commit nil 'git-log-edit-files buffer))\n-      (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))\n+\t\t\t\t\t (log-edit-diff-function . git-log-edit-diff)) buffer 'git-log-edit-mode)\n+\t(log-edit 'git-do-commit nil 'git-log-edit-files buffer\n+                  'git-log-edit-mode))\n       (setq paragraph-separate (concat (regexp-quote git-log-msg-separator) \"$\\\\|Author: \\\\|Date: \\\\|Merge: \\\\|Signed-off-by: \\\\|\\f\\\\|[ \t]*$\"))\n       (setq buffer-file-coding-system coding-system)\n       (re-search-forward (regexp-quote (concat git-log-msg-separator \"\\n\")) nil t))))\n\n-- \n1.7.4.rc2.18.gb20e9\n"}]}