I am facing a strange behavior regarding the implementation of color for shell outputs when using eshell. This is the content of my .emacs:
(require 'xterm-color)
(require 'eshell)
(add-hook 'eshell-before-prompt-hook
(lambda ()
(setq xterm-color-preserve-properties t)))
(add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter)
(setq eshell-output-filter-functions (remove 'eshell-handle-ansi-color eshell-output-filter-functions))
(setenv "TERM" "xterm-256color")
Strangely enough, eshell does not correctly show the colors on outputs (of git, or pytest for example) after emacs is initialized. However it does not raise any errors and, after it has been initialized, I evaluate this section of my init file with C-x C-e and, after I do that and restart eshell, it works fine as I expected.
I don't understand why it would work only if executed after emacs is initialized but would not have the expected effect on .emacs.
I do have the line (setq initial-buffer-choice 'eshell) on my .emacs, but only after the section above.
Any insight on why that might be happening would be helpful. Thank you,
Edit 1
I narrowed down the problem to the setenv
statement and the initial-buffer-choice
. For some reason, when I have the initial-buffer-choice
uncommented, the TERM
variable is set to dumb
. On the other hand, if I comment initial-buffer-choice
and open eshell after startup, then everything works as expected.
I tried to add the setenv
execution as a hook to eshell-mode and to emacs-startup, to see if I could force its execution at some other point during startup, but nothing really worked.