26 votes
Accepted

Using conda environments in emacs

I'd suggest using pyvenv library, it provides a neat interface to selecting a virtual env among several alternatives updating interpreter and library paths. You will need to alter WORKON_HOME variable ...
immerrr's user avatar
  • 564
13 votes

Emacs can't find Node when Node was installed using NVM

Best solution: Install exec-path-from-shell. From the documentation, after calling (package-initialize), add the following to your .emacs file: (when (memq window-system '(mac ns x)) (exec-path-...
user2245766's user avatar
9 votes
Accepted

Why does emacs (getenv "TERM") return incorrect data?

Quoting startup.el: ;; Subprocesses of Emacs do not have direct access to the terminal, so ;; unless told otherwise they should only assume a dumb terminal. ;; We are careful to do it late (after ...
phils's user avatar
  • 50.5k
8 votes

Using conda environments in emacs

I have recently incorporated Anaconda into my python development and was having similar problems setting up Emacs + flycheck + linters. This answer got me up and running, but I've modified it, since ...
Jim Parker's user avatar
8 votes
Accepted

How can I get buffer-local environment variables via .dir-locals?

Both the buffer-local and the global variable are initially pointing to the same cons cell / list. If setenv pushes a new value to the front of the list, that would only be reflected in the local ...
phils's user avatar
  • 50.5k
8 votes
Accepted

How to get the PATH from the SHELL

No, you don’t want to use -i because you’re not launching an interactive shell. That is, this shell will not be connected to a terminal that the user can type in. It is instead going to be connected ...
db48x's user avatar
  • 17.7k
6 votes
Accepted

How can I get some environment variables into init.el to construct file paths?

(substitute-in-file-name "~/.emacs.d/${USER}_${HOST}_custom.el") Should give you what you want. substitute-in-file-name is a built-in function in C source code. (substitute-in-file-name FILENAME)...
wvxvw's user avatar
  • 11.3k
6 votes

How to check whether ImageMagick is setup correctly on macOS?

According to the doc https://www.gnu.org/software/emacs/manual/html_node/elisp/ImageMagick-Images.html you can check for imagemagick support with (image-type-available-p 'imagemagick) you could use ...
junnu's user avatar
  • 780
5 votes
Accepted

Set environment variables for spawned subprocesses

setenv-internal and setenv change the list stored in process-environment (as local or special variable) by side-effects. It does not help if you assign the list (pointer) to a local variable process-...
Tobias's user avatar
  • 33.1k
5 votes

How to make terminal/shell spawned inside Emacs running on a Mac inherit the environment variables of the native terminal?

Like Mark said, Terminal and iTerm 2 invoke shells as login shells by default, so that Bash reads ~/.bash_profile but not ~/.bashrc, but M-x shell and M-x term invoke shells as non-login shells, so ...
nisetama's user avatar
  • 241
5 votes

Package `exec-path-from-shell` isn't setting PATH variables from `.zshenv` on MacOS

You should remove :defer f, because you don't want exec-path-from-shell to be defer loaded and you are going to use function from it when Emacs starts. Try something like the following (use-package ...
xuchunyang's user avatar
  • 14.5k
5 votes

What kind of environment variables does Emacs expect to find in .profile, .bash_profile etc?

By default, Emacs does not look at your shell config files. The behaviour you are seeing is on account of a third-party elisp package named exec-path-from-shell which you have installed. Maybe ...
phils's user avatar
  • 50.5k
5 votes
Accepted

What kind of environment variables does Emacs expect to find in .profile, .bash_profile etc?

This is a feature of the emacs package exec-path-from-shell, https://github.com/purcell/exec-path-from-shell. The message is trying to do you a favour in warning about PATH variable definitions in ...
Heikki's user avatar
  • 3,066
5 votes
Accepted

Why is getenv not working to read an environment variable in my macOS machine?

Because you don’t understand environment variables (you’re not alone here, this QA forum is littered with duplicate questions from people who don’t understand them). Environment variables are ...
db48x's user avatar
  • 17.7k
4 votes
Accepted

How to determine the initial current directory when emacs is run from command line?

AFAICT, Emacs does not save this info in a standard place. Håkon's solution might work for you, but that completely depends on the program that launches Emacs: some will put the directory in $PWD, ...
Stefan's user avatar
  • 26.3k
4 votes
Accepted

emacs daemon and ssh agent forwarding

Both return the same value when getenv is called on SSH_AUTH_SOCK from within an emacs client. That looks unlikely. One would return ~/.ssh/ssh_auth_sock and the other would return /path/to/HOME/....
phils's user avatar
  • 50.5k
4 votes
Accepted

Interpolate environment variables in string

I think you're looking for the function substitute-env-vars: substitute-env-vars is a compiled Lisp function in ‘env.el’. (substitute-env-vars STRING &optional WHEN-UNDEFINED) Substitute ...
Basil's user avatar
  • 12.3k
3 votes

How can I get some environment variables into init.el to construct file paths?

Try this: (setq custom-file (format "~/.emacs.d/%s_%s_custom.el" user-login-name (getenv "HOST"))) (when (file-exists-p custom-file) (load custom-file))
justbur's user avatar
  • 1,510
3 votes

Set environment variables for spawned subprocesses

Since Emacs 28.1 you can use the with-environment-variables macro. Example: (with-environment-variables (("DESKTOP_SESSION" "TEST_VALUE")) (shell-command "echo $...
flonic's user avatar
  • 41
3 votes

How to make shell-command run using shell profile and current directory hooks (ex. direnv)

nowadays you would likely want to use https://github.com/wbolster/emacs-direnv it works similar to the hook that direnv installs in your shell. the emacs environment is updated on request (or ...
wouter bolsterlee's user avatar
3 votes

UnicodeEncodeError in inferior python under windows

The solution is to just set the same environment variable to the same value as in your question. How that is done I was reminded of by an answer to a previous, similar question – which I asked myself, ...
Anaphory's user avatar
  • 240
3 votes
Accepted

How can I use 'emacsclient' as $PAGER in eshell with pipe? or any better PAGER which works well with eshell?

One option would be to disable the PAGER entirely: (setenv "PAGER" "") This dumps all output directly to the eshell buffer, so you can use normal Emacs navigation commands to navigate the output. ...
Scott Weldon's user avatar
  • 2,695
3 votes
Accepted

Run an external program with customized environment/options in current buffer

See C-hv process-environment List of overridden environment variables for subprocesses to inherit. Each element should be a string of the form ENVVARNAME=VALUE. Entries in this list take ...
phils's user avatar
  • 50.5k
3 votes

Function `cd` not working correctly in conjunction with `tramp` and `compile`

Your command cd /ssh:desktop:/home/user/project/Release && make will be given to a shell on the remote machine. This doesn't know any Tramp syntax, and it runs already on the proper host. So ...
Michael Albinus's user avatar
3 votes

Change $PATH once emacs is running

Emacs initialises C-hv exec-path based on PATH at start-up, and finds executables based upon that. This doesn't affect the LaTeX distro used by emacs when I call the function tex-file. Try this: (...
phils's user avatar
  • 50.5k
3 votes

Change $PATH once emacs is running

Using the emacs function setenv is a way to modify the environment of the running emacs process. For your particular use case, you'd want to evaluate: (setenv PATH "modified-path-variable") ...
einfeyn496's user avatar
3 votes
Accepted

Running a program from elisp that runs `emacsclient` set on `$EDITOR`

You're looking for the with-editor library (which is what @Lindydancer is alluding to in the comment about Magit). https://elpa.nongnu.org/nongnu/with-editor.html It provides the commands with-editor-...
phils's user avatar
  • 50.5k
3 votes
Accepted

Closure does not capture variable

You don't have a closure unless your file has set lexical-binding: t as a file-local variable. Without that, everything is using dynamic binding (in which case in your example your variable is indeed ...
phils's user avatar
  • 50.5k
2 votes
Accepted

Separate Environments for each emacsclient

You'll want to look at the environment frame parameter, which the server.el code sets up whenever a frame is created for a particular client: (frame-parameter nil 'environment) This should then hold ...
Stefan's user avatar
  • 26.3k
2 votes
Accepted

How can Emacs set an environment/shell variable in a subordinate shell?

After (re)reading the code of the shell function, here's what I'd do: (advice-add 'make-comint-in-buffer :around #'my-enable-auto-save-in-shell) (defun my-enable-auto-save-in-shell (...
Stefan's user avatar
  • 26.3k

Only top scored, non community-wiki answers of a minimum length are eligible