diff lisp/simple.el @ 93112:6ed43e8a395c

(minibuffer-local-shell-command-map): New var. (minibuffer-complete-shell-command, read-shell-command): New funs. (shell-command, shell-command-on-region): Use them.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 20 Mar 2008 19:48:07 +0000
parents b1cbc5b82a29
children c0af5c9f100b
line wrap: on
line diff
--- a/lisp/simple.el	Thu Mar 20 18:38:34 2008 +0000
+++ b/lisp/simple.el	Thu Mar 20 19:48:07 2008 +0000
@@ -1921,6 +1921,29 @@
 is run interactively.  A value of nil means that output to stderr and
 stdout will be intermixed in the output stream.")
 
+(defun minibuffer-complete-shell-command ()
+  "Dynamically complete shell command at point."
+  (interactive)
+  (require 'shell)
+  (run-hook-with-args-until-success 'shell-dynamic-complete-functions))
+
+(defvar minibuffer-local-shell-command-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map minibuffer-local-map)
+    (define-key map "\t" 'minibuffer-complete-shell-command)
+    map)
+  "Keymap used for completiing shell commands in minibufffer.")
+
+(defun read-shell-command (prompt &optional initial-contents hist &rest args)
+  "Read a shell command from the minibuffer.
+The arguments are the same as the ones of `read-from-minibuffer',
+except READ and KEYMAP are missing and HIST defaults
+to `shell-command-history'."
+  (apply 'read-from-minibuffer prompt initial-contents
+         (or keymap minibuffer-local-shell-command-map)
+         (or hist 'shell-command-history)
+         args))
+
 (defun shell-command (command &optional output-buffer error-buffer)
   "Execute string COMMAND in inferior shell; display output, if any.
 With prefix argument, insert the COMMAND's output at point.
@@ -1971,8 +1994,7 @@
 In an interactive call, the variable `shell-command-default-error-buffer'
 specifies the value of ERROR-BUFFER."
 
-  (interactive (list (read-from-minibuffer "Shell command: "
-					   nil nil nil 'shell-command-history)
+  (interactive (list (read-shell-command "Shell command: ")
 		     current-prefix-arg
 		     shell-command-default-error-buffer))
   ;; Look for a handler in case default-directory is a remote file name.
@@ -2190,9 +2212,7 @@
 		 ;; Do this before calling region-beginning
 		 ;; and region-end, in case subprocess output
 		 ;; relocates them while we are in the minibuffer.
-		 (setq string (read-from-minibuffer "Shell command on region: "
-						    nil nil nil
-						    'shell-command-history))
+		 (setq string (read-shell-command "Shell command on region: "))
 		 ;; call-interactively recognizes region-beginning and
 		 ;; region-end specially, leaving them in the history.
 		 (list (region-beginning) (region-end)