Created
April 4, 2018 14:07
-
-
Save vargonaut/bcf0060bdefac31fff61114641a1ca47 to your computer and use it in GitHub Desktop.
Repeat the last terminal command from any buffer (in Emacs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; I use it for other things, but in this case, its used to give you a | |
| ;; list of terminal buffers to choose from. FWIW, you could hard-code | |
| ;; the buffer name. | |
| (defun ajv-ido-completing-read-for-mode (prompt the-mode) | |
| (ido-completing-read prompt | |
| (save-excursion | |
| (delq | |
| nil | |
| (mapcar (lambda (buf) | |
| (when (buffer-live-p buf) | |
| (with-current-buffer buf | |
| (and (eq major-mode the-mode) | |
| (buffer-name buf))))) | |
| (buffer-list)))))) | |
| ;; This basically goes to the terminal buffer and does <up> <return> | |
| ;; to rerun the last command. Not graceful, but it works. | |
| (defun term-repeat-last-command () | |
| (interactive) | |
| (with-current-buffer (ajv-ido-completing-read-for-mode "Rerun from:" 'term-mode) | |
| (end-of-buffer) | |
| (term-send-up) | |
| (term-send-input))) | |
| ;; One binding to key them all! Wait, what? | |
| (global-set-key (kbd "M-r") 'term-repeat-last-command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment