[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: log-edit-strip-single-file-name

From: Dan Nicolaescu
Subject: Re: log-edit-strip-single-file-name
Date: Wed, 3 Feb 2010 23:51:31 -0800 (PST)

Stefan Monnier <address@hidden> writes:

  > >> >>> Should I be setting log-edit-strip-single-file-name to nil when using
  > >> > [...]
  > >> >>> If so, it should probably be in Emacs's .dir-locals.el.
  > >> >> Agreed,
  > >> > It doesn't work.  I guess dir-locals doesn't affect buffers not
  > >> > visiting files.
  > >> 
  > >> This is a "general" problem that we may want to solve: non-file (nor
  > >> dired) buffers that are (loosely) associated with a particular
  > >> directory should probably obey .dir-locals.el.
  > > How about solvin specific instances of this problem by calling
  > > `hack-dir-local-variables' from `log-edit-mode' and other VC related
  > > modes?
  > Doesn't sound too bad.  Just try and make sure the log-edit part of the
  > code is as clean as possible (i.e. modify hack-dir-local-variables or
  > provide a wrapper or a different function if extra work is needed), so
  > we have a clear path to add that functionality on other codes
  > (e.g. vc-dir, diff-mode, ...).

Here's the first cut, that amazingly works.
log-edit-strip-single-file-name is set correctly from .dir-locals.el
after this patch.
(the code  that sets the local variables  in
hack-dir-local-variables-non-file-buffer should be put in a function
that is also called from hack-local-variables).


--- files.el.~1.1104.~  2009-12-17 08:08:20.000000000 -0800
+++ files.el    2010-02-03 23:38:35.000000000 -0800
@@ -3403,20 +3403,21 @@ is found.  Returns the new class name."
                                      (nth 5 (file-attributes file)))
-(defun hack-dir-local-variables ()
-  "Read per-directory local variables for the current buffer.
+(defun hack-dir-local-variables (&optional dname)
+  "Read per-directory local variables.
+If DNAME is set look in that directory, if not look current buffer's default 
 Store the directory-local variables in `dir-local-variables-alist'
 and `file-local-variables-alist', without applying them."
   (when (and enable-local-variables
-            (buffer-file-name)
-            (not (file-remote-p (buffer-file-name))))
+            (or dname (buffer-file-name))
+            (not (file-remote-p (or dname (buffer-file-name)))))
     ;; Find the variables file.
-    (let ((variables-file (dir-locals-find-file (buffer-file-name)))
+    (let ((variables-file (dir-locals-find-file (or dname (buffer-file-name))))
          (class nil)
          (dir-name nil))
        ((stringp variables-file)
-       (setq dir-name (file-name-directory (buffer-file-name)))
+       (setq dir-name (or dname (file-name-directory (buffer-file-name))))
        (setq class (dir-locals-read-from-file variables-file)))
        ((consp variables-file)
        (setq dir-name (nth 0 variables-file))
@@ -3433,6 +3434,18 @@ and `file-local-variables-alist', withou
              (push elt dir-local-variables-alist))
            (hack-local-variables-filter variables dir-name)))))))
+(defun hack-dir-local-variables-non-file-buffer (dname)
+  (hack-dir-local-variables dname)
+  (when file-local-variables-alist
+    ;; Any 'evals must run in the Right sequence.
+    (setq file-local-variables-alist
+         (nreverse file-local-variables-alist))
+    (run-hooks 'before-hack-local-variables-hook)
+    (dolist (elt file-local-variables-alist)
+      (hack-one-local-variable (car elt) (cdr elt))))
+  (run-hooks 'hack-local-variables-hook))
 (defcustom change-major-mode-with-file-name t
   "Non-nil means \\[write-file] should set the major mode from the file name.

--- log-edit.el.~1.56.~ 2009-10-03 03:20:50.000000000 -0700
+++ log-edit.el 2010-02-03 23:41:20.000000000 -0800
@@ -152,6 +152,8 @@ can be obtained from `log-edit-files'."
   "If non-nil, remove file name from single-file log entries."
   :type 'boolean)
+(put 'log-edit-strip-single-file-name 'safe-local-variable 'booleanp)
 (defvar cvs-changelog-full-paragraphs t)
 (make-obsolete-variable 'cvs-changelog-full-paragraphs
@@ -365,7 +389,8 @@ commands (under C-x v for VC, for exampl
   (set (make-local-variable 'font-lock-defaults)
        '(log-edit-font-lock-keywords t))
-  (make-local-variable 'log-edit-comment-ring-index))
+  (make-local-variable 'log-edit-comment-ring-index)
+  (hack-dir-local-variables-non-file-buffer default-directory))
 (defun log-edit-hide-buf (&optional buf where)
   (when (setq buf (get-buffer (or buf log-edit-files-buf)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]