purcell / exec-path-from-shell

Make Emacs use the $PATH set up by the user's shell
Other
1.41k stars 81 forks source link

`gnome-terminal` fails to be launched from Emacs after initializing package #96

Closed arthurcgusmao closed 4 years ago

arthurcgusmao commented 4 years ago

Issue

After running (exec-path-from-shell-initialize), trying to launch gnome-terminal from Emacs (e.g., M-! gnome-terminal RET) fails, with following output:

Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Error spawning command line 'dbus-launch --autolaunch=246be9cd5eaf4c11b9405431fcfa4d0d --binary-syntax --close-stderr': Child process exited with code 1

Emacs version: GNU Emacs 27.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 2.24.30) of 2020-02-22

Context

I'm used to launching instances of a terminal emulator (gnome-terminal) as an Emacs subprocess, to quickly execute commands on the directory I'm currently in, by running

(start-process "" nil "x-terminal-emulator"
                     (concat "--working-directory=" default-directory) )

, which I put inside a function and bind to a keybinding.

After using the package (specifically, after running (exec-path-from-shell-initialize)), the process is created but no terminal window is launched on my OS (Ubuntu).

Investigating it further, it seems that after (exec-path-from-shell-initialize), trying to launch x-terminal-emulator (which points to gnome-terminal) from Emacs fails, giving the output discussed in previous section.

Any idea on what should be going on? Any ideas or solutions are welcome.

PS: Thank you for the good work :)

purcell commented 4 years ago

I think in your position I would note the values of environment variables in Emacs before and after running exec-path-from-shell-initialize, and see what's different. You can do this by inspecting the process-environment variable. Probably there is a change that affects the x-terminal-emulator script.

arthurcgusmao commented 4 years ago

Thank you for the helpful tip @purcell. Indeed, changing the values solved the issue; the culprit was /home/user/.miniconda3/bin in the PATH variable.

My particular solution was to add just the path that I needed manually instead of all paths:

(defun add-to-env-path (path)
  "Add PATH (first position) to the PATH environment variable"
  (setenv "PATH" (concat (expand-file-name path)
                         path-separator (getenv "PATH"))))

(add-to-env-path "~/.local/bin")
purcell commented 4 years ago

Great, glad you figured it out!