all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Creating and accessing environmental variables
@ 2024-12-08 18:27 the_wurfkreuz via Emacs development discussions.
  2024-12-08 19:51 ` Ship Mints
  0 siblings, 1 reply; 5+ messages in thread
From: the_wurfkreuz via Emacs development discussions. @ 2024-12-08 18:27 UTC (permalink / raw)
  To: emacs-devel@gnu.org

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

Is it possible to set environment variables and access them immediately without reloading the Emacs configuration (like using the load-file function)?
For instance, when I evaluate this code to set the PATH variable:

(let ((paths '("/some/path"
"/some/path/2")))
;; (setq exec-path (append paths exec-path))
(setenv "PATH" (concat (string-join paths ":")
":"
(getenv "PATH"))))
And then try to launch eshell in the current Emacs session, I find that the new values aren't appended. The only way to set them is to put the code into a config file and reload it through (load-file "~/.emacs.d/init.el").

[-- Attachment #2: Type: text/html, Size: 1605 bytes --]

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

* Re: Creating and accessing environmental variables
  2024-12-08 18:27 Creating and accessing environmental variables the_wurfkreuz via Emacs development discussions.
@ 2024-12-08 19:51 ` Ship Mints
  2024-12-08 20:14   ` Ship Mints
  0 siblings, 1 reply; 5+ messages in thread
From: Ship Mints @ 2024-12-08 19:51 UTC (permalink / raw)
  To: the_wurfkreuz; +Cc: emacs-devel@gnu.org

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

Couple of things. First, you should not be concatenating paths like you
showed. Do the following instead and it will be cross platform and more
"correct":

  (file-name-concat "/tmp/foo/bar" (getenv "PATH"))

Second, a question. After you setenv your PATH, in eshell, what does "echo
$PATH" show?

On Sun, Dec 8, 2024 at 1:51 PM the_wurfkreuz via Emacs development
discussions. <emacs-devel@gnu.org> wrote:

> Is it possible to set environment variables and access them immediately
> without reloading the Emacs configuration (like using the load-file
> function)?
>
> For instance, when I evaluate this code to set the PATH variable:
>
> (let ((paths '("/some/path"
>               "/some/path/2")))
>   ;; (setq exec-path (append paths exec-path))
>   (setenv "PATH" (concat (string-join paths ":")
>                         ":"
>                         (getenv "PATH"))))
>
> And then try to launch eshell in the current Emacs session, I find that
> the new values aren't appended. The only way to set them is to put the code
> into a config file and reload it through (load-file "~/.emacs.d/init.el").
>

[-- Attachment #2: Type: text/html, Size: 2525 bytes --]

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

* Re: Creating and accessing environmental variables
  2024-12-08 19:51 ` Ship Mints
@ 2024-12-08 20:14   ` Ship Mints
  2024-12-08 20:23     ` Ship Mints
  0 siblings, 1 reply; 5+ messages in thread
From: Ship Mints @ 2024-12-08 20:14 UTC (permalink / raw)
  To: the_wurfkreuz; +Cc: emacs-devel@gnu.org

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

Sheesh, I need more coffee... More like this since it's an OS path:

  (concat "/tmp/foo/bar" path-separator (getenv "PATH"))

On Sun, Dec 8, 2024 at 2:51 PM Ship Mints <shipmints@gmail.com> wrote:

> Couple of things. First, you should not be concatenating paths like you
> showed. Do the following instead and it will be cross platform and more
> "correct":
>
>   (file-name-concat "/tmp/foo/bar" (getenv "PATH"))
>
> Second, a question. After you setenv your PATH, in eshell, what does "echo
> $PATH" show?
>
> On Sun, Dec 8, 2024 at 1:51 PM the_wurfkreuz via Emacs development
> discussions. <emacs-devel@gnu.org> wrote:
>
>> Is it possible to set environment variables and access them immediately
>> without reloading the Emacs configuration (like using the load-file
>> function)?
>>
>> For instance, when I evaluate this code to set the PATH variable:
>>
>> (let ((paths '("/some/path"
>>               "/some/path/2")))
>>   ;; (setq exec-path (append paths exec-path))
>>   (setenv "PATH" (concat (string-join paths ":")
>>                         ":"
>>                         (getenv "PATH"))))
>>
>> And then try to launch eshell in the current Emacs session, I find that
>> the new values aren't appended. The only way to set them is to put the code
>> into a config file and reload it through (load-file "~/.emacs.d/init.el").
>>
>

[-- Attachment #2: Type: text/html, Size: 3237 bytes --]

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

* Re: Creating and accessing environmental variables
  2024-12-08 20:14   ` Ship Mints
@ 2024-12-08 20:23     ` Ship Mints
  2024-12-08 20:33       ` the_wurfkreuz via Emacs development discussions.
  0 siblings, 1 reply; 5+ messages in thread
From: Ship Mints @ 2024-12-08 20:23 UTC (permalink / raw)
  To: the_wurfkreuz; +Cc: emacs-devel@gnu.org

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

Triple coffee... I don't use eshell much, so need to add that you may want
to use "addpath" in an eshell instance which you can verify running
eshell-get-path in eshell.

On Sun, Dec 8, 2024 at 3:14 PM Ship Mints <shipmints@gmail.com> wrote:

> Sheesh, I need more coffee... More like this since it's an OS path:
>
>   (concat "/tmp/foo/bar" path-separator (getenv "PATH"))
>
> On Sun, Dec 8, 2024 at 2:51 PM Ship Mints <shipmints@gmail.com> wrote:
>
>> Couple of things. First, you should not be concatenating paths like you
>> showed. Do the following instead and it will be cross platform and more
>> "correct":
>>
>>   (file-name-concat "/tmp/foo/bar" (getenv "PATH"))
>>
>> Second, a question. After you setenv your PATH, in eshell, what does
>> "echo $PATH" show?
>>
>> On Sun, Dec 8, 2024 at 1:51 PM the_wurfkreuz via Emacs development
>> discussions. <emacs-devel@gnu.org> wrote:
>>
>>> Is it possible to set environment variables and access them immediately
>>> without reloading the Emacs configuration (like using the load-file
>>> function)?
>>>
>>> For instance, when I evaluate this code to set the PATH variable:
>>>
>>> (let ((paths '("/some/path"
>>>               "/some/path/2")))
>>>   ;; (setq exec-path (append paths exec-path))
>>>   (setenv "PATH" (concat (string-join paths ":")
>>>                         ":"
>>>                         (getenv "PATH"))))
>>>
>>> And then try to launch eshell in the current Emacs session, I find that
>>> the new values aren't appended. The only way to set them is to put the code
>>> into a config file and reload it through (load-file "~/.emacs.d/init.el").
>>>
>>

[-- Attachment #2: Type: text/html, Size: 3856 bytes --]

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

* Re: Creating and accessing environmental variables
  2024-12-08 20:23     ` Ship Mints
@ 2024-12-08 20:33       ` the_wurfkreuz via Emacs development discussions.
  0 siblings, 0 replies; 5+ messages in thread
From: the_wurfkreuz via Emacs development discussions. @ 2024-12-08 20:33 UTC (permalink / raw)
  To: Ship Mints; +Cc: emacs-devel@gnu.org

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

Yes, only after using addpath was eshell/which able to find executables in the added paths.
On Sunday, December 8th, 2024 at 23:23, Ship Mints <shipmints@gmail.com> wrote:

> Triple coffee... I don't use eshell much, so need to add that you may want to use "addpath" in an eshell instance which you can verify running eshell-get-path in eshell.
>
> On Sun, Dec 8, 2024 at 3:14 PM Ship Mints <shipmints@gmail.com> wrote:
>
>> Sheesh, I need more coffee... More like this since it's an OS path:
>>
>> (concat "/tmp/foo/bar" path-separator (getenv "PATH"))
>>
>> On Sun, Dec 8, 2024 at 2:51 PM Ship Mints <shipmints@gmail.com> wrote:
>>
>>> Couple of things. First, you should not be concatenating paths like you showed. Do the following instead and it will be cross platform and more "correct":
>>>
>>> (file-name-concat "/tmp/foo/bar" (getenv "PATH"))
>>>
>>> Second, a question. After you setenv your PATH, in eshell, what does "echo $PATH" show?
>>>
>>> On Sun, Dec 8, 2024 at 1:51 PM the_wurfkreuz via Emacs development discussions. <emacs-devel@gnu.org> wrote:
>>>
>>>> Is it possible to set environment variables and access them immediately without reloading the Emacs configuration (like using the load-file function)?
>>>> For instance, when I evaluate this code to set the PATH variable:
>>>>
>>>> (let ((paths '("/some/path"
>>>> "/some/path/2")))
>>>> ;; (setq exec-path (append paths exec-path))
>>>> (setenv "PATH" (concat (string-join paths ":")
>>>> ":"
>>>> (getenv "PATH"))))
>>>> And then try to launch eshell in the current Emacs session, I find that the new values aren't appended. The only way to set them is to put the code into a config file and reload it through (load-file "~/.emacs.d/init.el").

[-- Attachment #2: Type: text/html, Size: 4185 bytes --]

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

end of thread, other threads:[~2024-12-08 20:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-08 18:27 Creating and accessing environmental variables the_wurfkreuz via Emacs development discussions.
2024-12-08 19:51 ` Ship Mints
2024-12-08 20:14   ` Ship Mints
2024-12-08 20:23     ` Ship Mints
2024-12-08 20:33       ` the_wurfkreuz via Emacs development discussions.

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.