From: Stefan Monnier Date: Thu, 20 Mar 2008 19:48:07 +0000 (+0000) Subject: (minibuffer-local-shell-command-map): New var. X-Git-Tag: emacs-pretest-23.0.90~7017 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e5c4079cc47109540c1a8e69a320f98e1b8c4039;p=emacs.git (minibuffer-local-shell-command-map): New var. (minibuffer-complete-shell-command, read-shell-command): New funs. (shell-command, shell-command-on-region): Use them. --- diff --git a/etc/NEWS b/etc/NEWS index 3d881e40232..751e1dd31cd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -65,6 +65,8 @@ default toolkit, but you can use --with-x-toolkit=gtk if necessary. * 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 @@ functions and variables (formerly used for Tamil script). * 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. diff --git a/lisp/simple.el b/lisp/simple.el index d7cea7d3194..38c30e3ae9a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1921,6 +1921,29 @@ This buffer is used when `shell-command' or `shell-command-on-region' 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 @@ If it is nil, error output is mingled with regular output. 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 @@ specifies the value of ERROR-BUFFER." ;; 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)