blob: c69e5690ee6e35fe614843bb1eff9ea380201c40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
;;; shell.el -*- lexical-binding: t; -*-
;;;
;;; Author: Jakob L. Kreuze <zerodaysfordays@sdf.org>
;;; URL: https://git.sr.ht/~jakob/.emacs.d/
;;;
;;; `shell' is sometimes clunky, and I can't get `alacritty' to work on my
;;; Pinebook Pro anymore, so I've been experimenting with `vterm'. Thus far, it
;;; is a nice medium between the two, so I am considering dropping `shell'
;;; altogether, albeit with a very slow transition-out.
;;;
;; Global variable that we use for the custom modeline.
(defvar vterm-buffer-titles (make-hash-table)
"Title set by shell program.")
;; Some niceties for creating VTerm buffers with descriptive names.
(defun vterm-create-session-interactively (&optional ARG)
"Wrapper around `vterm' to _always_ create a new session.
Possibly with a user-specified distinctive name."
(interactive "p")
(if (/= ARG 1)
(vterm (format "*vterm*<%s>" (read-string "Name of buffer: ")))
(vterm 't)))
(defun vterm-cycle-buffers ()
"Switch to a vterm buffer in a cyclic order.
If a vterm buffer is currently open, choose the next in the ring.
Otherwise, switch to the first available vterm buffer."
(interactive)
(let* ((buffer-names (mapcar #'buffer-name (buffer-list)))
(candidates (seq-filter (lambda (x) (string-search "*vterm*" x)) buffer-names))
(cur-idx (or (seq-find-index (lambda (x)
(string= x (buffer-name (current-buffer))))
candidates)
-1))
(idx (if (= (1+ cur-idx) (length candidates))
0
(1+ cur-idx))))
(switch-to-buffer (elt candidates idx))))
(use-package vterm
;; Hook into `vterm--set-title' for updating our custom modeline.
:config
(defun vterm--set-title (title)
"Use TITLE to set the buffer name according to `vterm-buffer-name-string'."
(puthash (current-buffer) title vterm-buffer-titles))
;; Custom keybindings for cycling through open VTerm buffers.
:bind
(:map vterm-mode-map
("M-s-p" . vterm-cycle-buffer)
("M-s-d" . vterm-cycle-buffer))
:bind
("s-<return>" . (lambda ()
(interactive)
(vterm-create-session-interactively 2))))
|
© 2015 - 2026 Jakob L. Kreuze