Closed lange1 closed 3 years ago
Yes, but you can set the default-directory
variable as you like, eg. to be your home directory. I did the following in my ~/.emacs.d/init.el
;; Set default directory to user home
(setq default-directory (concat (getenv "HOME") "/"))
The drawback of using default-directory
is, if I'm using emacs from a command line (e.g., emacs -nw
) then I actually want the default directory to be the current working directory, not hard-coded to ~/
.
Can I assume that you didn't change anything in your build scripts between 26.3 and 27.1 that would cause this? In that case, I think my issue is upstream.
I'm not the maintainer, just a plain user experienced the same issue like you did, so to answer your question, I didn't change anything in the build scripts.
Since I don't really use it from the command line, the explicit setting of default-directory
has solved the issue for me. But you're right, this solution will definitely do wrong if you want to use it from the command line.
Yes, I think the issue is upstream. Today, I downloaded the tarball from the official GNU Emacs site and built Emacs from the official source, and I can confirm that the vanilla Emacs version 27.1 behaves the same! So if you launch the Cocoa app, then it will have "/" as the default directory. However if you run it from the command line eg. emacs -nw
, then it will have the cwd
as the default directory. So it seems like it has nothing to do with the emacsformacosx build, but with the new Emacs version itself.
Until I've figured this out, I'm using this in the macOS-specific portion of my config files. It only changes the default directory if it's /
, which I feel is an okay compromise as I basically never launch emacs from the root directory.
(if (string= default-directory "/")
(progn (setq default-directory (concat (getenv "HOME") "/"))
(setq command-line-default-directory default-directory)))
And I came up with the following workaround for the rare occasions I wan't to run it from the command line.
;; Set the default directory to user home, when we launch the Cocoa app, and the default-directory is "/".
(when (and (eq window-system 'ns)
(string= default-directory "/"))
(setq default-directory (concat (getenv "HOME") "/")))
It sets the default-directory
only, when we are on macOS, run the Cocoa app and the default-directory
is set to "/"
at startup. Don't bother setting otherwise.
I'm also curious what has happened in this new version of Emacs. Do you mind posting a short note here is you find out?
This issue has also been raised at https://apple.stackexchange.com/questions/399187/how-to-set-default-directory-for-emacs-27-1-app
If you launch the app from the command line with /Applications/Emacs.app/Contents/MacOS/Emacs
then you get the correct behaviour. Something has changed between 26 and 27 in the way that Emacs inherits its directory from the Finder.
Also M-x shell
no longer runs my .profile
correctly since upgrading to 27. I believe this is part of the same issue, because if I launch it using the command line as mentioned https://github.com/caldwell/build-emacs/issues/98#issuecomment-720579758 then the problem is corrected.
If I launch the binary named Emacs-x86_64-10_14
from the application package using the Finder, the directory is correct again, and consistent with 26. This suggests that there is a problem in the Emacs
script that selects the binary, whether it has changed, or something else has caused it to work differently.
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 https://github.com/caldwell/build-emacs/blob/0b7456860759418ff5b2ebf309f034c94d0e961f/launch.rb#L69 . This is the simplest consistent workaround I can think of, but isn't a proper bug fix because I don't understand how this has gone wrong between 26 and 27.
This looks likely to be the cause of the problem https://github.com/emacs-mirror/emacs/commit/900276502fbb4dcabdabc5d7d24b4bc5645f2cf3
I have sent an Emacs bug report http://debbugs.gnu.org/cgi/bugreport.cgi?bug=44446
“Looks like the fix will be in 27.2.” https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44446#11
I think this issue could be closed on https://github.com/caldwell/build-emacs .
Closing here as the issue seems to be fixed upstream.
@rptb1 Thanks for tracking this down. I was able to verify that it was broken the other day but didn't have any good info about why. It's good to know it's not a build issue.
Running on Mojave. Just upgraded from 26.3 to 27.1.
When I launch Emacs from the GUI (e.g., Finder or Spotlight) and do a
C-x C-f
the default directory is now/
instead of my home directory.Under 26.3 and before, doing the above defaulted to
~/
my home directory.I have made no configuration changes other than the package upgrade (through homebrew).