diff options
author | Vincent Ambo <tazjin@google.com> | 2019-12-14T13·21+0000 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-12-14T13·21+0000 |
commit | c1ba41a62d3fedc11c18796ed4f28239a7f2f752 (patch) | |
tree | 0c71745022f480f8c3b4a813bcad85af05af3d69 /tools/emacs/init/term-setup.el | |
parent | bd7c9e4b5acb5671e0b96572dcde0525a0f7c9c1 (diff) |
feat(emacs.d): Generalise counsel terminal selector r/139
This makes it possible to use my terminal selector with any X11 terminal, configurable via two simple variables.
Diffstat (limited to 'tools/emacs/init/term-setup.el')
-rw-r--r-- | tools/emacs/init/term-setup.el | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/tools/emacs/init/term-setup.el b/tools/emacs/init/term-setup.el index a2a71be9eeba..cd4f9c25ef73 100644 --- a/tools/emacs/init/term-setup.el +++ b/tools/emacs/init/term-setup.el @@ -1,37 +1,36 @@ -;; Utilities for Alacritty buffers. +;; Utilities for X11 terminal buffers. -(defun open-or-create-alacritty-buffer (buffer-name) - "Switch to the buffer with BUFFER-NAME or create a - new buffer running Alacritty." +(defvar x11-terminal-program "gnome-terminal" + "Which X11 terminal application to use.") + +(defvar x11-terminal-buffer-prefix "Term" + "String prefix for X11 terminal buffer names.") + +(defun 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))) (if (not buffer) - (run-external-command "alacritty") + (run-external-command x11-terminal-program) (switch-to-buffer buffer)))) -(defun is-alacritty-buffer (buffer) - "Determine whether BUFFER runs Alacritty." +(defun is-terminal-buffer (buffer) + "Determine whether BUFFER runs an X11 terminal." (and (equal 'exwm-mode (buffer-local-value 'major-mode buffer)) - (s-starts-with? "Alacritty" (buffer-name buffer)))) + (s-starts-with? x11-terminal-buffer-prefix (buffer-name buffer)))) -(defun counsel-switch-to-alacritty () - "Switch to a (multi-)term buffer or create one." +(defun counsel-switch-to-terminal () + "Switch to an X11 terminal buffer, or create a new one." (interactive) (let ((terms (-map #'buffer-name - (-filter #'is-alacritty-buffer (buffer-list))))) + (-filter #'is-terminal-buffer (buffer-list))))) (if terms - (ivy-read "Switch to Alacritty buffer: " + (ivy-read "Switch to terminal buffer: " (cons "New terminal" terms) - :caller 'counsel-switch-to-alacritty + :caller 'counsel-switch-to-terminal + :preselect (s-concat "^" x11-terminal-buffer-prefix) :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.")))) + :action #'open-or-create-terminal-buffer) + (run-external-command x11-terminal-program)))) (provide 'term-setup) |