changeset 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 f84051049637
children c0af5c9f100b
files etc/NEWS lisp/simple.el
diffstat 2 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS	Thu Mar 20 18:38:34 2008 +0000
+++ b/etc/NEWS	Thu Mar 20 19:48:07 2008 +0000
@@ -65,6 +65,8 @@
 
 * Changes in Emacs 23.1
 
+** Minibuffer input of shell commands now comes with completion.
+
 ** Operations like C-x b and C-x C-f which use switch-to-buffer do not fail
 any more when used in a minibuffer or a dedicated window.  Instead, they
 fallback on using pop-to-buffer which will use some other window.
@@ -642,7 +644,10 @@
 
 * Lisp Changes in Emacs 23.1
 
-** The new `buffer-swap-text' function can swap the text between two buffers.
+** The `read-shell-command' function does what its name says, with completion.
+It uses the minibuffer-local-shell-command-map for that.
+
+** The `buffer-swap-text' function can swap the text between two buffers.
 This can be useful for modes such as tar-mode, archive-mode, RMAIL.
 
 ** `clear-image-cache' can be told to flush only images of a specific file.
--- 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)