unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Perry E. Metzger" <perry@piermont.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: path, cwd in NS port
Date: Thu, 28 May 2020 16:30:38 -0400	[thread overview]
Message-ID: <20200528163038.07d03193@jabberwock.cb.piermont.com> (raw)
In-Reply-To: <jwv4ks0klja.fsf-monnier+emacs@gnu.org>

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	other threads:[~2020-05-28 20:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200528163038.07d03193@jabberwock.cb.piermont.com \
    --to=perry@piermont.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).