1
0
Fork 0
emacs-config/oni-eshell.el
Tom Willemse 11f53711a4 Fix error in setting up xterm-color in eshell
Apparently when the ‘oni-eshell’ library gets loaded neither
‘eshell-preoutput-filter-functions’ nor ‘eshell-output-filter-functions’ are
ready to be used, even though they are defined in the ‘esh-mode’ libary, which
is loaded at this point in time.
2019-09-20 09:34:43 -07:00

88 lines
3.1 KiB
EmacsLisp
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; oni-eshell.el --- Eshell configuration -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Tom Willemse
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2019.0920.093304
;; Package-Requires: (eshell-fringe-status esh-autosuggest xterm-color)
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Eshell configuration.
;;; Code:
(require 'eshell)
(require 'em-prompt)
(require 'esh-autosuggest)
(require 'xterm-color)
(defun oni-eshell--C-d ()
"Call `delete-char' or close the buffer if it fails."
(interactive)
(condition-case err
(call-interactively #'delete-char)
(error (if (and (eq (car err) 'end-of-buffer)
(looking-back eshell-prompt-regexp nil))
(kill-buffer)
(signal (car err) (cdr err))))))
(defun oni-eshell--enable-truncating-buffers ()
"Add `eshell-truncate-buffer' to `eshell-output-filter-functions'."
(add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer))
(defun oni-eshell--enable-xterm-filter ()
"Add xterm-color-filter to eshell-preoutput-filter-functions."
(add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter))
(defun oni-eshell--disable-ansi-color-handling ()
"Remove eshell-handle-ansi-color from eshell-output-filter-functions."
(setq eshell-output-filter-functions
(remove 'eshell-handle-ansi-color eshell-output-filter-functions)))
(defun oni-eshell--set-eshell-C-d ()
"Set `C-d' to quit eshell if used at end of prompt."
(define-key eshell-mode-map (kbd "C-d") #'oni-eshell--C-d))
(defun oni-eshell--set-xterm-variables ()
"Set xterm-color-preserve-properties to t."
(setq xterm-color-preserve-properties t))
(add-hook 'eshell-first-time-mode-hook #'oni-eshell--set-eshell-C-d)
(add-hook 'eshell-load-hook #'oni-eshell--enable-truncating-buffers)
(add-hook 'eshell-load-hook #'oni-eshell--enable-xterm-filter)
(add-hook 'eshell-load-hook #'oni-eshell--disable-ansi-color-handling)
(add-hook 'eshell-mode-hook 'esh-autosuggest-mode)
(add-hook 'eshell-mode-hook 'goto-address-mode)
(add-hook 'eshell-before-prompt-hook #'oni-eshell--set-xterm-variables)
(when (display-graphic-p)
(add-hook 'eshell-mode-hook 'eshell-fringe-status-mode))
(setenv "TERM" "xterm-256color")
(add-to-list 'display-buffer-alist
'("\\`\\*eshell" display-buffer-in-side-window
(side . bottom)
(slot . 0)
(window-height . 0.33)))
;;;###autoload(with-eval-after-load 'eshell (require 'oni-eshell))
(provide 'oni-eshell)
;;; oni-eshell.el ends here