Skip to content

Latest commit

 

History

History
187 lines (140 loc) · 4.29 KB

wal-terminal.org

File metadata and controls

187 lines (140 loc) · 4.29 KB

Terminal

I am convinced that we are in a terminal process. — E. P. Thompson

Header

;;; wal-terminal.el --- Terminal. -*- lexical-binding: t -*-

;;; Commentary:
;;
;; Provide terminal packages.

;;; Code:

(eval-when-compile
  (require 'wal-useful nil t)
  (require 'wal-package nil t)
  (require 'wal-bridge nil t))

(declare-function project-buffers "ext:project.el")
(declare-function project-current "ext:project.el")
(declare-function project-prefixed-buffer-name "ext:project.el")
(declare-function project-root "ext:project.el")
(declare-function vterm "ext:vterm.el")
(declare-function wdb-faraway "wal-useful.el")

(defvar eshell-buffer-name)

Packages

with-editor

Makes sure that Emacs is used as a visual editor when a terminal opens a file.

(use-package with-editor
  :custom
  (with-editor-mode-lighter " w/e"))

Eshell

(junk-expand eshell
  "Make eshell feel like a feature-complete shell."
  :packages (eshell-syntax-highlighting))

eshell

I’ve been told it’s not a complete shell but it allows using Emacs commands from a shell-like interface.

This makes sure truncation actually fully truncates. Also sets up with-editor and a banner message.

(defun wal-instead-truncate-buffer (&rest _r)
  "Advise to truncate buffer."
  (defvar eshell-buffer-maximum-lines)
  (declare-function eshell-truncate-buffer "ext:eshell.el")

  (let ((eshell-buffer-maximum-lines 0))

    (eshell-truncate-buffer)))

(use-package eshell
  :hook
  ((eshell-mode . with-editor-export-editor)
   (eshell-mode . with-editor-export-git-editor))

  :config
  (advice-add
   'eshell/clear :override
   #'wal-instead-truncate-buffer)

  :custom
  (eshell-banner-message (concat
                          (propertize "}< ,.__)" 'face 'mode-line-highlight)
                          "-eshell"
                          "\n\n"))

  :bind
  (("C-c e" . eshell)))

eshell-syntax-highlighting

Add syntax highlighting in eshell buffers.

(use-package eshell-syntax-highlighting
  :hook (eshell-mode . eshell-syntax-highlighting-mode))

vterm

Fully functional and slightly cumbersome terminal usable within Emacs.

Adds the same functionality to have one vterm buffer per project and sets up with-editor.

(defun wal-vterm--prefer-project (fun &optional arg)
  "Get preferably a `vterm' buffer.

This calls FUN (which is `vterm'). If there is a project and ARG
is non-nil, this creates a new buffer even if a project buffer
already exists."
  (interactive "P")

  (if-let ((project (project-current)))

    (let* ((default-directory (project-root project))
           (vterm-buffer-name (project-prefixed-buffer-name "vterm"))
           (buffer (get-buffer vterm-buffer-name)))

      (if (and buffer (not arg))
          (pop-to-buffer buffer (bound-and-true-p display-comint-buffer-action))

        (funcall fun arg)))

    (funcall fun arg)))

(defun wal-vterm-adjust-by-disabling-query-on-exit (buffer)
  "Disable query-on-exit for BUFFER."
  (when-let ((proc (get-buffer-process buffer)))
    (set-process-query-on-exit-flag proc nil)))

(use-package vterm
  :hook
  (vterm-mode . with-editor-export-git-editor)

  :init
  (advice-add
   'vterm :around
   #'wal-vterm--prefer-project)

  (advice-add
   'vterm :filter-return
   #'wal-vterm-adjust-by-disabling-query-on-exit)

  :custom
  (vterm-prefix "VTerm")
  (vterm-max-scrollback 10000)

  :general
  (ambassador "t" 'vterm)

  :delight
  (vterm-copy-mode " vcp"))

Footer

(provide 'wal-terminal)

;;; wal-terminal.el ends here