unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* path, cwd in NS port
@ 2020-05-28 15:00 Perry E. Metzger
  2020-05-28 16:10 ` Eli Zaretskii
  2020-05-28 17:45 ` Stefan Monnier
  0 siblings, 2 replies; 12+ messages in thread
From: Perry E. Metzger @ 2020-05-28 15:00 UTC (permalink / raw)
  To: emacs-devel

Howdy! For years, it has irritated me a bit that when Emacs is
invoked by double-clicking the icon in the NS port, that the
user's path is basically empty and the selected cwd is sometimes "/".

I would like to make it possible for a user to at least correct this
situation in their .emacs by knowing when Emacs has been invoked by
launching the .app versus when it has been invoked from the command
line (and has the proper PATH set etc.)

Does anyone have ideas for ways that the user could figure out which
it is correctly inside their init file? (It's okay if the method
doesn't currently exist and it would require hacking to Emacs to add
such a feature; I'll happily do that.)

Note that in a theoretical sense such an issue probably exists on
other platforms (or might in the future) so something clean would be
good.

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: path, cwd in NS port
  2020-05-28 15:00 path, cwd in NS port Perry E. Metzger
@ 2020-05-28 16:10 ` Eli Zaretskii
  2020-05-28 16:31   ` Perry E. Metzger
  2020-05-28 17:45 ` Stefan Monnier
  1 sibling, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2020-05-28 16:10 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

> Date: Thu, 28 May 2020 11:00:37 -0400
> From: "Perry E. Metzger" <perry@piermont.com>
> 
> Howdy! For years, it has irritated me a bit that when Emacs is
> invoked by double-clicking the icon in the NS port, that the
> user's path is basically empty and the selected cwd is sometimes "/".
> 
> I would like to make it possible for a user to at least correct this
> situation in their .emacs by knowing when Emacs has been invoked by
> launching the .app versus when it has been invoked from the command
> line (and has the proper PATH set etc.)
> 
> Does anyone have ideas for ways that the user could figure out which
> it is correctly inside their init file? (It's okay if the method
> doesn't currently exist and it would require hacking to Emacs to add
> such a feature; I'll happily do that.)

Is this the same problem as discussed in bug#40924?  (I don't use
macOS, so apologies if I;m confused about this issue.)



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

* Re: path, cwd in NS port
  2020-05-28 16:10 ` Eli Zaretskii
@ 2020-05-28 16:31   ` Perry E. Metzger
  2020-05-28 20:46     ` Alan Third
  2020-05-28 22:38     ` 조성빈
  0 siblings, 2 replies; 12+ messages in thread
From: Perry E. Metzger @ 2020-05-28 16:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

On Thu, 28 May 2020 19:10:43 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
> > Date: Thu, 28 May 2020 11:00:37 -0400
> > From: "Perry E. Metzger" <perry@piermont.com>
> > 
> > Howdy! For years, it has irritated me a bit that when Emacs is
> > invoked by double-clicking the icon in the NS port, that the
> > user's path is basically empty and the selected cwd is sometimes
> > "/".
> > 
> > I would like to make it possible for a user to at least correct
> > this situation in their .emacs by knowing when Emacs has been
> > invoked by launching the .app versus when it has been invoked
> > from the command line (and has the proper PATH set etc.)
> > 
> > Does anyone have ideas for ways that the user could figure out
> > which it is correctly inside their init file? (It's okay if the
> > method doesn't currently exist and it would require hacking to
> > Emacs to add such a feature; I'll happily do that.)  
> 
> Is this the same problem as discussed in bug#40924?  (I don't use
> macOS, so apologies if I;m confused about this issue.)

It's certainly a version of the same issue; something happened such
that the default CWD is no longer set to ~/ recently. That should be
fixed independently if anyone knows what changed. (I've noticed this
issue myself and it is quite irritating.)

However, the user's PATH has always been non-optimal on invocation
from the dock, spotlight, clicking in the Applications directory, etc.
If the thing invoking Emacs doesn't already have the user's PATH in
its environment, it can't pass it to Emacs, and it would be nice for
Emacs users to have an easy solution to fix this.

I imagine such problems will also exist in some Linux window managers
etc. as well.

This issue was brought up on the list only a week or two ago I
believe. I've started poking and prodding at it.

One option that occurred to me was that it would be pretty easy to
invoke an "echo $PATH" shell command in my .emacs and parse it into
the exec-path, though I'd prefer only to do this if Emacs was invoked
a certain way (from the dock, spotlight, etc.) where the PATH is
known not to be set. 

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: path, cwd in NS port
  2020-05-28 15:00 path, cwd in NS port Perry E. Metzger
  2020-05-28 16:10 ` Eli Zaretskii
@ 2020-05-28 17:45 ` Stefan Monnier
  2020-05-28 20:30   ` Perry E. Metzger
  1 sibling, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2020-05-28 17:45 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

> I would like to make it possible for a user to at least correct this
> situation in their .emacs by knowing when Emacs has been invoked by
> launching the .app versus when it has been invoked from the command
> line (and has the proper PATH set etc.)

I don't know if that can be easily detected, but you can simply try
something like the following in your .emacs:

    (when (equal default-directory "/") (cd "~/"))

> Note that in a theoretical sense such an issue probably exists on
> other platforms (or might in the future) so something clean would
> be good.

At leas under GNU/Linux, I can't think of any reason a GUI desktop
environment would use "/" as the starting directory for an application
unless maybe that app is started as root.

Then again, that same reasoning implies that it's braindead for macOS to
do just that.  I take it as an implicit statement on the part of Apple
that they really intend to move towards single-user systems (as is
basically the case for their iOS devices already)


        Stefan




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

* Re: path, cwd in NS port
  2020-05-28 17:45 ` Stefan Monnier
@ 2020-05-28 20:30   ` Perry E. Metzger
  0 siblings, 0 replies; 12+ messages in thread
From: Perry E. Metzger @ 2020-05-28 20:30 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Thu, 28 May 2020 13:45:17 -0400 Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> > I would like to make it possible for a user to at least correct
> > this situation in their .emacs by knowing when Emacs has been
> > invoked by launching the .app versus when it has been invoked
> > from the command line (and has the proper PATH set etc.)  
> 
> I don't know if that can be easily detected, but you can simply try
> something like the following in your .emacs:
> 
>     (when (equal default-directory "/") (cd "~/"))

Already done, but a bit more sophisticated.

Right now, I have a script called "emacs" that invokes Emacs that
reads:

--------------------
#!/bin/sh

export EMACS_INVOKED_FROM_SHELL=1
exec /Applications/Emacs.app/Contents/MacOS/Emacs "$@"
exit 1
--------------------

This assures that when I type "emacs" on the command line, I get the
one I want.

My .emacs has:

--------------------
;;;; Am I being run as Emacs.app by clicking?
(defvar invoked-as-app
  (if (and window-system
           (not (getenv "EMACS_INVOKED_FROM_SHELL")))
      t nil)
  "If t, Emacs has been invoked by clicking on an icon.")

(if invoked-as-app (cd "~/"))
--------------------

I can do anything I like on invoked-as-app, including messing with the
path etc.

However,

1. Setting the CWD shouldn't really be necessary (as Eli points out,
there's an open bug report about it having been broken in 27; it was
working "right" before that) and
2. It would be nice if there was an "official" way to know you were
invoked from the dock etc. One option would be a flag or environment
variable in the Info.plist invoked when Emacs is started that way.

> Then again, that same reasoning implies that it's braindead for
> macOS to do just that.  I take it as an implicit statement on the
> part of Apple that they really intend to move towards single-user
> systems (as is basically the case for their iOS devices already)

No, again, part of this (the working directory) is broken in recent
Emacs versions for some reason. However, the PATH problem is long
term; the user's PATH is set in their bash or zsh init scripts, but
isn't available to the window manager.

What I could do is invoke "echo $PATH" in my .emacs iff emacs has been
invoked from the dock or spotlight or what have you, but again, it
would be nice if there was something official to test for to know to
do that.

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: path, cwd in NS port
  2020-05-28 16:31   ` Perry E. Metzger
@ 2020-05-28 20:46     ` Alan Third
  2020-05-28 22:30       ` 조성빈
  2020-05-30  1:03       ` Perry E. Metzger
  2020-05-28 22:38     ` 조성빈
  1 sibling, 2 replies; 12+ messages in thread
From: Alan Third @ 2020-05-28 20:46 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: Eli Zaretskii, emacs-devel

On Thu, May 28, 2020 at 12:31:37PM -0400, Perry E. Metzger wrote:
> On Thu, 28 May 2020 19:10:43 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
> > Is this the same problem as discussed in bug#40924?  (I don't use
> > macOS, so apologies if I;m confused about this issue.)
> 
> It's certainly a version of the same issue; something happened such
> that the default CWD is no longer set to ~/ recently. That should be
> fixed independently if anyone knows what changed. (I've noticed this
> issue myself and it is quite irritating.)

Does it definitely work in Emacs 26? I've had this

      ((string-equal system-type "darwin")
       (setq default-directory (concat (getenv "HOME") "/"))

in my init.el since 2015.

> One option that occurred to me was that it would be pretty easy to
> invoke an "echo $PATH" shell command in my .emacs and parse it into
> the exec-path, though I'd prefer only to do this if Emacs was invoked
> a certain way (from the dock, spotlight, etc.) where the PATH is
> known not to be set. 

A cheap and nasty method would be to look for environment variables
normally set by the shell.

Why not use exec-path-from-shell?
-- 
Alan Third



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

* Re: path, cwd in NS port
  2020-05-28 20:46     ` Alan Third
@ 2020-05-28 22:30       ` 조성빈
  2020-05-30  1:03       ` Perry E. Metzger
  1 sibling, 0 replies; 12+ messages in thread
From: 조성빈 @ 2020-05-28 22:30 UTC (permalink / raw)
  To: Alan Third; +Cc: Perry E. Metzger, Eli Zaretskii, Emacs-devel


> On May 29, 2020, at 5:50 AM, Alan Third <alan@idiocy.org> wrote:
> 
> On Thu, May 28, 2020 at 12:31:37PM -0400, Perry E. Metzger wrote:
>>> On Thu, 28 May 2020 19:10:43 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
>>> Is this the same problem as discussed in bug#40924?  (I don't use
>>> macOS, so apologies if I;m confused about this issue.)
>> 
>> It's certainly a version of the same issue; something happened such
>> that the default CWD is no longer set to ~/ recently. That should be
>> fixed independently if anyone knows what changed. (I've noticed this
>> issue myself and it is quite irritating.)
> 
> Does it definitely work in Emacs 26?

For me, (as with other people) this was only a problem in Emacs 27 — in Emacs 26 it worked in my machine.

> I've had this
> 
>      ((string-equal system-type "darwin")
>       (setq default-directory (concat (getenv "HOME") "/"))
> 
> in my init.el since 2015.
> 
>> One option that occurred to me was that it would be pretty easy to
>> invoke an "echo $PATH" shell command in my .emacs and parse it into
>> the exec-path, though I'd prefer only to do this if Emacs was invoked
>> a certain way (from the dock, spotlight, etc.) where the PATH is
>> known not to be set. 
> 
> A cheap and nasty method would be to look for environment variables
> normally set by the shell.
> 
> Why not use exec-path-from-shell?
> -- 
> Alan Third
> 



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

* Re: path, cwd in NS port
  2020-05-28 16:31   ` Perry E. Metzger
  2020-05-28 20:46     ` Alan Third
@ 2020-05-28 22:38     ` 조성빈
  2020-05-28 22:52       ` Stefan Monnier
  1 sibling, 1 reply; 12+ messages in thread
From: 조성빈 @ 2020-05-28 22:38 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: Eli Zaretskii, Emacs-devel


> On May 29, 2020, at 1:33 AM, Perry E. Metzger <perry@piermont.com> wrote:
> 
> On Thu, 28 May 2020 19:10:43 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
>>> Date: Thu, 28 May 2020 11:00:37 -0400
>>> From: "Perry E. Metzger" <perry@piermont.com>
>>> 
>>> Howdy! For years, it has irritated me a bit that when Emacs is
>>> invoked by double-clicking the icon in the NS port, that the
>>> user's path is basically empty and the selected cwd is sometimes
>>> "/".
>>> 
>>> I would like to make it possible for a user to at least correct
>>> this situation in their .emacs by knowing when Emacs has been
>>> invoked by launching the .app versus when it has been invoked
>>> from the command line (and has the proper PATH set etc.)
>>> 
>>> Does anyone have ideas for ways that the user could figure out
>>> which it is correctly inside their init file? (It's okay if the
>>> method doesn't currently exist and it would require hacking to
>>> Emacs to add such a feature; I'll happily do that.)  
>> 
>> Is this the same problem as discussed in bug#40924?  (I don't use
>> macOS, so apologies if I;m confused about this issue.)
> 
> It's certainly a version of the same issue; something happened such
> that the default CWD is no longer set to ~/ recently. That should be
> fixed independently if anyone knows what changed. (I've noticed this
> issue myself and it is quite irritating.)
> 
> However, the user's PATH has always been non-optimal on invocation
> from the dock, spotlight, clicking in the Applications directory, etc.
> If the thing invoking Emacs doesn't already have the user's PATH in
> its environment, it can't pass it to Emacs, and it would be nice for
> Emacs users to have an easy solution to fix this.

Actually, I didn’t mention this in that thread but (as a macOS user) I’m not sure if Emacs having the shell env vars is expected behavior: I think most people would expect it to have the PATH as defined in /etc/paths and /etc/paths.d (as all GUI programs). 

> I imagine such problems will also exist in some Linux window managers
> etc. as well.

Linux has the concept of the login shell, which means that the .profile (or whatever login shell init file is) gets executed and the environment persists during computer use — that’s why the environment is inherited. In macOS that’s not the case, and it’s rather unexpected to have the shell variables.

I’m not sure how to reliably get the env-vars as well, too. AFAIK exec-path-with-shell requires the shell to be a POSIXy one — something that is usually true to not be a problem in practice as a package, but it won’t work if the user uses e.g. powershell as the default shellZ

> This issue was brought up on the list only a week or two ago I
> believe. I've started poking and prodding at it.
> 
> One option that occurred to me was that it would be pretty easy to
> invoke an "echo $PATH" shell command in my .emacs and parse it into
> the exec-path, though I'd prefer only to do this if Emacs was invoked
> a certain way (from the dock, spotlight, etc.) where the PATH is
> known not to be set. 
> 
> Perry
> -- 
> Perry E. Metzger        perry@piermont.com
> 



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

* Re: path, cwd in NS port
  2020-05-28 22:38     ` 조성빈
@ 2020-05-28 22:52       ` Stefan Monnier
  2020-05-30  0:48         ` 조성빈
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2020-05-28 22:52 UTC (permalink / raw)
  To: 조성빈; +Cc: Eli Zaretskii, Emacs-devel, Perry E. Metzger

> Linux has the concept of the login shell, which means that the .profile (or

But that's only for *interactive shells*, such as SSH logins.
For GUI that doesn't work, since the login shell may be a program such
as zsh, tcsh, scsh, Emacs, and many more so there's no standard way for
the GUI program to start a "login shell" and tell it to do something
because each shell uses a different syntax.


        Stefan




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

* Re: path, cwd in NS port
  2020-05-28 22:52       ` Stefan Monnier
@ 2020-05-30  0:48         ` 조성빈
  2020-05-30 14:17           ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: 조성빈 @ 2020-05-30  0:48 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Perry E. Metzger, Eli Zaretskii, Emacs-devel


> On May 29, 2020, at 7:53 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
> 
>> Linux has the concept of the login shell, which means that the .profile (or
> 
> But that's only for *interactive shells*, such as SSH logins.
> For GUI that doesn't work, since the login shell may be a program such
> as zsh, tcsh, scsh, Emacs, and many more so there's no standard way for
> the GUI program to start a "login shell"

But I thought in Linux the login shell gets started on boot (by systemd)? So  the GUI doesn’t need to go through hoops to get PATH — It’s automatically inherited.

> and tell it to do something
> because each shell uses a different syntax.
> 
> 
>       Stefan



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

* Re: path, cwd in NS port
  2020-05-28 20:46     ` Alan Third
  2020-05-28 22:30       ` 조성빈
@ 2020-05-30  1:03       ` Perry E. Metzger
  1 sibling, 0 replies; 12+ messages in thread
From: Perry E. Metzger @ 2020-05-30  1:03 UTC (permalink / raw)
  To: Alan Third; +Cc: Eli Zaretskii, emacs-devel

On Thu, 28 May 2020 21:46:48 +0100 Alan Third <alan@idiocy.org> wrote:
> Does it definitely work in Emacs 26? I've had this
> 
>       ((string-equal system-type "darwin")
>        (setq default-directory (concat (getenv "HOME") "/"))

Yes; I've confirmed it works in Emacs 26 but not 27.

> > One option that occurred to me was that it would be pretty easy to
> > invoke an "echo $PATH" shell command in my .emacs and parse it
> > into the exec-path, though I'd prefer only to do this if Emacs
> > was invoked a certain way (from the dock, spotlight, etc.) where
> > the PATH is known not to be set.   
> 
> A cheap and nasty method would be to look for environment variables
> normally set by the shell.

That's possible, though I think the cleanest solution would be for
Emacs to set something itself using Info.plist

> Why not use exec-path-from-shell?

exec-path-from-shell seems to be a third party package that I did not
previously know existed.

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: path, cwd in NS port
  2020-05-30  0:48         ` 조성빈
@ 2020-05-30 14:17           ` Stefan Monnier
  0 siblings, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2020-05-30 14:17 UTC (permalink / raw)
  To: 조성빈; +Cc: Eli Zaretskii, Emacs-devel, Perry E. Metzger

> But I thought in Linux the login shell gets started on boot (by systemd)?

It can't for the same reason, plus it can't because on boot systemd
doesn't know which user(s) will later start a GUI login.


        Stefan




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

end of thread, other threads:[~2020-05-30 14:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-28 15:00 path, cwd in NS port Perry E. Metzger
2020-05-28 16:10 ` Eli Zaretskii
2020-05-28 16:31   ` Perry E. Metzger
2020-05-28 20:46     ` Alan Third
2020-05-28 22:30       ` 조성빈
2020-05-30  1:03       ` Perry E. Metzger
2020-05-28 22:38     ` 조성빈
2020-05-28 22:52       ` Stefan Monnier
2020-05-30  0:48         ` 조성빈
2020-05-30 14:17           ` Stefan Monnier
2020-05-28 17:45 ` Stefan Monnier
2020-05-28 20:30   ` Perry E. Metzger

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).