emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature request : Tab-completion for 'shell-comand'


From: TSUCHIYA Masatoshi
Subject: Re: Feature request : Tab-completion for 'shell-comand'
Date: Sat, 15 Mar 2008 17:29:52 +0900
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux)

Dear Emacs developers,

>> On Tue, 11 Mar 2008 22:12:01 -0400
>> address@hidden (Stefan Monnier) said as follows:

>> I have just prepared the minimized patch to support tab-completion
>> features for `shell-command' etc.

>Could you provide a new version of your patch without the
>make-shell-prompt-string?

Thanks for your comments.  I have just prepared the re-minimized version
and attach it at the end of this message.  I believe that this patch
meets all of your comments.

Regards,

-- 
TSUCHIYA Masatoshi
diff -ur emacs-22.1.orig/lisp/progmodes/compile.el 
emacs-22.1/lisp/progmodes/compile.el
--- emacs-22.1.orig/lisp/progmodes/compile.el   2007-05-25 21:43:33.000000000 
+0900
+++ emacs-22.1/lisp/progmodes/compile.el        2008-03-15 17:18:37.000000000 
+0900
@@ -902,7 +902,9 @@
     (let ((command (eval compile-command)))
       (if (or compilation-read-command current-prefix-arg)
          (read-from-minibuffer "Compile command: "
-                               command nil nil
+                               command
+                               minibuffer-complete-shell-command-map
+                               nil
                                (if (equal (car compile-history) command)
                                    '(compile-history . 1)
                                  'compile-history))
diff -ur emacs-22.1.orig/lisp/progmodes/grep.el 
emacs-22.1/lisp/progmodes/grep.el
--- emacs-22.1.orig/lisp/progmodes/grep.el      2007-04-08 11:08:48.000000000 
+0900
+++ emacs-22.1/lisp/progmodes/grep.el   2008-03-15 17:19:44.000000000 +0900
@@ -541,7 +541,8 @@
        (list (read-from-minibuffer "Run grep (like this): "
                                   (if current-prefix-arg
                                       default grep-command)
-                                  nil nil 'grep-history
+                                  minibuffer-complete-shell-command-map
+                                  nil 'grep-history
                                   (if current-prefix-arg nil default))))))
 
   ;; Setting process-setup-function makes exit-message-function work
@@ -566,7 +567,9 @@
      (grep-compute-defaults)
      (if grep-find-command
         (list (read-from-minibuffer "Run find (like this): "
-                                    grep-find-command nil nil
+                                    grep-find-command
+                                    minibuffer-complete-shell-command-map
+                                    nil
                                      'grep-find-history))
        ;; No default was set
        (read-string
diff -ur emacs-22.1.orig/lisp/simple.el emacs-22.1/lisp/simple.el
--- emacs-22.1.orig/lisp/simple.el      2007-05-27 23:35:51.000000000 +0900
+++ emacs-22.1/lisp/simple.el   2008-03-15 17:25:40.000000000 +0900
@@ -1367,6 +1367,42 @@
   ;; Return the width of everything before the field at the end of
   ;; the buffer; this should be 0 for normal buffers.
   (1- (minibuffer-prompt-end)))
+
+(defcustom minibuffer-complete-shell-command-functions
+  '(shell-dynamic-complete-environment-variable
+    shell-dynamic-complete-command
+    shell-replace-by-expanded-directory
+    comint-dynamic-complete-filename)
+  "*Function list to complete shell commands."
+  :type 'hook
+  :group 'shell)
+
+(defun minibuffer-completing-message (string &rest arguments)
+  "Alternative function of `message' when completing shell command."
+  (let ((s (apply (function format) string arguments)))
+    (minibuffer-message (concat " [" s "]"))
+    s))
+
+(defun minibuffer-complete-shell-command ()
+  "Dynamically complete shell command at point with functions
+specified in `minibuffer-complete-shell-command-functions'."
+  (interactive)
+  (let ((orig-function (symbol-function 'message)))
+    (unwind-protect
+       (progn
+         (fset 'message 'minibuffer-completing-message)
+         (require 'shell)
+         (require 'comint)
+         (run-hook-with-args-until-success
+          'minibuffer-complete-shell-command-functions))
+      (fset 'message orig-function))))
+
+(defvar minibuffer-complete-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.")
 
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (defalias 'advertised-undo 'undo)
@@ -1809,7 +1845,10 @@
 specifies the value of ERROR-BUFFER."
 
   (interactive (list (read-from-minibuffer "Shell command: "
-                                          nil nil nil 'shell-command-history)
+                                          nil
+                                          minibuffer-complete-shell-command-map
+                                          nil
+                                          'shell-command-history)
                     current-prefix-arg
                     shell-command-default-error-buffer))
   ;; Look for a handler in case default-directory is a remote file name.
@@ -2028,7 +2067,9 @@
                 ;; 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
+                                                   nil
+                                                   
minibuffer-complete-shell-command-map
+                                                   nil
                                                    'shell-command-history))
                 ;; call-interactively recognizes region-beginning and
                 ;; region-end specially, leaving them in the history.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]