I just upgraded Emacs to 27.1 using brew cask
. One noticeable change is that when I launch the app and c-x c-f
the directory is /
instead of ~/
.
This really bothers me, is there a way to change it back?
I had the same issue after installing Emacs 27.1, my default directory became "/"
I could fix it by adding the following to my .emacs file.
(setq default-directory "~/")
(setq command-line-default-directory "~/")
(setq default-directory "~/")
to my .emacs, but when I c-x c-f
the default directory is still /
. But weirdly, if I switch to another buffer like *scratch*
then it becomes ~/
. So I think maybe this is related to some unknown change of *GNU Emacs
buffer.
Commented
Aug 14, 2020 at 20:18
(setq command-line-default-directory "~/")
. I'll update the answer
emacs -nw foo.c
will open ~/foo.c and not ./foo.c.
Commented
Aug 19, 2020 at 12:45
dotspacemacs/user-init
section not user-config
as it needs to be loaded before subsequent packages. Sigh. Seems they've known about this forever but still released it lists.gnu.org/archive/html/help-gnu-emacs/2020-04/msg00240.html
Commented
Oct 4, 2020 at 0:05
'emacsclient -nw -a "" -c "$@"'
-- I alias it in my .zshrc file, alias sp='emacsclient -nw -a "" -c "$@"'
. Files seem to open correctly from the command line.
Commented
Nov 8, 2020 at 15:25
I have worked around this issue by editing /Applications/Emacs.app/Contents/MacOS/Emacs, inserting
Dir.chdir(ENV['HOME'])
before the call to exec at line 69
exec [emacs[:exe], emacs[:exe]], *ARGV
This is obviously just a temporary workaround, but it restores the previous behaviour of Emacs 26 without modifying any of my configuration or affecting Emacs command line calls, since it only modifies the Finder launch.
I've also posted this at https://github.com/caldwell/build-emacs/issues/98#issuecomment-720609277 EDIT: “Looks like the fix will be in 27.2.” https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44446#11
Dir.chdir(ENV['HOME'])
to: if ENV['PWD']\n Dir.chdir(ENV['PWD'])\n else\n Dir.chdir(ENV['HOME'])\n end
. That did the trick! (sorry about the bad formatting)
Commented
Jan 18, 2021 at 17:11
Following the lead of @rptb1 , I modified /Applications/Emacs.app/Contents/MacOS/Emacs, inserting
if ENV['PWD']
Dir.chdir(ENV['PWD'])
else
Dir.chdir(ENV['HOME'])
end
before the call to exec
:
exec [emacs[:exe], emacs[:exe]], *ARGV
The advantage of this over the previous answer is that if you start emacs with the open
command, you'll get the current working directory, which is normally what you'd expect, instead of your home directory. This is critical for me because I often use the command-line to open a file in the current directory.
Although this is mostly a duplicate of his answer, I am posting it as a new answer because my comment on his answer came out so badly formatted. I hope the upcoming bug fix preserves the current directory, as emacs 26 did.
open
before this bug was introduced?
open
before I upgraded to emacs 27.1 more-or-less matches the behavior I now get with 27.1 combined with this script change. Does that answer your question?
Commented
Jan 21, 2021 at 17:17
~/
that a shortcut to your home directory.~/
=$HOME
=/Users/DreamLinuxer/
See Bash Tilde Expansion for more info./
.c-x c-f
this is what shows up i.imgur.com/RM1sQih.png . But in 26.3 the path is~/
instead of/
.