help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Set the default-directory dynamically according to the buffer-file-n


From: Hongyi Zhao
Subject: Re: Set the default-directory dynamically according to the buffer-file-name.
Date: Thu, 30 Sep 2021 09:08:08 +0800

On Wed, Sep 29, 2021 at 11:34 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I wrote the following function to set the default-directory
> > dynamically according to the buffer-file-name:
> >
> > (defun my/default-directory ()
> >   (let ((file (buffer-file-name)))
> >     (if (not file)
> >         (message "no file name here.")
> >         (setq default-directory (file-name-directory (buffer-file-name))))))
> >
> > Then I apply this function to specific hooks, say, python-mode-hook.
> > This will make it easier for me to invoke files using the relative
> > path of each project. I want to know if this is a good practice.
>
> Isn't that already the case that file-visiting buffers have
>
>   (file-name-directory (buffer-file-name))
>
> as `default-directory'?

Yes, that's it. So, my code snippet is unnecessary. The problem I
posted here should be relevant to and handled by Projectile, as I've
noticed the following message:

Projectile is initializing cache for /home/werner/ ...

HZ



reply via email to

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