merge(PR#12): Switch Emacs terminals over to libvterm
This moves the terminals inside of my Emacs from being `gnome-terminal` instances under EXWM over to [emacs-libvterm](https://github.com/akermu/emacs-libvterm). This incredible package embeds a fully featured terminal emulator (based on `libvterm`) into Emacs with the killer feature of being able to switch a terminal buffer to read-only text mode and use normal Emacs selection commands. This is something I've wanted for a long time and that `ansi-term` etc. just weren't good enough for!
This commit is contained in:
commit
4897669f50
3 changed files with 36 additions and 39 deletions
|
@ -1,72 +1,55 @@
|
||||||
;;; term-switcher.el --- Easily switch between open X11 terminals
|
;;; term-switcher.el --- Easily switch between open vterms
|
||||||
;;
|
;;
|
||||||
;; Copyright (C) 2019 Google Inc.
|
;; Copyright (C) 2019 Google Inc.
|
||||||
;;
|
;;
|
||||||
;; Author: Vincent Ambo <tazjin@google.com>
|
;; Author: Vincent Ambo <tazjin@google.com>
|
||||||
;; Version: 1.0
|
;; Version: 1.1
|
||||||
;; Package-Requires: (dash ivy s)
|
;; Package-Requires: (dash ivy s)
|
||||||
;;
|
;;
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This package adds a function that lets users quickly switch between
|
;; This package adds a function that lets users quickly switch between
|
||||||
;; different open X11 terminals using ivy.
|
;; different open vterms via ivy.
|
||||||
;;
|
|
||||||
;; It is primarily intended to be used by EXWM users who use graphical
|
|
||||||
;; terminals inside of Emacs.
|
|
||||||
;;
|
|
||||||
;; Users MUST configure the group `term-switcher' and can then bind
|
|
||||||
;; `ts/switch-to-terminal' to an appropriate key.
|
|
||||||
|
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
(require 'ivy)
|
(require 'ivy)
|
||||||
(require 's)
|
(require 's)
|
||||||
|
|
||||||
(defgroup term-switcher nil
|
(defgroup term-switcher nil
|
||||||
"Customization options for configuring `term-switcher' with the
|
"Customization options `term-switcher'.")
|
||||||
user's terminal emulator of choice.")
|
|
||||||
|
|
||||||
(defcustom term-switcher-program "gnome-terminal"
|
(defcustom term-switcher-buffer-prefix "vterm<"
|
||||||
"X11 terminal application to use."
|
"String prefix for vterm terminal buffers. For example, if you
|
||||||
|
set your titles to match `vterm<...>' a useful prefix might be
|
||||||
|
`vterm<'."
|
||||||
:type '(string)
|
:type '(string)
|
||||||
:group 'term-switcher)
|
:group 'term-switcher)
|
||||||
|
|
||||||
(defcustom term-switcher-buffer-prefix "Term"
|
(defun ts/open-or-create-vterm (buffer-name)
|
||||||
"String prefix for X11 terminal buffers. For example, if your
|
"Switch to the buffer with BUFFER-NAME or create a new vterm
|
||||||
EXWM configuration renames X11 terminal buffers to
|
buffer."
|
||||||
`Term</foo/bar>' you might want to use `Term' as the matching
|
|
||||||
prefix."
|
|
||||||
:type '(string)
|
|
||||||
:group 'term-switcher)
|
|
||||||
|
|
||||||
(defun ts/run-terminal-program ()
|
|
||||||
(message "Starting %s..." term-switcher-program)
|
|
||||||
(start-process-shell-command term-switcher-program nil term-switcher-program))
|
|
||||||
|
|
||||||
(defun ts/open-or-create-terminal-buffer (buffer-name)
|
|
||||||
"Switch to the buffer with BUFFER-NAME or create a new buffer
|
|
||||||
running the configured X11 terminal."
|
|
||||||
(let ((buffer (get-buffer buffer-name)))
|
(let ((buffer (get-buffer buffer-name)))
|
||||||
(if (not buffer)
|
(if (not buffer)
|
||||||
(ts/run-terminal-program)
|
(vterm)
|
||||||
(switch-to-buffer buffer))))
|
(switch-to-buffer buffer))))
|
||||||
|
|
||||||
(defun ts/is-terminal-buffer (buffer)
|
(defun ts/is-vterm-buffer (buffer)
|
||||||
"Determine whether BUFFER runs an X11 terminal."
|
"Determine whether BUFFER runs a vterm."
|
||||||
(and (equal 'exwm-mode (buffer-local-value 'major-mode buffer))
|
(equal 'vterm-mode (buffer-local-value 'major-mode buffer)))
|
||||||
(s-starts-with? term-switcher-buffer-prefix (buffer-name buffer))))
|
|
||||||
|
|
||||||
(defun ts/switch-to-terminal ()
|
(defun ts/switch-to-terminal ()
|
||||||
"Switch to an X11 terminal buffer, or create a new one."
|
"Switch to an existing vterm buffer or create a new one."
|
||||||
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((terms (-map #'buffer-name
|
(let ((terms (-map #'buffer-name
|
||||||
(-filter #'ts/is-terminal-buffer (buffer-list)))))
|
(-filter #'ts/is-vterm-buffer (buffer-list)))))
|
||||||
(if terms
|
(if terms
|
||||||
(ivy-read "Switch to terminal buffer: "
|
(ivy-read "Switch to vterm: "
|
||||||
(cons "New terminal" terms)
|
(cons "New vterm" terms)
|
||||||
:caller 'ts/switch-to-terminal
|
:caller 'ts/switch-to-terminal
|
||||||
:preselect (s-concat "^" term-switcher-buffer-prefix)
|
:preselect (s-concat "^" term-switcher-buffer-prefix)
|
||||||
:require-match t
|
:require-match t
|
||||||
:action #'ts/open-or-create-terminal-buffer)
|
:action #'ts/open-or-create-vterm)
|
||||||
(ts/run-terminal-program))))
|
(vterm))))
|
||||||
|
|
||||||
(provide 'term-switcher)
|
(provide 'term-switcher)
|
||||||
|
|
|
@ -73,6 +73,19 @@
|
||||||
(use-package pg)
|
(use-package pg)
|
||||||
(use-package restclient)
|
(use-package restclient)
|
||||||
|
|
||||||
|
(use-package vterm
|
||||||
|
:config (progn
|
||||||
|
(setq vterm-shell "/usr/bin/fish")
|
||||||
|
(setq vterm-exit-functions
|
||||||
|
(lambda (&rest _) (kill-buffer (current-buffer))))
|
||||||
|
(setq vterm-set-title-functions
|
||||||
|
(lambda (title)
|
||||||
|
(rename-buffer
|
||||||
|
(generate-new-buffer-name
|
||||||
|
(format "vterm<%s>"
|
||||||
|
(s-trim-left
|
||||||
|
(s-chop-prefix "fish" title)))))))))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Packages providing language-specific functionality
|
;; Packages providing language-specific functionality
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -73,6 +73,7 @@ let
|
||||||
transient
|
transient
|
||||||
use-package
|
use-package
|
||||||
uuidgen
|
uuidgen
|
||||||
|
vterm
|
||||||
web-mode
|
web-mode
|
||||||
websocket
|
websocket
|
||||||
which-key
|
which-key
|
||||||
|
|
Loading…
Reference in a new issue