\f
* 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.
\f
* 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.
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.
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.
;; 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)