Skip to content

Commit

Permalink
Enhance the eshell with its built-in ansi-color support
Browse files Browse the repository at this point in the history
* layers/+tools/shell/packages.el: Bump the xterm-color package for
* emacs < 29.0.50.
* layers/+tools/shell/README.org: Document for the changes.
  • Loading branch information
sunlin7 authored and smile13241324 committed May 11, 2024
1 parent 1c6d9f9 commit b5e43c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
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

0 comments on commit b5e43c7

Please sign in to comment.