emacs-devel
[Top][All Lists]
Advanced

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

Re: .dir-locals.el


From: Eric Schulte
Subject: Re: .dir-locals.el
Date: Thu, 08 Jan 2009 16:30:33 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Stefan Monnier <address@hidden> writes:

> If you do
>
> (defadvice cd (after dir-locals-on-cd activate)
>   (let ((buffer-file-name default-directory))
>     (hack-dir-local-variables)))
>

This generates errors for me which look like.

  Args out of range: "~/src/foo/", 23, 10

However when I actually replace (buffer-file-name) with
default-directory in the function it works fine.

>
> it might get you a bit further.  But note that it still won't do what
> you want: it'll only give you file-local-variables-alist, which you then
> have to apply to the buffer.
>
> Furthermore, before applying it, you'll need to un-apply those settings
> you had applied earlier and which were relevant to the directory in
> which you were before `cd'.
>
> So you'll want something like (100% guaranteed untested)
>
[...]
>

Thanks for this suggestion, using a slightly altered version [1] of what
you suggested I was able to get the behavior I expected.  It's certainly
not pretty, but it seems to work.  Note: most of the code below is just
a copy of hack-dir-local-variables with all calls to buffer-file-name
removed.

Thanks, I'll be using this moving forward -- Eric

[1]
,----
| (defadvice cd (around dir-locals-on-cd activate)
|   "Apply the variables defined in .dir-locals.el when changing
| into and outof a directory in eshell."
|   ;; clean up old variables
|   (while file-local-variables-alist
|     (let ((x (pop file-local-variables-alist)))
|       (kill-local-variable x)))
|   ;; cd
|   ad-do-it
|   ;; run hack-dir-local-variables w/o buffer-file-name
|   (let ((variables-file (dir-locals-find-file default-directory))
|       (class nil)
|       (dir-name nil))
|     (cond
|      ((stringp variables-file)
|       (setq dir-name (file-name-directory default-directory))
|       (setq class (dir-locals-read-from-file variables-file)))
|      ((consp variables-file)
|       (setq dir-name (car variables-file))
|       (setq class (cdr 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)))))
|   ;; apply file-local-variables to buffer
|   (while file-local-variables-alist
|     (let ((x (pop file-local-variables-alist)))
|       (if (consp x)
|           (set (car x) (cdr x))
|         (kill-local-variable x)))))
`----




reply via email to

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