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: Thu, 16 Jul 2009 03:30:55 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

>> `C-h v' prints "Local in buffer", but maybe it should also add a source
>> of its value, e.g. "a file-local variable" or "a directory-local variable
>> from the file .../.dir-locals.el"?
>
> Patch welcome,

The patch below adds this information to the output of `C-h v'.
It distinguishes file-local variables from dir-local variables
by subtracting `file-local-variables-alist' from `dir-local-variables-alist',
i.e. a file-local variable with its value is a member of only
`file-local-variables-alist', but a dir-local variable with its value
is a member of both.

`dir-local-variables-alist' is a new function refactored from
`hack-dir-local-variables'.  It seems it should not be a variable
since it is required now only for documentation purposes.

Removed (declare-function c-postprocess-file-styles "cc-mode" ())
that are remains of the old code.

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    16 Jul 2009 00:27:09 -0000
***************
*** 685,690 ****
--- 685,691 ----
                              (error variable)))
                     (obsolete (get variable 'byte-obsolete-variable))
                   (use (car obsolete))
+                  (file-local (member (cons variable val) 
file-local-variables-alist))
                   (safe-var (get variable 'safe-local-variable))
                     (doc (or (documentation-property variable 
'variable-documentation)
                              (documentation-property alias 
'variable-documentation)))
***************
*** 710,715 ****
--- 711,728 ----
                             (use (format ";\n  use `%s' instead." (car 
obsolete)))
                             (t ".")))
                  (terpri))
+ 
+             (when file-local
+               (setq extra-line t)
+               (let* ((elt (car (dir-local-variables-alist)))
+                      (dir-name (car elt))
+                      (variables (cdr elt)))
+                 (if (member (cons variable val) variables)
+                     (princ (concat
+                             "  This variable is a directory-local variable\n"
+                             "  from the file \"" dir-name dir-locals-file 
"\".\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 ")

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.1055
diff -c -r1.1055 files.el
*** lisp/files.el       5 Jul 2009 22:15:37 -0000       1.1055
--- lisp/files.el       16 Jul 2009 00:27:28 -0000
***************
*** 3362,3368 ****
                                      (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.
--- 3372,3399 ----
                                      (nth 5 (file-attributes file)))
        class-name)))
  
! (defun dir-local-variables-alist ()
!   "Return an alist of directory-local variable settings in the current buffer.
! Each element in this list has the form (DIR-NAME . VARIABLES),
! where DIR-NAME is a directory name and VARIABLES is an alist of
! directory-local variable settings from this directory with the same
! format as in the variable `file-local-variables-alist'."
!   ;; Find the variables file.
!   (let ((variables-file (dir-locals-find-file (buffer-file-name)))
!       (class nil)
!       (dir-name nil))
!     (cond
!      ((stringp variables-file)
!       (setq dir-name (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))
!       (setq class (nth 1 variables-file))))
!     (when class
!       (list
!        (cons dir-name
!            (dir-locals-collect-variables
!             (dir-locals-get-class-variables class) dir-name nil))))))
  
  (defun hack-dir-local-variables ()
    "Read per-directory local variables for the current buffer.
***************
*** 3371,3393 ****
    (when (and enable-local-variables
             (buffer-file-name)
             (not (file-remote-p (buffer-file-name))))
!     ;; Find the variables file.
!     (let ((variables-file (dir-locals-find-file (buffer-file-name)))
!         (class nil)
!         (dir-name nil))
!       (cond
!        ((stringp variables-file)
!       (setq dir-name (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))
!       (setq class (nth 1 variables-file))))
!       (when class
!       (let ((variables
!              (dir-locals-collect-variables
!               (dir-locals-get-class-variables class) dir-name nil)))
!         (when variables
!           (hack-local-variables-filter variables dir-name)))))))
  
  
  (defcustom change-major-mode-with-file-name t
--- 3402,3412 ----
    (when (and enable-local-variables
             (buffer-file-name)
             (not (file-remote-p (buffer-file-name))))
!     (let* ((elt (car (dir-local-variables-alist)))
!          (dir-name (car elt))
!          (variables (cdr elt)))
!       (when variables
!       (hack-local-variables-filter variables dir-name)))))
  
  
  (defcustom change-major-mode-with-file-name t

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




reply via email to

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