unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Set the default-directory dynamically according to the buffer-file-name.
@ 2021-09-29 14:31 Hongyi Zhao
  2021-09-29 14:50 ` Hongyi Zhao
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Hongyi Zhao @ 2021-09-29 14:31 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-10-01  7:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-29 14:31 Set the default-directory dynamically according to the buffer-file-name Hongyi Zhao
2021-09-29 14:50 ` Hongyi Zhao
2021-09-29 15:31 ` Tassilo Horn
2021-09-30  1:08   ` Hongyi Zhao
2021-09-30  3:37     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30  7:00       ` Hongyi Zhao
2021-09-30  7:39         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30  8:54           ` Hongyi Zhao
2021-09-30  9:58             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-29 15:47 ` [External] : " Drew Adams
2021-10-01  4:41   ` Hongyi Zhao
2021-10-01  7:09     ` Emanuel Berg via Users list for the GNU Emacs text editor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).