all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#42836: 27.1; default-directory is set to "/" after startup
@ 2020-08-12 20:53 Sean Devlin
       [not found] ` <handler.42836.B.15972656459719.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Sean Devlin @ 2020-08-12 20:53 UTC (permalink / raw)
  To: 42836

Hi folks,

When I start Emacs, the value of default-directory in the *scratch* and
*Messages* buffers is "/". In previous versions of Emacs, it was "~/".

I am on macOS, and I installed Emacs 27.1 as packaged by
https://emacsformacosx.com. There is information about how this is built
and packaged here: https://emacsformacosx.com/about.

Basically, it provides a .app bundle as per typical on macOS. This lets
you open Emacs by clicking on the application icon or running "open -a
Emacs" from the terminal. You can also run it directly by invoking the
full path to the executable
(e.g. /Applications/Emacs.app/Contents/MacOS/Emacs) from the terminal.

When I open Emacs 27.1 by either of the first two methods, the value of
default-directory in the *scratch* and *Messages* buffers is "/". This
is true even though the process working directory is my home directory,
which I verified by running "lsof -a -d cwd -p $(pgrep -i emacs)" after
starting Emacs.

I reinstalled a copy of Emacs 26.3 and verified default-directory used
to be "~/" in these buffers after startup.

When I open Emacs 27.1 by invoking the executable directly (i.e. the
last method above), the default-directory in those buffers is "~/".

I have performed all the above steps using the "-Q" argument to make
sure my own configuration is not confounding anything.

I think you should be able to reproduce by the following steps:

1. Download Emacs from https://emacsformacosx.com and install the
application. (I think
https://emacsformacosx.com/emacs-builds/Emacs-27.1-universal.dmg is the
right URL.)
2. In a terminal, run "open -a Emacs --args -Q" to start Emacs.
3. Once Emacs starts, switch to the *scratch* buffer and evaluate
"default-directory" or "(pwd)" and observe the result.

I tried to do a little digging to determine how and when this variable
is first set to "/", but I couldn't figure it out. It seems that the
default directory is already "/" by the time early-init.el runs. I
determined this by putting "(message default-directory)" in my
early-init.el file and checking the messages buffer after startup.

Please let me know if there's any more information I can provide.

Thanks!


In GNU Emacs 27.1 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95))
of 2020-08-12 built on builder10-14.porkrind.org
Windowing system distributor 'Apple', version 10.3.2004
System Description:  macOS

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set
Mark deactivated
Making completion list...

Configured using:
'configure --with-ns '--enable-locallisppath=/Library/Application
Support/Emacs/${version}/site-lisp:/Library/Application
Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
THREADS JSON PDUMPER

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode elisp-mode lisp-mode prog-mode register page
tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse
jit-lock font-lock syntax facemenu font-core term/tty-colors frame
minibuffer cl-generic cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite charscript charprop case-table epa-hook jka-cmpr-hook help
simple abbrev obarray cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
threads kqueue cocoa ns multi-tty make-network-process emacs)

Memory information:
((conses 16 44955 6142)
(symbols 48 5927 1)
(strings 32 15262 1819)
(string-bytes 1 504806)
(vectors 16 10186)
(vector-slots 8 126975 12482)
(floats 8 19 42)
(intervals 56 201 0)
(buffers 1000 12))





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

* bug#42836: 27.1; default-directory is set to "/" after startup
       [not found] ` <handler.42836.B.15972656459719.ack@debbugs.gnu.org>
@ 2020-08-12 21:17   ` Sean Devlin
  2020-08-12 22:52     ` Alan Third
  2020-08-13  2:32     ` Eli Zaretskii
  0 siblings, 2 replies; 10+ messages in thread
From: Sean Devlin @ 2020-08-12 21:17 UTC (permalink / raw)
  To: 42836

> When I open Emacs 27.1 by invoking the executable directly (i.e. the
> last method above), the default-directory in those buffers is "~/“.

Correction: the default directory is the working directory of the parent process (i.e. the shell) in this case.

Thanks!




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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-12 21:17   ` Sean Devlin
@ 2020-08-12 22:52     ` Alan Third
  2020-08-13 14:52       ` Alan Third
  2020-08-13  2:32     ` Eli Zaretskii
  1 sibling, 1 reply; 10+ messages in thread
From: Alan Third @ 2020-08-12 22:52 UTC (permalink / raw)
  To: Sean Devlin; +Cc: 42836

On Wed, Aug 12, 2020 at 05:17:28PM -0400, Sean Devlin wrote:
> > When I open Emacs 27.1 by invoking the executable directly (i.e. the
> > last method above), the default-directory in those buffers is "~/“.
> 
> Correction: the default directory is the working directory of the
> parent process (i.e. the shell) in this case.

The code at line 1623 of emacs.c appears to be supposed to set the
correct starting directory, however it doesn't matter what it does
there. I've tried hard coding directories and all sorts, but it ALWAYS
ends up starting in "/"... I think something somewhere else must be
resetting it. I can't find where just now. I may have to do a git bisect,
which I don't much fancy.
-- 
Alan Third





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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-12 21:17   ` Sean Devlin
  2020-08-12 22:52     ` Alan Third
@ 2020-08-13  2:32     ` Eli Zaretskii
  2020-08-13  4:08       ` Sean Devlin
  1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2020-08-13  2:32 UTC (permalink / raw)
  To: Sean Devlin; +Cc: 42836

> From: Sean Devlin <spd@toadstyle.org>
> Date: Wed, 12 Aug 2020 17:17:28 -0400
> 
> > When I open Emacs 27.1 by invoking the executable directly (i.e. the
> > last method above), the default-directory in those buffers is "~/“.
> 
> Correction: the default directory is the working directory of the parent process (i.e. the shell) in this case.

If that's what happens, it's what I would expect, and it happens for
me on systems other than macOS.





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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-13  2:32     ` Eli Zaretskii
@ 2020-08-13  4:08       ` Sean Devlin
  0 siblings, 0 replies; 10+ messages in thread
From: Sean Devlin @ 2020-08-13  4:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 42836


> On Aug 12, 2020, at 10:32 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> 
>> 
>> From: Sean Devlin <spd@toadstyle.org>
>> Date: Wed, 12 Aug 2020 17:17:28 -0400
>> 
>>> When I open Emacs 27.1 by invoking the executable directly (i.e. the
>>> last method above), the default-directory in those buffers is "~/“.
>> 
>> Correction: the default directory is the working directory of the parent process (i.e. the shell) in this case.
> 
> If that's what happens, it's what I would expect, and it happens for
> me on systems other than macOS.

That’s not the unexpected part; I just mentioned it for completeness.

The unexpected behavior is that opening the application by clicking the icon sets default-directory to “/“ in the scratch buffer. This is true even though the process-level working directory is my home directory. It is also a change in behavior from 26.3.




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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-12 22:52     ` Alan Third
@ 2020-08-13 14:52       ` Alan Third
  2020-08-13 19:54         ` Paul Eggert
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Third @ 2020-08-13 14:52 UTC (permalink / raw)
  To: Sean Devlin, 42836; +Cc: eggert

On Thu, Aug 13, 2020 at 12:52:51AM +0200, Alan Third wrote:
> On Wed, Aug 12, 2020 at 05:17:28PM -0400, Sean Devlin wrote:
> > > When I open Emacs 27.1 by invoking the executable directly (i.e. the
> > > last method above), the default-directory in those buffers is "~/“.
> > 
> > Correction: the default directory is the working directory of the
> > parent process (i.e. the shell) in this case.
> 
> The code at line 1623 of emacs.c appears to be supposed to set the
> correct starting directory, however it doesn't matter what it does
> there. I've tried hard coding directories and all sorts, but it ALWAYS
> ends up starting in "/"... I think something somewhere else must be
> resetting it. I can't find where just now. I may have to do a git bisect,
> which I don't much fancy.

The commit in question is:

    900276502fbb4dcabdabc5d7d24b4bc5645f2cf3
    Act like POSIX sh if $HOME is relative

I suspect the best solution here is to move the code at line
emacs.c:1623 to before emacs_wd is set. What do you think, Paul?
-- 
Alan Third





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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-13 14:52       ` Alan Third
@ 2020-08-13 19:54         ` Paul Eggert
  2020-08-13 21:18           ` Sean Devlin
  2020-08-13 22:06           ` Alan Third
  0 siblings, 2 replies; 10+ messages in thread
From: Paul Eggert @ 2020-08-13 19:54 UTC (permalink / raw)
  To: Alan Third, Sean Devlin, 42836

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

On 8/13/20 7:52 AM, Alan Third wrote:
> I suspect the best solution here is to move the code at line
> emacs.c:1623 to before emacs_wd is set. What do you think, Paul?

It's probably safer to leave the code where it is, and to update emacs_wd if 
Emacs chdirs successfully.

Does the attached patch work for you? If so, I can install it into the emacs-27 
branch. (I don't use macOS so can't easily test it myself.)

[-- Attachment #2: 0001-Fix-startup-working-dir-bug-on-NeXTSTEP.patch --]
[-- Type: text/x-patch, Size: 1623 bytes --]

From 5bf06fd09669d4b48dc0e3f3f756006d0ca2059b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 13 Aug 2020 12:48:57 -0700
Subject: [PATCH] Fix startup working dir bug on NeXTSTEP

* src/emacs.c (main) [NS_IMPL_COCOA]: Update emacs_wd
after a NS GUI chdirs successfully (Bug#42836).
---
 src/emacs.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/emacs.c b/src/emacs.c
index 1dcf195891..11dcdb33fe 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1638,23 +1638,27 @@ main (int argc, char **argv)
     {
 #ifdef NS_IMPL_COCOA
       /* Started from GUI? */
-      /* FIXME: Do the right thing if get_homedir returns "", or if
-         chdir fails.  */
-      if (! inhibit_window_system && ! isatty (STDIN_FILENO) && ! ch_to_dir)
-        chdir (get_homedir ());
+      bool go_home = (!ch_to_dir && !inhibit_window_system
+		      && !isatty (STDIN_FILENO));
       if (skip_args < argc)
         {
           if (!strncmp (argv[skip_args], "-psn", 4))
             {
               skip_args += 1;
-              if (! ch_to_dir) chdir (get_homedir ());
+	      go_home |= !ch_to_dir;
             }
           else if (skip_args+1 < argc && !strncmp (argv[skip_args+1], "-psn", 4))
             {
               skip_args += 2;
-              if (! ch_to_dir) chdir (get_homedir ());
+	      go_home |= !ch_to_dir;
             }
         }
+      if (go_home)
+	{
+	  char const *home = get_homedir ();
+	  if (*home && chdir (home) == 0)
+	    emacs_wd = emacs_get_current_dir_name ();
+	}
 #endif  /* COCOA */
     }
 #endif /* HAVE_NS */
-- 
2.17.1


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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-13 19:54         ` Paul Eggert
@ 2020-08-13 21:18           ` Sean Devlin
  2020-08-13 22:06           ` Alan Third
  1 sibling, 0 replies; 10+ messages in thread
From: Sean Devlin @ 2020-08-13 21:18 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 42836

Hi Paul,

> Does the attached patch work for you? If so, I can install it into the emacs-27 branch. (I don't use macOS so can't easily test it myself.)
> <0001-Fix-startup-working-dir-bug-on-NeXTSTEP.patch>

I tried the patch, and it does seem to work based on very limited testing. I should also add the caveat that I’m not experienced at building Emacs from source, so please take my testing with a grain of salt.

Thanks!




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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-13 19:54         ` Paul Eggert
  2020-08-13 21:18           ` Sean Devlin
@ 2020-08-13 22:06           ` Alan Third
  2020-08-13 22:44             ` Paul Eggert
  1 sibling, 1 reply; 10+ messages in thread
From: Alan Third @ 2020-08-13 22:06 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Sean Devlin, 42836

On Thu, Aug 13, 2020 at 12:54:00PM -0700, Paul Eggert wrote:
> On 8/13/20 7:52 AM, Alan Third wrote:
> > I suspect the best solution here is to move the code at line
> > emacs.c:1623 to before emacs_wd is set. What do you think, Paul?
> 
> It's probably safer to leave the code where it is, and to update emacs_wd if
> Emacs chdirs successfully.
> 
> Does the attached patch work for you? If so, I can install it into the
> emacs-27 branch. (I don't use macOS so can't easily test it myself.)

It works for me.

Thanks!
-- 
Alan Third





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

* bug#42836: 27.1; default-directory is set to "/" after startup
  2020-08-13 22:06           ` Alan Third
@ 2020-08-13 22:44             ` Paul Eggert
  0 siblings, 0 replies; 10+ messages in thread
From: Paul Eggert @ 2020-08-13 22:44 UTC (permalink / raw)
  To: Alan Third, Sean Devlin, 42836-done

Thanks for checking. I installed the patch on the emacs-27 branch and am closing 
the bug report.





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

end of thread, other threads:[~2020-08-13 22:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-12 20:53 bug#42836: 27.1; default-directory is set to "/" after startup Sean Devlin
     [not found] ` <handler.42836.B.15972656459719.ack@debbugs.gnu.org>
2020-08-12 21:17   ` Sean Devlin
2020-08-12 22:52     ` Alan Third
2020-08-13 14:52       ` Alan Third
2020-08-13 19:54         ` Paul Eggert
2020-08-13 21:18           ` Sean Devlin
2020-08-13 22:06           ` Alan Third
2020-08-13 22:44             ` Paul Eggert
2020-08-13  2:32     ` Eli Zaretskii
2020-08-13  4:08       ` Sean Devlin

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.