[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
- Set the default-directory dynamically according to the buffer-file-name., Hongyi Zhao, 2021/09/29
- Re: Set the default-directory dynamically according to the buffer-file-name., Hongyi Zhao, 2021/09/29
- Re: Set the default-directory dynamically according to the buffer-file-name., Tassilo Horn, 2021/09/29
- Re: Set the default-directory dynamically according to the buffer-file-name.,
Hongyi Zhao <=
- Re: Set the default-directory dynamically according to the buffer-file-name., Emanuel Berg, 2021/09/29
- Re: Set the default-directory dynamically according to the buffer-file-name., Hongyi Zhao, 2021/09/30
- Re: Set the default-directory dynamically according to the buffer-file-name., Emanuel Berg, 2021/09/30
- Re: Set the default-directory dynamically according to the buffer-file-name., Hongyi Zhao, 2021/09/30
- Re: Set the default-directory dynamically according to the buffer-file-name., Emanuel Berg, 2021/09/30
RE: [External] : Set the default-directory dynamically according to the buffer-file-name., Drew Adams, 2021/09/29