about summary refs log tree commit diff
path: root/tools/emacs/init/term-setup.el
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-14T11·31+0000
committerVincent Ambo <tazjin@google.com>2019-12-14T11·31+0000
commitb938d716ff20d6d9f093626db1ac0d0d3f97976e (patch)
tree335dab321bdbb2159d776fdf6ad33cfb6714a0c9 /tools/emacs/init/term-setup.el
parent00129e06b2b4968a2e988c177c8d6650120aa278 (diff)
parent15c61c0beebeb2d9645ac7cd3736d21fe286dd3a (diff)
merge(emacs): Merge (unrelated) emacs.d history into tools/emacs r/129
Diffstat (limited to 'tools/emacs/init/term-setup.el')
-rw-r--r--tools/emacs/init/term-setup.el37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/emacs/init/term-setup.el b/tools/emacs/init/term-setup.el
new file mode 100644
index 000000000000..a2a71be9eeba
--- /dev/null
+++ b/tools/emacs/init/term-setup.el
@@ -0,0 +1,37 @@
+;; Utilities for Alacritty buffers.
+
+(defun open-or-create-alacritty-buffer (buffer-name)
+  "Switch to the buffer with BUFFER-NAME or create a
+  new buffer running Alacritty."
+  (let ((buffer (get-buffer buffer-name)))
+    (if (not buffer)
+        (run-external-command "alacritty")
+      (switch-to-buffer buffer))))
+
+(defun is-alacritty-buffer (buffer)
+  "Determine whether BUFFER runs Alacritty."
+  (and (equal 'exwm-mode (buffer-local-value 'major-mode buffer))
+       (s-starts-with? "Alacritty" (buffer-name buffer))))
+
+(defun counsel-switch-to-alacritty ()
+  "Switch to a (multi-)term buffer or create one."
+  (interactive)
+  (let ((terms (-map #'buffer-name
+                     (-filter #'is-alacritty-buffer (buffer-list)))))
+    (if terms
+        (ivy-read "Switch to Alacritty buffer: "
+                  (cons "New terminal" terms)
+                  :caller 'counsel-switch-to-alacritty
+                  :require-match t
+                  :action #'open-or-create-alacritty-buffer)
+      (run-external-command "alacritty"))))
+
+(defun alacritty-rename ()
+  "Rename the current terminal buffer."
+  (interactive)
+  (let* ((buffer (get-buffer (buffer-name))))
+    (if (is-alacritty-buffer buffer)
+        (rename-buffer (format "Alacritty<%s>" (read-string "New terminal name: ")))
+      (error "This function is only intended to rename Alacritty buffers."))))
+
+(provide 'term-setup)