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.
This commit is contained in:
		
							parent
							
								
									2c5946163c
								
							
						
					
					
						commit
						5b5f051b13
					
				
					 4 changed files with 35 additions and 36 deletions
				
			
		
							
								
								
									
										13
									
								
								init.el
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								init.el
									
										
									
									
									
								
							| 
						 | 
					@ -78,19 +78,6 @@
 | 
				
			||||||
  :bind ("C-c g" . magit-status)
 | 
					  :bind ("C-c g" . magit-status)
 | 
				
			||||||
  :init (setq magit-repository-directories '(("/home/vincent/projects" . 2))))
 | 
					  :init (setq magit-repository-directories '(("/home/vincent/projects" . 2))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;; (use-package multi-term
 | 
					 | 
				
			||||||
;;   :bind ("C-x t" . counsel-switch-to-term)
 | 
					 | 
				
			||||||
;;   :init (progn
 | 
					 | 
				
			||||||
;;           ;; term-mode's attempt to use isearch is not my favourite thing in the
 | 
					 | 
				
			||||||
;;           ;; world.
 | 
					 | 
				
			||||||
;;           (delete '("C-r" . isearch-backward) term-bind-key-alist)
 | 
					 | 
				
			||||||
;;           (delete '("C-s" . isearch-forward) term-bind-key-alist)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
;;           (add-to-list 'term-bind-key-alist '("C-r" . term-send-reverse-search-history))
 | 
					 | 
				
			||||||
;;           (add-to-list 'term-bind-key-alist '("C-c C-l" . term-line-mode))
 | 
					 | 
				
			||||||
;;           (add-to-list 'term-bind-key-alist '("C-s" . swiper))
 | 
					 | 
				
			||||||
;;           (add-to-list 'term-bind-key-alist '("C-c C-r" . term-rename))))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
(use-package password-store)
 | 
					(use-package password-store)
 | 
				
			||||||
(use-package pg)
 | 
					(use-package pg)
 | 
				
			||||||
(use-package restclient)
 | 
					(use-package restclient)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,6 +158,16 @@ Including indent-buffer, which should not be called automatically on save."
 | 
				
			||||||
   append lsdir into completions
 | 
					   append lsdir into completions
 | 
				
			||||||
   finally return (sort completions 'string-lessp)))
 | 
					   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 ()
 | 
					(defun ivy-run-external-command ()
 | 
				
			||||||
  "Prompts the user with a list of all installed applications and
 | 
					  "Prompts the user with a list of all installed applications and
 | 
				
			||||||
  lets them select one to launch."
 | 
					  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
 | 
					    (ivy-read "Command:" external-commands-list
 | 
				
			||||||
              :require-match t
 | 
					              :require-match t
 | 
				
			||||||
              :history 'external-commands-history
 | 
					              :history 'external-commands-history
 | 
				
			||||||
              :action (lambda (cmd)
 | 
					              :action #'run-external-command)))
 | 
				
			||||||
                        (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-password-store (&optional password-store-dir)
 | 
					(defun ivy-password-store (&optional password-store-dir)
 | 
				
			||||||
  "Custom version of password-store integration with ivy that
 | 
					  "Custom version of password-store integration with ivy that
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,6 +63,9 @@
 | 
				
			||||||
                                         (interactive)
 | 
					                                         (interactive)
 | 
				
			||||||
                                         (ivy-password-store "~/.aprila-secrets")))
 | 
					                                         (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
 | 
					    ;; Toggle between line-mode / char-mode
 | 
				
			||||||
    (exwm-input-set-key (kbd "C-c C-t C-t") #'exwm-input-toggle-keyboard)
 | 
					    (exwm-input-set-key (kbd "C-c C-t C-t") #'exwm-input-toggle-keyboard)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
					  "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)))
 | 
					  (let ((buffer (get-buffer buffer-name)))
 | 
				
			||||||
    (if (not buffer)
 | 
					    (if (not buffer)
 | 
				
			||||||
        (multi-term)
 | 
					        (run-external-command "alacritty")
 | 
				
			||||||
      (switch-to-buffer buffer))))
 | 
					      (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."
 | 
					  "Switch to a (multi-)term buffer or create one."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (let ((terms (counsel-list-buffers-with-mode 'term-mode)))
 | 
					  (let ((terms (-map #'buffer-name
 | 
				
			||||||
 | 
					                     (-filter #'is-alacritty-buffer (buffer-list)))))
 | 
				
			||||||
    (if terms
 | 
					    (if terms
 | 
				
			||||||
        (ivy-read "Switch to term buffer: "
 | 
					        (ivy-read "Switch to Alacritty buffer: "
 | 
				
			||||||
                  (cons "New terminal" terms)
 | 
					                  (cons "New terminal" terms)
 | 
				
			||||||
                  :caller 'counsel-switch-to-term
 | 
					                  :caller 'counsel-switch-to-alacritty
 | 
				
			||||||
                  :require-match t
 | 
					                  :require-match t
 | 
				
			||||||
                  :action #'open-or-create-term-buffer)
 | 
					                  :action #'open-or-create-alacritty-buffer)
 | 
				
			||||||
      (multi-term))))
 | 
					      (run-external-command "alacritty"))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun term-rename ()
 | 
					(defun alacritty-rename ()
 | 
				
			||||||
  "Rename the current terminal buffer."
 | 
					  "Rename the current terminal buffer."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (let* ((buffer (get-buffer (buffer-name)))
 | 
					  (let* ((buffer (get-buffer (buffer-name))))
 | 
				
			||||||
         (mode (buffer-local-value 'major-mode buffer)))
 | 
					    (if (is-alacritty-buffer buffer)
 | 
				
			||||||
    (if (equal 'term-mode mode)
 | 
					        (rename-buffer (format "Alacritty<%s>" (read-string "New terminal name: ")))
 | 
				
			||||||
        (rename-buffer (format "*terminal<%s>*" (read-string "New terminal name: ")))
 | 
					      (error "This function is only intended to rename Alacritty buffers."))))
 | 
				
			||||||
      (error "This function is only intended to rename terminal buffers."))))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(provide 'term-setup)
 | 
					(provide 'term-setup)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue