emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: path, cwd in NS port


From: Perry E. Metzger
Subject: Re: path, cwd in NS port
Date: Thu, 28 May 2020 16:30:38 -0400

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]