unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* PWD is not seen by my emacs installation
@ 2023-08-08  1:58 Patrick Mahan
  2023-08-08 12:44 ` tpeplt
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Patrick Mahan @ 2023-08-08  1:58 UTC (permalink / raw)
  To: Help Gnu Emacs

Hardware -

   Macbook Pro 14" (Apple M1 Pro)
   Mac OS 13.1 (Ventura)

Emacs -

   Emacs 28.2 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00
Version 12.0.1 (Build 21A559)) of 2022-09-12)

My emacs does not see the current directory, but instead is expecting
everything to be under ~/.  I thought emacs grokked the PWD environment
variable.

From my shell -

    % echo $PWD
    /Users/mahan/src/PPP/ppp-master/pppd

But inside my .emacs I have -

(setq workingdir (getenv "PWD"))
message "PWD = '%s'" workingdir)

Which results in -

PWD = ’nil’

Unless I open using a Full pathname, it will not open the file correctly.

Suggestions?

Thanks,

Patrick


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

* Re: PWD is not seen by my emacs installation
  2023-08-08  1:58 PWD is not seen by my emacs installation Patrick Mahan
@ 2023-08-08 12:44 ` tpeplt
       [not found]   ` <CAFDHx1Jk=jtHhLdThFUeFpfa=yGTXoKYuu0bADYAN-j-7FjSHw@mail.gmail.com>
  2023-08-08 19:07 ` stefan-husmann
  2023-08-30 22:29 ` Rudolf Adamkovič
  2 siblings, 1 reply; 12+ messages in thread
From: tpeplt @ 2023-08-08 12:44 UTC (permalink / raw)
  To: Patrick Mahan; +Cc: Help Gnu Emacs

Patrick Mahan <plmahan@gmail.com> writes:

>
> But inside my .emacs I have -
>
> (setq workingdir (getenv "PWD"))
> message "PWD = '%s'" workingdir)
>
> Which results in -
>
> PWD = ’nil’
>
> Unless I open using a Full pathname, it will not open the file correctly.
>
> Suggestions?
>

1. View your *Messages* (type C-h e) to see if there are any error
   messages during Emacs’s start-up that might be related to this.

2. Read the Emacs manual on the environment (although there does not
   appear to be any problem with your expressions other than a missing
   leading parenthesis before ‘message’).  Type

      M-: (info "(emacs) Environment")

--



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

* Re: PWD is not seen by my emacs installation
  2023-08-08  1:58 PWD is not seen by my emacs installation Patrick Mahan
  2023-08-08 12:44 ` tpeplt
@ 2023-08-08 19:07 ` stefan-husmann
  2023-08-08 21:21   ` Patrick Mahan
  2023-08-30 22:29 ` Rudolf Adamkovič
  2 siblings, 1 reply; 12+ messages in thread
From: stefan-husmann @ 2023-08-08 19:07 UTC (permalink / raw)
  To: Patrick Mahan; +Cc: help-gnu-emacs


Patrick Mahan <plmahan@gmail.com> writes:

> Hardware -
>
>    Macbook Pro 14" (Apple M1 Pro)
>    Mac OS 13.1 (Ventura)
>
> Emacs -
>
>    Emacs 28.2 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00
> Version 12.0.1 (Build 21A559)) of 2022-09-12)
>
> My emacs does not see the current directory, but instead is expecting
> everything to be under ~/.  I thought emacs grokked the PWD environment
> variable.
>
> From my shell -
>
>     % echo $PWD
>     /Users/mahan/src/PPP/ppp-master/pppd
>
> But inside my .emacs I have -
>
> (setq workingdir (getenv "PWD"))
> message "PWD = '%s'" workingdir)

There is  missing a ( at beginning of line? You should get an
"unbalanced parantheses" message.

>
> Which results in -
>
> PWD = ’nil’
>
> Unless I open using a Full pathname, it will not open the file
> correctly.

What file?
>
> Suggestions?
>
> Thanks,
>
> Patrick


How did you invoke emacs? If you start it from some graphical MacOS
environment, may PWD _is_ undefined (I know nothing about MacOS)? Did you cd into
/Users/mahan/src/PPP/ppp-master/pppd in a shell and start emacs from
the command line from there?

Best Regards
Stefan



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

* Re: PWD is not seen by my emacs installation
  2023-08-08 19:07 ` stefan-husmann
@ 2023-08-08 21:21   ` Patrick Mahan
  2023-08-09  5:37     ` Rudolf Schlatte
  0 siblings, 1 reply; 12+ messages in thread
From: Patrick Mahan @ 2023-08-08 21:21 UTC (permalink / raw)
  To: stefan-husmann; +Cc: help-gnu-emacs

On Tue, Aug 8, 2023 at 12:27 PM <stefan-husmann@t-online.de> wrote:

>
> Patrick Mahan <plmahan@gmail.com> writes:
>
> > Hardware -
> >
> >    Macbook Pro 14" (Apple M1 Pro)
> >    Mac OS 13.1 (Ventura)
> >
> > Emacs -
> >
> >    Emacs 28.2 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00
> > Version 12.0.1 (Build 21A559)) of 2022-09-12)
> >
> > My emacs does not see the current directory, but instead is expecting
> > everything to be under ~/.  I thought emacs grokked the PWD environment
> > variable.
> >
> > From my shell -
> >
> >     % echo $PWD
> >     /Users/mahan/src/PPP/ppp-master/pppd
> >
> > But inside my .emacs I have -
> >
> > (setq workingdir (getenv "PWD"))
> > message "PWD = '%s'" workingdir)
>
> There is  missing a ( at beginning of line? You should get an
> "unbalanced parantheses" message.
>
>
No, there is not, that was a cut-n-paste error.


> >
> > Which results in -
> >
> > PWD = ’nil’
> >
> > Unless I open using a Full pathname, it will not open the file
> > correctly.
>
> What file?
>

If I am in /Users/mahan/src/PPP/ppp-master/pppd and attempt to open
sys-linux.c, it opens an emacs window, but nothing is present.  If I look
at the buffers window -

.%* *Messages*              695 Messages
    sys-linux.c               0 C/*l             ~/sys-linux.c
    *scratch*               144 Lisp Interaction

It shows up as being in my home directory.


> >
> > Suggestions?
> >
> > Thanks,
> >
> > Patrick
>
>
> How did you invoke emacs? If you start it from some graphical MacOS
> environment, may PWD _is_ undefined (I know nothing about MacOS)? Did you
> cd into
> /Users/mahan/src/PPP/ppp-master/pppd in a shell and start emacs from
> the command line from there?
>
>
Thanks!  That was a good suggestion.  I was using the Mac OS X 'open'
command which is probably, as you suggested, not picking up the correct
environment, though oddly it is picking up the PATH correctly.

This was something I took from another user on a mailing list.

Dropping the 'open' and invoking Emacs directly fixes that issue!

Patrick


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

* Re: PWD is not seen by my emacs installation
       [not found]   ` <CAFDHx1Jk=jtHhLdThFUeFpfa=yGTXoKYuu0bADYAN-j-7FjSHw@mail.gmail.com>
@ 2023-08-09  0:59     ` tpeplt
  0 siblings, 0 replies; 12+ messages in thread
From: tpeplt @ 2023-08-09  0:59 UTC (permalink / raw)
  To: Patrick Mahan; +Cc: Help Gnu Emacs

Patrick Mahan <plmahan@gmail.com> writes:

>  >
>  > Suggestions?
>  >
>
>  1. View your *Messages* (type C-h e) to see if there are any error
>     messages during Emacs’s start-up that might be related to this.
>
> Nothing to indicate any errors.

You might try starting Emacs from your shell with: $ emacs -Q

- Once it has started, try the command ‘getenv’ by typing M-x getenv

- Respond to the "Get environment variable: " prompt with PWD

If the result is not nil, then it might indicate a problem in your Emacs
initialization file (~/.emacs or one of the many variants).  If the
result is nil, then you could try checking other environment variables
or simply display Emacs’s entire list of your environment that it knows
about by typing C-h v initial-environment

None of this shows where the problem is yet, but it could be that there
is a problem in your installed Emacs or in some Emacs Lisp code that you
are running.  You want to try to identify or eliminate one or the other
as the source of the problem.

>  
>  2. Read the Emacs manual on the environment (although there does not
>     appear to be any problem with your expressions other than a missing
>     leading parenthesis before ‘message’).  Type
>
>        M-: (info "(emacs) Environment")
>
> *SIGH* That was a cut-and-paste error, it is there (otherwise, I WOULD have errors on startup).
>

--



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

* Re: PWD is not seen by my emacs installation
  2023-08-08 21:21   ` Patrick Mahan
@ 2023-08-09  5:37     ` Rudolf Schlatte
  2023-08-09 20:21       ` Patrick Mahan
  0 siblings, 1 reply; 12+ messages in thread
From: Rudolf Schlatte @ 2023-08-09  5:37 UTC (permalink / raw)
  To: help-gnu-emacs

Patrick Mahan <plmahan@gmail.com> writes:
>> How did you invoke emacs? If you start it from some graphical MacOS
>> environment, may PWD _is_ undefined (I know nothing about MacOS)? Did you
>> cd into
>> /Users/mahan/src/PPP/ppp-master/pppd in a shell and start emacs from
>> the command line from there?
>>
>>
> Thanks!  That was a good suggestion.  I was using the Mac OS X 'open'
> command which is probably, as you suggested, not picking up the correct
> environment, though oddly it is picking up the PATH correctly.

In that case, you can write "open -a Emacs.app /path/to/somefile.txt"
and it will be opened by Emacs as expected.

Note that in Emacs, each buffer has its own "current directory", so
e.g. starting dired when in the "somefile.txt" buffer will display the
contents of "/path/to".




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

* Re: PWD is not seen by my emacs installation
  2023-08-09  5:37     ` Rudolf Schlatte
@ 2023-08-09 20:21       ` Patrick Mahan
  2023-08-22  1:14         ` David Masterson
  0 siblings, 1 reply; 12+ messages in thread
From: Patrick Mahan @ 2023-08-09 20:21 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: help-gnu-emacs

On Tue, Aug 8, 2023 at 10:38 PM Rudolf Schlatte <rudi@constantly.at> wrote:

> Patrick Mahan <plmahan@gmail.com> writes:
> >> How did you invoke emacs? If you start it from some graphical MacOS
> >> environment, may PWD _is_ undefined (I know nothing about MacOS)? Did
> you
> >> cd into
> >> /Users/mahan/src/PPP/ppp-master/pppd in a shell and start emacs from
> >> the command line from there?
> >>
> >>
> > Thanks!  That was a good suggestion.  I was using the Mac OS X 'open'
> > command which is probably, as you suggested, not picking up the correct
> > environment, though oddly it is picking up the PATH correctly.
>
> In that case, you can write "open -a Emacs.app /path/to/somefile.txt"
> and it will be opened by Emacs as expected.
>
> Note that in Emacs, each buffer has its own "current directory", so
> e.g. starting dired when in the "somefile.txt" buffer will display the
> contents of "/path/to".
>
>
Yes, that is what occurs, but my issue is the need to give the full path
(or even a relative path off of '~').  I just want to edit the file in the
local directory.  I do not want to have to say "open -a Emacs.app
$PWD/file.txt" just to open a local file.

I also tried using the --env option to the open command but it does not
seem to work.

Invoking it directly works correctly.

Thanks,

Patrick


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

* Re: PWD is not seen by my emacs installation
  2023-08-09 20:21       ` Patrick Mahan
@ 2023-08-22  1:14         ` David Masterson
  2023-08-22  4:24           ` Patrick Mahan
  0 siblings, 1 reply; 12+ messages in thread
From: David Masterson @ 2023-08-22  1:14 UTC (permalink / raw)
  To: Patrick Mahan; +Cc: Rudolf Schlatte, help-gnu-emacs

Patrick Mahan <plmahan@gmail.com> writes:

> Yes, that is what occurs, but my issue is the need to give the full path
> (or even a relative path off of '~').  I just want to edit the file in the
> local directory.  I do not want to have to say "open -a Emacs.app
> $PWD/file.txt" just to open a local file.
>
> I also tried using the --env option to the open command but it does not
> seem to work.
>
> Invoking it directly works correctly.

This sounds like the same problem of starting Emacs from an icon in many
window managers.  The standard icons often don't load your "profile",
but rather uses a default "slimmed down" profile.  Try this:

1. Start Emacs from the icon
2. Check your environment by either of these ways:
2a, 'M-x shell' and then 'env'
2b. 'C-h v process-environment'
3. Compare that environment with your "directly" environment
4. If $HOME is correct in #2 & #3, you can fix other key environment
variables using early-init.el (see 'Init File' in the Emacs infodocs).
5. Use 'setenv' in early-init.el to adjust your environment as needed.

-- 
David Masterson



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

* Re: PWD is not seen by my emacs installation
  2023-08-22  1:14         ` David Masterson
@ 2023-08-22  4:24           ` Patrick Mahan
  0 siblings, 0 replies; 12+ messages in thread
From: Patrick Mahan @ 2023-08-22  4:24 UTC (permalink / raw)
  To: David Masterson; +Cc: Rudolf Schlatte, help-gnu-emacs

Thanks, I'll check it out.

On Mon, Aug 21, 2023 at 6:14 PM David Masterson <dsmasterson@gmail.com>
wrote:

> Patrick Mahan <plmahan@gmail.com> writes:
>
> > Yes, that is what occurs, but my issue is the need to give the full path
> > (or even a relative path off of '~').  I just want to edit the file in
> the
> > local directory.  I do not want to have to say "open -a Emacs.app
> > $PWD/file.txt" just to open a local file.
> >
> > I also tried using the --env option to the open command but it does not
> > seem to work.
> >
> > Invoking it directly works correctly.
>
> This sounds like the same problem of starting Emacs from an icon in many
> window managers.  The standard icons often don't load your "profile",
> but rather uses a default "slimmed down" profile.  Try this:
>
> 1. Start Emacs from the icon
> 2. Check your environment by either of these ways:
> 2a, 'M-x shell' and then 'env'
> 2b. 'C-h v process-environment'
> 3. Compare that environment with your "directly" environment
> 4. If $HOME is correct in #2 & #3, you can fix other key environment
> variables using early-init.el (see 'Init File' in the Emacs infodocs).
> 5. Use 'setenv' in early-init.el to adjust your environment as needed.
>
> --
> David Masterson
>


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

* Re: PWD is not seen by my emacs installation
  2023-08-08  1:58 PWD is not seen by my emacs installation Patrick Mahan
  2023-08-08 12:44 ` tpeplt
  2023-08-08 19:07 ` stefan-husmann
@ 2023-08-30 22:29 ` Rudolf Adamkovič
  2023-08-30 23:43   ` Patrick Mahan
  2023-09-03 15:27   ` Rudolf Schlatte
  2 siblings, 2 replies; 12+ messages in thread
From: Rudolf Adamkovič @ 2023-08-30 22:29 UTC (permalink / raw)
  To: Patrick Mahan, Help Gnu Emacs

Patrick Mahan <plmahan@gmail.com> writes:

> Hardware -
>
>    Macbook Pro 14" (Apple M1 Pro)
>    Mac OS 13.1 (Ventura)

I am on the same system, with the same
problem, and I solved it as follows...

From my literate configuration file:

[...]

Copy the =$PATH=, =$MANPATH=, and =LC_ALL=
variables from the interactive login shell to
Emacs.  This is necessary on macOS, as its
GUI starts programs within a minimal
environment.

In practice, this fixes various problems,
such as the =*compilation*= buffer not
finding =emacs=, =fortune= not finding
=strfile=, =geiser-mode= not finding =guile=,
=emacs= not finding =gcc= for native
compilation, as well as, spurious =locale=
warnings.

#+BEGIN_SRC emacs-lisp :eval no :tangle ~/.emacs
(when (eq window-system 'ns)
  (defun shell-get-environment-variable+ (variable)
    "Return the value of VARIABLE from login shell."
    (shell-command-to-string
     (format "$SHELL --login -c 'echo -n $%s'" variable)))
  ;;
  ;; Set the path variable.
  (let* ((path "PATH")
         (path-value (shell-get-environment-variable+ path)))
    (setenv path path-value)
    (setq exec-path (split-string path-value path-separator)))
  ;;
  ;; Set the locale.
  (let* ((variable "LC_ALL")
         (variable-value (shell-get-environment-variable+ variable)))
    (setenv variable variable-value)))
#+END_SRC

P.S. 1: My code launches the login shell
twice instead of once, which is something to
improve.

P.S. 2: It would be useful to have a command
that does this in vanilla Emacs.

Rudy
-- 
"Programming reliably -- must be an activity
of an undeniably mathematical nature […] You
see, mathematics is about thinking, and doing
mathematics is always trying to think as well
as possible."  -- Edsger W. Dijkstra, 1981

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



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

* Re: PWD is not seen by my emacs installation
  2023-08-30 22:29 ` Rudolf Adamkovič
@ 2023-08-30 23:43   ` Patrick Mahan
  2023-09-03 15:27   ` Rudolf Schlatte
  1 sibling, 0 replies; 12+ messages in thread
From: Patrick Mahan @ 2023-08-30 23:43 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: Help Gnu Emacs

Thanks for sharing.

Patrick

On Wed, Aug 30, 2023 at 3:30 PM Rudolf Adamkovič <salutis@me.com> wrote:

> Patrick Mahan <plmahan@gmail.com> writes:
>
> > Hardware -
> >
> >    Macbook Pro 14" (Apple M1 Pro)
> >    Mac OS 13.1 (Ventura)
>
> I am on the same system, with the same
> problem, and I solved it as follows...
>
> From my literate configuration file:
>
> [...]
>
> Copy the =$PATH=, =$MANPATH=, and =LC_ALL=
> variables from the interactive login shell to
> Emacs.  This is necessary on macOS, as its
> GUI starts programs within a minimal
> environment.
>
> In practice, this fixes various problems,
> such as the =*compilation*= buffer not
> finding =emacs=, =fortune= not finding
> =strfile=, =geiser-mode= not finding =guile=,
> =emacs= not finding =gcc= for native
> compilation, as well as, spurious =locale=
> warnings.
>
> #+BEGIN_SRC emacs-lisp :eval no :tangle ~/.emacs
> (when (eq window-system 'ns)
>   (defun shell-get-environment-variable+ (variable)
>     "Return the value of VARIABLE from login shell."
>     (shell-command-to-string
>      (format "$SHELL --login -c 'echo -n $%s'" variable)))
>   ;;
>   ;; Set the path variable.
>   (let* ((path "PATH")
>          (path-value (shell-get-environment-variable+ path)))
>     (setenv path path-value)
>     (setq exec-path (split-string path-value path-separator)))
>   ;;
>   ;; Set the locale.
>   (let* ((variable "LC_ALL")
>          (variable-value (shell-get-environment-variable+ variable)))
>     (setenv variable variable-value)))
> #+END_SRC
>
> P.S. 1: My code launches the login shell
> twice instead of once, which is something to
> improve.
>
> P.S. 2: It would be useful to have a command
> that does this in vanilla Emacs.
>
> Rudy
> --
> "Programming reliably -- must be an activity
> of an undeniably mathematical nature […] You
> see, mathematics is about thinking, and doing
> mathematics is always trying to think as well
> as possible."  -- Edsger W. Dijkstra, 1981
>
> Rudolf Adamkovič <salutis@me.com> [he/him]
> Studenohorská 25
> 84103 Bratislava
> Slovakia
>


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

* Re: PWD is not seen by my emacs installation
  2023-08-30 22:29 ` Rudolf Adamkovič
  2023-08-30 23:43   ` Patrick Mahan
@ 2023-09-03 15:27   ` Rudolf Schlatte
  1 sibling, 0 replies; 12+ messages in thread
From: Rudolf Schlatte @ 2023-09-03 15:27 UTC (permalink / raw)
  To: help-gnu-emacs

Rudolf Adamkovič <salutis@me.com> writes:

>
> From my literate configuration file:
>
> [...]
>
> Copy the =$PATH=, =$MANPATH=, and =LC_ALL=
> variables from the interactive login shell to
> Emacs.  This is necessary on macOS, as its
> GUI starts programs within a minimal
> environment.

See also the package `exec-path-from-shell'
(https://github.com/purcell/exec-path-from-shell), which does this for a
customizable list of variables (`exec-path-from-shell-variables').




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

end of thread, other threads:[~2023-09-03 15:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-08  1:58 PWD is not seen by my emacs installation Patrick Mahan
2023-08-08 12:44 ` tpeplt
     [not found]   ` <CAFDHx1Jk=jtHhLdThFUeFpfa=yGTXoKYuu0bADYAN-j-7FjSHw@mail.gmail.com>
2023-08-09  0:59     ` tpeplt
2023-08-08 19:07 ` stefan-husmann
2023-08-08 21:21   ` Patrick Mahan
2023-08-09  5:37     ` Rudolf Schlatte
2023-08-09 20:21       ` Patrick Mahan
2023-08-22  1:14         ` David Masterson
2023-08-22  4:24           ` Patrick Mahan
2023-08-30 22:29 ` Rudolf Adamkovič
2023-08-30 23:43   ` Patrick Mahan
2023-09-03 15:27   ` Rudolf Schlatte

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).