Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance the eshell with its built-in ansi-color support #16377

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions layers/+tools/shell/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ Some advanced configuration is setup for =eshell= in this layer:
- add support for auto-completion via =company= (when the =auto-completion=
layer is installed)
- pressing ~i~ in normal state will automatically jump to the prompt
- color support with package ~xterm-color~ on Emacs28 and before
- color support with built-in ~ansi-color~ by default on Emacs29 and later

* Key bindings

Expand Down
40 changes: 19 additions & 21 deletions layers/+tools/shell/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(shell :location built-in)
shell-pop
(term :location built-in)
xterm-color
(xterm-color :toggle (version< emacs-version "29.0.50"))
terminal-here
vi-tilde-fringe
window-purpose
Expand Down Expand Up @@ -101,26 +101,8 @@
(add-hook 'eshell-mode-hook 'spacemacs/disable-hl-line-mode)
(with-eval-after-load 'centered-cursor-mode
(add-hook 'eshell-mode-hook 'spacemacs//inhibit-global-centered-cursor-mode))
:config

;; Work around bug in eshell's preoutput-filter code.
;; Eshell doesn't call preoutput-filter functions in the context of the eshell
;; buffer. This breaks the xterm color filtering when the eshell buffer is updated
;; when it's not currently focused.
;; To remove if/when fixed upstream.
(defun eshell-output-filter@spacemacs-with-buffer (fn process string)
(let ((proc-buf (if process (process-buffer process)
(current-buffer))))
(when proc-buf
(with-current-buffer proc-buf
(funcall fn process string)))))
(advice-add
#'eshell-output-filter
:around
#'eshell-output-filter@spacemacs-with-buffer)

(require 'esh-opt)

:config
;; quick commands
(defalias 'eshell/e 'find-file-other-window)
(defalias 'eshell/d 'dired)
Expand Down Expand Up @@ -314,7 +296,23 @@
(add-hook 'comint-preoutput-filter-functions 'xterm-color-filter)
(setq comint-output-filter-functions
(remove 'ansi-color-process-output comint-output-filter-functions))
(add-hook 'eshell-mode-hook 'spacemacs/init-eshell-xterm-color)))
(add-hook 'eshell-mode-hook 'spacemacs/init-eshell-xterm-color)
(with-eval-after-load 'eshell
;; Work around bug in eshell's preoutput-filter code.
;; Eshell doesn't call preoutput-filter functions in the context of the eshell
;; buffer. This breaks the xterm color filtering when the eshell buffer is updated
;; when it's not currently focused.
;; To remove if/when fixed upstream.
(defun eshell-output-filter@spacemacs-with-buffer (fn process string)
(let ((proc-buf (if process (process-buffer process)
(current-buffer))))
(when proc-buf
(with-current-buffer proc-buf
(funcall fn process string)))))
(advice-add
#'eshell-output-filter
:around
#'eshell-output-filter@spacemacs-with-buffer))))

(defun shell/init-terminal-here ()
(use-package terminal-here
Expand Down
Loading