aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Kågedal <david@virtutech.com>2010-02-03 10:09:58 +0100
committerGustav Hållberg <gustav@virtutech.com>2010-02-03 10:09:58 +0100
commite8faa44b9a8771490b14044bbb99fa2538d0f42e (patch)
tree98cd77d72fa8fd97b2e9d2e18319f741f8425ec1
parent54239abfc46cde2551435cf1cb777c702b31b2f5 (diff)
downloadstgit-e8faa44b9a8771490b14044bbb99fa2538d0f42e.tar.gz
stgit.el: Add the stgit-execute command and bind it to "!"
Signed-off-by: David Kågedal <david@virtutech.com> Signed-off-by: Gustav Hållberg <gustav@virtutech.com>
-rw-r--r--contrib/stgit.el58
1 files changed, 57 insertions, 1 deletions
diff --git a/contrib/stgit.el b/contrib/stgit.el
index 86602be..6248cd9 100644
--- a/contrib/stgit.el
+++ b/contrib/stgit.el
@@ -1006,7 +1006,8 @@ file for (applied) copies and renames."
("\C-c\C-b" . stgit-rebase)
("t" . ,toggle-map)
("d" . ,diff-map)
- ("q" . stgit-quit))))
+ ("q" . stgit-quit)
+ ("!" . stgit-execute))))
(let ((at-unmerged-file '(let ((file (stgit-patched-file-at-point)))
(and file (eq (stgit-file->status file)
@@ -1148,6 +1149,8 @@ Basic commands:
\\[stgit-git-status] Run `git-status' (if available)
+\\[stgit-execute] Run an stg shell command
+
Movement commands:
\\[stgit-previous-line] Move to previous line
\\[stgit-next-line] Move to next line
@@ -2211,6 +2214,59 @@ deepest patch had before the squash."
(interactive)
(describe-function 'stgit-mode))
+(defun stgit-execute-process-sentinel (process sentinel)
+ (let (old-sentinel stgit-buf)
+ (with-current-buffer (process-buffer process)
+ (setq old-sentinel old-process-sentinel
+ stgit-buf stgit-buffer))
+ (and (memq (process-status process) '(exit signal))
+ (buffer-live-p stgit-buf)
+ (with-current-buffer stgit-buf
+ (stgit-reload)))
+ (funcall old-sentinel process sentinel)))
+
+(defun stgit-execute ()
+ "Prompt for an stg command to execute in a shell.
+
+The names of any marked patches or the patch at point are
+inserted in the command to be executed.
+
+If the command ends in an ampersand, run it asynchronously.
+
+When the command has finished, reload the stgit buffer."
+ (interactive)
+ (stgit-assert-mode)
+ (let* ((patches (stgit-patches-marked-or-at-point nil t))
+ (patch-names (mapcar 'symbol-name patches))
+ (hyphens (find-if (lambda (s) (string-match "^-" s)) patch-names))
+ (defaultcmd (if patches
+ (concat "stg "
+ (and hyphens "-- ")
+ (mapconcat 'identity patch-names " "))
+ "stg "))
+ (cmd (read-from-minibuffer "Shell command: " (cons defaultcmd 5)
+ nil nil 'shell-command-history))
+ (async (string-match "&[ \t]*\\'" cmd))
+ (buffer (get-buffer-create
+ (if async
+ "*Async Shell Command*"
+ "*Shell Command Output*"))))
+ ;; cannot use minibuffer as stgit-reload would overwrite it; if we
+ ;; show the buffer, shell-command will not use the minibuffer
+ (display-buffer buffer)
+ (shell-command cmd)
+ (if async
+ (let ((old-buffer (current-buffer)))
+ (with-current-buffer buffer
+ (let ((process (get-buffer-process buffer)))
+ (set (make-local-variable 'old-process-sentinel)
+ (process-sentinel process))
+ (set (make-local-variable 'stgit-buffer)
+ old-buffer)
+ (set-process-sentinel process 'stgit-execute-process-sentinel))))
+ (shrink-window-if-larger-than-buffer (get-buffer-window buffer))
+ (stgit-reload))))
+
(defun stgit-undo-or-redo (redo hard)
"Run stg undo or, if REDO is non-nil, stg redo.