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

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

Set the default-directory dynamically according to the buffer-file-name.


From: Hongyi Zhao
Subject: Set the default-directory dynamically according to the buffer-file-name.
Date: Wed, 29 Sep 2021 22:31:20 +0800

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.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



reply via email to

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