purcell / exec-path-from-shell

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

TERM does not seems to work correctly #110

Closed jvillasante closed 2 years ago

jvillasante commented 2 years ago

Hello, I'm having an issue with this great package which I configure like this:

(progn
  (require 'exec-path-from-shell)
  (dolist (var '("TERM" "LANG"))
    (add-to-list 'exec-path-from-shell-variables var))

  (when (daemonp)
    (add-hook
     'emacs-startup-hook
     (lambda ()
       (exec-path-from-shell-initialize)))))

The problem is that TERM won't get set until I later on call exec-path-from-shell-initialze again, other variables like PATH or LANG do get set correctly. Here's an ielm session showing this:

*** Welcome to IELM ***  Type (describe-mode) or press C-h m for help.
ELISP> (getenv "TERM")
"dumb"
ELISP> (exec-path-from-shell-initialize)
(("MANPATH")
 ("PATH" . "/home/jvillasante/anaconda3/bin:/home/jvillasante/anaconda3/condabin:/home/jvillasante/.tmuxifier/bin:/home/jvillasante/.cargo/bin:/home/jvillasante/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin")
 ("TERM" . "xterm-256color")
 ("LANG" . "en_US.UTF-8"))

ELISP> (getenv "TERM")
"xterm-256color"
ELISP> 

So, after initialization TERM is still "dumb" and I need to run exec-path-from-shell-initialize again for it to be set, I'm I doing something wrong?

jvillasante commented 2 years ago

It looks like it has to be with running emacs as daemon, this work but I'm not sure if the call to exec-path-from-shell-initialize is needed for every frame.

(progn
  (require 'exec-path-from-shell)
  (dolist (var '("TERM" "SSH_AUTH_SOCK" "SSH_AGENT_PID" "GPG_AGENT_INFO" "LANG" "LC_CTYPE" "NIX_SSL_CERT_FILE" "NIX_PATH"))
    (add-to-list 'exec-path-from-shell-variables var))

  (if (daemonp)
      (add-hook 'after-make-frame-functions
                (lambda (frame)
                  (with-selected-frame frame
                    (exec-path-from-shell-initialize))))
    (exec-path-from-shell-initialize)))
jvillasante commented 2 years ago

Ok, I've read a little bit about this and was able to find the

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

Emacs itself sets TERM to "dumb" and it looks like it is the right setting.