Suppose I launch emacs -nw
from DIRECTORY_A
in Terminal.app (osx 10.9.5). Then, inside emacs I navigate to DIRECTORY_B
(e.g., using dired). At this point, if I close emacs (C-x C-c
) or if I do M-x suspend-frame
I find myself in DIRECTORY_A
(of course this is standard behavior).
I would like to be able to execute a command from within emacss that changes DIRECTORY_A
(the directory from which I invoked emacs -nw
) to DIRECTORY_B
(the current directory in emacs). So that when I exit emacs I would end-up in DIRECTORY_B
.
I (naively) attempted achieving this by using a shell command:
(defun my-cd-to-current-dir ()
(interactive)
(shell-command (concat "cd " (expand-file-name "."))))
In the *Messages*
buffer I can see
(Shell command succeeded with no output)
but when I exit emacs I am still in DIRECTORY_A
.
Clarification:
When I change directory within emacs, the value of the environmental variable PWD (accessed via M-! env
) reflects correctly the current directory (DIRECTORY_B
). But if I do M-x suspend-frame
and then issue env
from the prompt in the terminal I get DIRECTORY_A
. Hence, changing the value of PWD from within emacs doesn't seem to solve the problem (it is possible that I am doing something wrong).