More run-command improvements

This commit is contained in:
Jeremy Dormitzer 2024-04-19 16:00:50 -04:00
parent 312492428e
commit 2b1a828021

View File

@ -8,13 +8,28 @@
(defvar-local run-command-project-local-commands nil)
(put 'run-command-project-local-commands 'safe-local-variable (lambda (_) t))
:config
;; Prevent run-command-runner-vterm from clobbering globals
(defun run-command-runner-vterm-advice (orig-fun command-line buffer-base-name output-buffer &rest args)
(with-current-buffer output-buffer
(make-local-variable 'change-major-mode-hook)
(make-local-variable 'buffer-read-only))
(apply orig-fun command-line buffer-base-name output-buffer args))
(advice-add 'run-command-runner-vterm :around #'run-command-runner-vterm-advice)
;; Add ability to edit command line with prefix arg
(defvar run-command-edit? nil)
(defun run-command-core-run-advice (orig-fun command-spec &rest args)
(let ((spec (if run-command-edit?
(plist-put command-spec :command-line (read-string "Command: " (plist-get command-spec :command-line)))
command-spec)))
(let* ((buffer-base-name
(format "%s[%s]"
(map-elt command-spec :command-name)
(map-elt command-spec :scope-name)))
(buffer (get-buffer-create (concat "*" buffer-base-name "*")))
(spec (if run-command-edit?
(plist-put command-spec :command-line (read-string "Command: " (plist-get command-spec :command-line)))
command-spec)))
(when buffer (kill-buffer buffer))
(apply orig-fun spec args)))
(defun run-command-advice (orig-fun &rest args)
@ -24,6 +39,16 @@
(advice-add 'run-command :around #'run-command-advice)
(advice-add 'run-command-core-run :around #'run-command-core-run-advice)
(defun run-command-with-runner (runner)
(interactive (list (completing-read "Runner: "
'(run-command-runner-compile
run-command-runner-vterm
run-command-runner-term
run-command-runner-eat)
nil t)))
(let ((run-command-default-runner (intern runner)))
(call-interactively #'run-command)))
(defun run-command-recipe-terraform ()
(when (directory-files default-directory
nil
@ -460,7 +485,8 @@
:runner 'run-command-runner-vterm))))))))
:general
(leader-map "\"" #'run-command)
(leader-map "'" #'run-command)
(leader-map "\"" #'run-command-with-runner)
:custom
(run-command-default-runner 'run-command-runner-compile)
(run-command-completion-method 'completing-read)