feat(term-setup): First attempt to make multi-term tolerable
I've been wanting to use in-emacs terminal buffers instead of Alacritty as an EXWM window for a while. In light of the recent EXWM bugs that cause overlapping X-windows occasionally I've finally had it! This commit introduces a new configuration file for multi-term related settings. Primarily this does the following: * Introduce a new `C-x t` keybinding which launches a terminal if none is running, or prompts the user to select one of the existing ones. * Remap key bindings in term-mode for quick access to features I want. * Add a `C-c C-r` key binding in term-mode to quickly rename terminal buffers into something sensible. Hopefully this will play nice with the ivy-based selector from the first point mentioned here. I'll see how it goes!
This commit is contained in:
		
							parent
							
								
									ced93e2606
								
							
						
					
					
						commit
						7b8902a36a
					
				
					 2 changed files with 47 additions and 0 deletions
				
			
		
							
								
								
									
										1
									
								
								init.el
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								init.el
									
										
									
									
									
								
							|  | @ -32,6 +32,7 @@ | ||||||
|                    settings |                    settings | ||||||
|                    modes |                    modes | ||||||
|                    bindings |                    bindings | ||||||
|  |                    term-setup | ||||||
|                    eshell-setup |                    eshell-setup | ||||||
|                    haskell-setup |                    haskell-setup | ||||||
|                    rust-setup |                    rust-setup | ||||||
|  |  | ||||||
							
								
								
									
										46
									
								
								init/term-setup.el
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								init/term-setup.el
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,46 @@ | ||||||
|  | ;; Configuration for multi-term mode: | ||||||
|  | 
 | ||||||
|  | (require 'multi-term) | ||||||
|  | 
 | ||||||
|  | (defun open-or-create-term-buffer (buffer-name) | ||||||
|  |   "Switch to the buffer with BUFFER-NAME or create a | ||||||
|  |   new (multi-)term-mode buffer." | ||||||
|  |   (let ((buffer (get-buffer buffer-name))) | ||||||
|  |     (if (not buffer) | ||||||
|  |         (multi-term) | ||||||
|  |       (switch-to-buffer buffer)))) | ||||||
|  | 
 | ||||||
|  | (defun counsel-switch-to-term () | ||||||
|  |   "Switch to a (multi-)term buffer or create one." | ||||||
|  |   (interactive) | ||||||
|  |   (let ((terms (counsel-list-buffers-with-mode 'term-mode))) | ||||||
|  |     (if terms | ||||||
|  |         (ivy-read "Switch to term buffer: " | ||||||
|  |                   (cons "New terminal" terms) | ||||||
|  |                   :caller 'counsel-switch-to-term | ||||||
|  |                   :require-match t | ||||||
|  |                   :action #'open-or-create-term-buffer) | ||||||
|  |       (multi-term)))) | ||||||
|  | 
 | ||||||
|  | (defun term-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.")))) | ||||||
|  | 
 | ||||||
|  | (global-set-key (kbd "C-x t") #'counsel-switch-to-term) | ||||||
|  | 
 | ||||||
|  | ;; 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)) | ||||||
|  | 
 | ||||||
|  | (provide 'term-setup) | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue