emacs-devel
[Top][All Lists]
Advanced

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

Re: .dir-locals.el


From: Stefan Monnier
Subject: Re: .dir-locals.el
Date: Thu, 08 Jan 2009 11:30:46 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

> (defadvice cd (after dir-locals-on-cd activate)
>   "Apply the variables defined in .dir-locals.el when changing
> into and outof a directory in eshell."
>   (hack-dir-local-variables))

If you do

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

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)

(defadvice cd (around dir-locals-on-cd activate)
  (while eshell-previous-values
    (let ((x (pop eshell-previous-values)))
      (if (consp x)
          (set (car x) (cdr x))
        (kill-local-variable x))))
  ad-do-it
  (let ((buffer-file-name default-directory))
    (hack-dir-local-variables))
  (dolist (x file-local-variables-alist)
    (let ((var (car x))
          (val (cdr x)))
      (push (if (buffer-local-p var)
                (cons var (symbol-value var))
              var)
           eshell-previous-values)
      (set (make-local-variable var) val))))

> Is there a supported way to do this?

Not.

> If not should I write a new function for this?

Your call.

> If so should it be included in the dir-locals.el functionality?

Not sure.

> If not is there a reason to only allow setting local variables for
> buffers visiting files?

It's not obviously clear that applying .dir-locals.el to eshell like you
suggest is a good idea.  It seems consistent with the idea that
"cd /ssh:foo:" ends up behaving like "ssh foo", tho.

Maybe your suggestion to change hack-dir-local-variables so it uses
default-directory rather than buffer-file-name is a good one.  It seems
like it would be a safe change and would allow the above advice to feel
a tiny bit less hackish.


        Stefan




reply via email to

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