summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/terminal.el42
1 files changed, 41 insertions, 1 deletions
diff --git a/lisp/terminal.el b/lisp/terminal.el
index 334062e..31787a1 100644
--- a/lisp/terminal.el
+++ b/lisp/terminal.el
@@ -9,11 +9,51 @@
;;; altogether, albeit with a very slow transition-out.
;;;
+;; Global variable that we use for the custom modeline.
(defvar vterm-buffer-title nil
"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'."
- (setq vterm-buffer-title title)))
+ (setq vterm-buffer-title title))
+
+ ;; 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