diff options
author | Vincent Ambo <mail@tazj.in> | 2018-10-31T09·29+0100 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2019-02-10T20·43+0100 |
commit | 5b5f051b13633cec58e7daa0399085ffcdb1e430 (patch) | |
tree | 88c6ae48a8aeae1cd844caf4eea909cee7850d5a /init | |
parent | 2c5946163c03dfa9b12f9bc83697c593965d08cd (diff) |
refactor: Reutilise multi-term commands for Alacritty buffers
In practice I never use multi-term, but it's nice to have the same buffer selection functionality for Alacritty buffers.
Diffstat (limited to 'init')
-rw-r--r-- | init/functions.el | 18 | ||||
-rw-r--r-- | init/nixos.el | 3 | ||||
-rw-r--r-- | init/term-setup.el | 37 |
3 files changed, 35 insertions, 23 deletions
diff --git a/init/functions.el b/init/functions.el index 640957f109e1..8b96a0e737df 100644 --- a/init/functions.el +++ b/init/functions.el @@ -158,6 +158,16 @@ Including indent-buffer, which should not be called automatically on save." append lsdir into completions finally return (sort completions 'string-lessp))) +(defun run-external-command (cmd) + "Execute the specified command and notify the user when it + finishes." + (message "Starting %s..." cmd) + (set-process-sentinel + (start-process-shell-command cmd nil cmd) + (lambda (process event) + (when (string= event "finished\n") + (message "%s process finished." process))))) + (defun ivy-run-external-command () "Prompts the user with a list of all installed applications and lets them select one to launch." @@ -167,13 +177,7 @@ Including indent-buffer, which should not be called automatically on save." (ivy-read "Command:" external-commands-list :require-match t :history 'external-commands-history - :action (lambda (cmd) - (message "Starting %s..." cmd) - (set-process-sentinel - (start-process-shell-command cmd nil cmd) - (lambda (process event) - (when (string= event "finished\n") - (message "%s process finished." process)))))))) + :action #'run-external-command))) (defun ivy-password-store (&optional password-store-dir) "Custom version of password-store integration with ivy that diff --git a/init/nixos.el b/init/nixos.el index f3cefea7f391..e0e832ce1584 100644 --- a/init/nixos.el +++ b/init/nixos.el @@ -63,6 +63,9 @@ (interactive) (ivy-password-store "~/.aprila-secrets"))) + ;; Add Alacritty selector to a key + (exwm-input-set-key (kbd "C-x t") #'counsel-switch-to-alacritty) + ;; Toggle between line-mode / char-mode (exwm-input-set-key (kbd "C-c C-t C-t") #'exwm-input-toggle-keyboard) diff --git a/init/term-setup.el b/init/term-setup.el index ea58a53bbf04..a2a71be9eeba 100644 --- a/init/term-setup.el +++ b/init/term-setup.el @@ -1,32 +1,37 @@ -;; Utilities for term-mode +;; Utilities for Alacritty buffers. -(defun open-or-create-term-buffer (buffer-name) +(defun open-or-create-alacritty-buffer (buffer-name) "Switch to the buffer with BUFFER-NAME or create a - new (multi-)term-mode buffer." + new buffer running Alacritty." (let ((buffer (get-buffer buffer-name))) (if (not buffer) - (multi-term) + (run-external-command "alacritty") (switch-to-buffer buffer)))) -(defun counsel-switch-to-term () +(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 (counsel-list-buffers-with-mode 'term-mode))) + (let ((terms (-map #'buffer-name + (-filter #'is-alacritty-buffer (buffer-list))))) (if terms - (ivy-read "Switch to term buffer: " + (ivy-read "Switch to Alacritty buffer: " (cons "New terminal" terms) - :caller 'counsel-switch-to-term + :caller 'counsel-switch-to-alacritty :require-match t - :action #'open-or-create-term-buffer) - (multi-term)))) + :action #'open-or-create-alacritty-buffer) + (run-external-command "alacritty")))) -(defun term-rename () +(defun alacritty-rename () "Rename the current terminal buffer." (interactive) - (let* ((buffer (get-buffer (buffer-name))) - (mode (buffer-local-value 'major-mode buffer))) - (if (equal 'term-mode mode) - (rename-buffer (format "*terminal<%s>*" (read-string "New terminal name: "))) - (error "This function is only intended to rename terminal buffers.")))) + (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) |