emacs-devel
[Top][All Lists]
Advanced

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

Re: Blunderbuss ".dir-locals.el" raises everything in its path!!


From: Juri Linkov
Subject: Re: Blunderbuss ".dir-locals.el" raises everything in its path!!
Date: Sun, 19 Jul 2009 00:55:05 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

> The problem is that the 3rd case doesn't seem correct.  I think we should
> fix `hack-local-variables-filter' to remove (variable . value) from
> `dir-local-variables-alist' when it comes from file-locals and thus
> overrides dir-locals.
>
> So the 3rd case will be:
>
> 3. if it's set both in file-local and in dir-locals.el
>    then (variable . value) is stored in `file-local-variables-alist'
>    but not in `dir-local-variables-alist'
>
> I could implement this with adding a new variable `dir-local-variables-alist'
> after Yidong installs his patch in the same part of code that removes
> duplicates from `file-local-variables-alist'.

This is implemented in the following patch:

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.1057
diff -c -r1.1057 files.el
*** lisp/files.el       18 Jul 2009 20:41:32 -0000      1.1057
--- lisp/files.el       18 Jul 2009 21:48:54 -0000
***************
*** 2637,2643 ****
  
  (defvar ignored-local-variables
    '(ignored-local-variables safe-local-variable-values
!     file-local-variables-alist)
    "Variables to be ignored in a file's local variable spec.")
  
  (defvar hack-local-variables-hook nil
--- 2637,2643 ----
  
  (defvar ignored-local-variables
    '(ignored-local-variables safe-local-variable-values
!     file-local-variables-alist dir-local-variables-alist)
    "Variables to be ignored in a file's local variable spec.")
  
  (defvar hack-local-variables-hook nil
***************
*** 2760,2765 ****
--- 2760,2774 ----
  if it is changed by the major or minor modes, or by the user.")
  (make-variable-buffer-local 'file-local-variables-alist)
  
+ (defvar dir-local-variables-alist nil
+   "Alist of directory-local variable settings in the current buffer.
+ Each element in this list has the form (VAR . VALUE), where VAR
+ is a directory-local variable (a symbol) found in .dir-locals.el
+ and VALUE is the value specified.  The actual value in the buffer
+ may differ from VALUE, if it is changed by the major or minor modes,
+ or by the user.")
+ (make-variable-buffer-local 'dir-local-variables-alist)
+ 
  (defvar before-hack-local-variables-hook nil
    "Normal hook run before setting file-local variables.
  It is called after checking for unsafe/risky variables and
***************
*** 2963,2969 ****
              (let ((var (car elt)))
                (unless (eq var 'eval)
                  (setq file-local-variables-alist
!                       (assq-delete-all var file-local-variables-alist)))
                (push elt file-local-variables-alist))))
        ;; Query, unless all are known safe or the user wants no
        ;; querying.
--- 2972,2981 ----
              (let ((var (car elt)))
                (unless (eq var 'eval)
                  (setq file-local-variables-alist
!                       (assq-delete-all var file-local-variables-alist))
!                 (unless dir-name
!                   (setq dir-local-variables-alist
!                         (assq-delete-all var dir-local-variables-alist))))
                (push elt file-local-variables-alist))))
        ;; Query, unless all are known safe or the user wants no
        ;; querying.
***************
*** 2977,2983 ****
              (let ((var (car elt)))
                (unless (eq var 'eval)
                  (setq file-local-variables-alist
!                       (assq-delete-all var file-local-variables-alist)))
                (push elt file-local-variables-alist))))))))
  
  
--- 2989,2998 ----
              (let ((var (car elt)))
                (unless (eq var 'eval)
                  (setq file-local-variables-alist
!                       (assq-delete-all var file-local-variables-alist))
!                 (unless dir-name
!                   (setq dir-local-variables-alist
!                         (assq-delete-all var dir-local-variables-alist))))
                (push elt file-local-variables-alist))))))))
  
  
***************
*** 3372,3383 ****
                                      (nth 5 (file-attributes file)))
        class-name)))
  
- (declare-function c-postprocess-file-styles "cc-mode" ())
- 
  (defun hack-dir-local-variables ()
    "Read per-directory local variables for the current buffer.
! Store the directory-local variables in `file-local-variables-alist',
! without applying them."
    (when (and enable-local-variables
             (buffer-file-name)
             (not (file-remote-p (buffer-file-name))))
--- 3387,3396 ----
                                      (nth 5 (file-attributes file)))
        class-name)))
  
  (defun hack-dir-local-variables ()
    "Read per-directory local variables for the current buffer.
! 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))))
***************
*** 3397,3402 ****
--- 3410,3421 ----
               (dir-locals-collect-variables
                (dir-locals-get-class-variables class) dir-name nil)))
          (when variables
+           (dolist (elt variables)
+             (let ((var (car elt)))
+               (unless (eq var 'eval)
+                 (setq dir-local-variables-alist
+                       (assq-delete-all var dir-local-variables-alist)))
+               (push elt dir-local-variables-alist)))
            (hack-local-variables-filter variables dir-name)))))))
  
  

Index: lisp/help-fns.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/help-fns.el,v
retrieving revision 1.133
diff -c -r1.133 help-fns.el
*** lisp/help-fns.el    28 Jun 2009 05:06:59 -0000      1.133
--- lisp/help-fns.el    18 Jul 2009 21:49:33 -0000
***************
*** 710,715 ****
--- 710,727 ----
                             (use (format ";\n  use `%s' instead." (car 
obsolete)))
                             (t ".")))
                  (terpri))
+ 
+             (when (member (cons variable val) file-local-variables-alist)
+               (setq extra-line t)
+               (if (member (cons variable val) dir-local-variables-alist)
+                   (let ((file (and (buffer-file-name)
+                                    (not (file-remote-p (buffer-file-name)))
+                                    (dir-locals-find-file 
(buffer-file-name)))))
+                     (princ "  This variable is a directory local variable")
+                     (if file (princ (concat "\n  from the file \"" file 
"\"")))
+                     (princ ".\n"))
+                 (princ "  This variable is a file local variable.\n")))
+ 
              (when safe-var
                  (setq extra-line t)
                (princ "  This variable is safe as a file local variable ")

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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