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: Tassilo Horn
Subject: Re: Set the default-directory dynamically according to the buffer-file-name.
Date: Wed, 29 Sep 2021 17:31:26 +0200
User-agent: mu4e 1.7.0; emacs 28.0.50

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'?

Bye,
Tassilo



reply via email to

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