20

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 (it defaults to $HOME/.virtualenvs used by virtualenvwrapper). (setenv "WORKON_HOME" "/Users/Pablo/anaconda/envs") (pyvenv-mode 1) After that choose the ...


7

exec-path-from-shell provides the exec-path-from-shell-copy-env command, which lets you copy the value of environment variables to Emacs sessions. For instance, M-x exec-path-from-shell-copy-env RET FOO sets the value of $FOO in Emacs as well. Note that exec-path-from-shell-copy-env spawns a new shell to extract the value of the environment variable. ...


5

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 spacemacs installs this by default. This will probably help: M-x finder-commentary RET exec-path-from-shell RET


5

This question has been already answered by rekado (thanks!) (as a reply to another more general question about eshell): You can configure TRAMP to respect the PATH variable on the remote machine (for remote eshell sessions) by adding 'tramp-own-remote-path to the list 'tramp-remote-path: (add-to-list 'tramp-remote-path 'tramp-own-remote-path) ...


5

As a workaround, the following can be used (Linux, Bash): First run printenv -0 > env.txt from the Bash terminal window, Then from within Emacs, run (defun my-update-env () (interactive) (let ((str (with-temp-buffer (insert-file-contents "env.txt") (buffer-string))) lst) (setq lst (split-string str "\000")) (...


5

I recently started using emacs outside of the terminal which was causing me some PATH issues. I had tried setting it by adding (getenv "PATH") to my exec-path, among other things that ultimately never worked. I ended up installing the exec-path-from-shell package via melpa. It works by using your $SHELL environment variable to ask your shell to print out ...


5

Running eval "$(direnv hook $0)" defines a function that hooks into $PROMPT_COMMAND, which is never called when bash is run as bash -ic because there is no prompt. You can change the line: eval "$(direnv hook $0)" to: eval "$(direnv hook $0)" && _direnv_hook to explicitly call the hook function. Edit: Just realized rekado gave a very similar ...


5

This doesn't seem to be a problem with Emacs but with bash. shell-command just executes call-process on the shell and passes arguments. I tried this on a regular shell: bash -ic "cd ~/code/foo && echo $PATH" ~/.bashrc is sourced, but the direnv hook is not run. When direnv hook bash is executed, a function _direnv_hook is output and prepended to ...


5

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 term-setup-hook), although the ;; new multi-tty code does not use $TERM any more there anyway. (setenv "TERM" "dumb") If Emacs didn't set TERM=dumb then every ...


4

Thanks to Rekado and Erik for pointing out how the direnv hook works by using $PROMPT_COMMAND. Since shell-command doesn't use a prompt, this wasn't getting executed. While Erik's answer works in my example of calling a shell command with M-! with default-directory set, it wouldn't work in the following example: (let ((default-directory "~/code/")) (...


4

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 configuration files that are not read by non-interactive shells. Many Emacs commands use command line programs to do the real work. The package reads your PATH ...


4

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, but others won't (so you may get a valid $PWD, or no $PWD, or a $PWD that's not truthful). Other solutions would be: If it's for your own personal use, just add ...


4

(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) Substitute environment variables referred to in FILENAME. $FOO where FOO is an environment variable name means to substitute the value of that variable. ...


4

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-environment. You still have only a single list for the process-environment which is just bound to two variables -- the global variable process-environment and ...


3

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 list value (the global value would effectively point to the cdr of the local value) in which case your code should work as desired; however if setenv is modifying ...


3

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 that Bash reads ~/.bashrc but not ~/.bash_profile. Either add . ~/.bash_profile to ~/.bashrc and keep using ~/.bash_profile as your Bash configuration file, or ...


3

I used to use this: function export-emacs { if [ "$(emacsclient -e t)" != 't' ]; then return 1 fi for name in "${@}"; do value=$(eval echo \"\$${name}\") emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null done } Lets you export a named variable, E.G: export EDITOR=vim export-emacs EDITOR


3

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. You can even disable it for an individual command by running the command as: PAGER="" <command>


3

Given the actual title here "How to make terminal/shell spawned inside Emacs running on a Mac inherit the environment variables of the native terminal?" you can't as Emacs will not have the Terminal.app as a super process at any level so Emacs cannot inherit anything form the shell in Terminal.app. You have to make the environment the same by sourcing the ...


3

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/.ssh/ssh_auth_sock, no? Have you tested whether SSH_AUTH_SOCK can actually contain ~ as a substitute for your HOME directory? Usually that would be expanded by a ...


2

No, You can't use a remote virtual environment with emacs with elpy as of now. Here is jorgenschaefer the author of elpy) comments on this I'm afraid that won't work. Tramp does a lot of magic with Emacs internals to do what it does, but it breaks in interesting ways if you try to tweak it too far. Elpy does that, because it runs so many different ...


2

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 a list of strings, where some of those strings will be like "SSH_CLIENT=IP PORT1 PORT2".


2

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 environment variables referred to in STRING. ‘$FOO’ where FOO is an environment variable name means to substitute the value of that variable. The variable name ...


2

Extending Realraptor's comment with the answer here: .bash_profile or .bashrc for shell in emacs? Stick TERM=xterm-256color into your .bashrc, and for good measure, this in .emacs: (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) (add-to-list 'comint-output-filter-functions 'ansi-color-process-output) (autoload 'ansi-color-for-comint-mode-on "...


2

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


2

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, but had forgotten about: It's as simple as adding (setenv "PYTHONIOENCODING" "UTF-8") to your emacs startup file.


2

Load pyvenv first and then activate env. Add this to your init file. (require 'pyvenv) (pyvenv-activate "~/.virtualenvs/exp/") If you are using virtualenvwrapper, you can use pyvenv-workon (require 'pyvenv) (pyvenv-workon "exp") If you load elpy first, it will automatically load pyvenv. You don't need to do (require 'pyvenv).


2

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 exec-path-from-shell :ensure t :if (memq window-system '(mac ns x)) :config (setq exec-path-from-shell-variables '("PATH" "GOPATH")) (exec-path-from-...


2

The "let binding" way is the following (notice that contrary to Tobias's answer, this does not involve any copying or "set"ting): (let ((process-environment (cons "HOME" (cons (concat "OLDHOME=" (getenv "HOME")) process-environment)))) (start-process "proc" (current-buffer) ...))


2

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 emacs-plus (https://github.com/d12frosted/homebrew-emacs-plus) which supports imagemagick by default brew tap d12frosted/emacs-plus brew install emacs-plus --...


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