Emacs, change of $PWD variable

浪尽此生 提交于 2019-12-12 02:53:37

问题


I do always work with emacs in no windows mode (emacs -nw) inside Guake, and I have set guake to open a new tab in the same directory on which I'm in that moment.

My purpose is:

  • If I work with a certain file in emacs, and I open a new tab, I want the path (PWD variable) is the same of the file.
  • When I close emacs, the PWD variable is restored with its original value.

How can I set my .emacs file to achieve that?


回答1:


With the help of wvxvw's answer:

(defvar pwd-orig (getenv "PWD"))

(add-hook 'find-file-hook (lambda () (setenv "PWD" default-directory)))

(add-hook 'kill-emacs-hook (lambda () (setenv "PWD" pwd-orig)))




回答2:


M-xcd You can use it in .emacs like this:

(defvar initial-directory (getenv "PWD"))
(cd "~/some-directory/")
(add-hook 'kill-emacs-hook (lambda () (cd initial-directory)))

Sorry, I didn't test the above, but it looks like it would work. (Not sure about how many arguments the 'kill-emacs-hook takes.



来源:https://stackoverflow.com/questions/17123765/emacs-change-of-pwd-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!