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: Juri Linkov
Subject: Re: Feature request : Tab-completion for 'shell-comand'
Date: Thu, 20 Mar 2008 22:55:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

>> 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.
>
> Thanks.  I've installed a slightly different version.
> Now we need to fix the minibuffer messages (and use read-shell-command
> wherever it can be used).

The following patch fixes the minibuffer messages.  I tried it for a week,
and it works really well.  There is no need to display most of the
completion messages (except "No completions") in the minibuffer
because it is self-evident what completion does from its result
(this is like completion in shells that doesn't display special
messages but it is clear what it does without messages).

This patch also fixes incorrect highlighting of the common completion
substring by adding a new optional argument `common-substring' to
`comint-dynamic-list-completions':

Index: lisp/comint.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/comint.el,v
retrieving revision 1.375
diff -c -r1.375 comint.el
*** lisp/comint.el      12 Mar 2008 17:56:57 -0000      1.375
--- lisp/comint.el      20 Mar 2008 20:52:54 -0000
***************
*** 2871,2877 ****
         (directory (if filedir (comint-directory filedir) default-directory))
         (completion (file-name-completion filenondir directory)))
      (cond ((null completion)
!          (message "No completions of %s" filename)
           (setq success nil))
          ((eq completion t)            ; Means already completed "file".
           (insert filesuffix)
--- 2871,2879 ----
         (directory (if filedir (comint-directory filedir) default-directory))
         (completion (file-name-completion filenondir directory)))
      (cond ((null completion)
!          (if minibuffer-p
!              (minibuffer-message (format " [No completions of %s]" filename))
!            (message "No completions of %s" filename))
           (setq success nil))
          ((eq completion t)            ; Means already completed "file".
           (insert filesuffix)
***************
*** 2935,2953 ****
  
  See also `comint-dynamic-complete-filename'."
    (let* ((completion-ignore-case (memq system-type '(ms-dos windows-nt 
cygwin)))
         (suffix (cond ((not comint-completion-addsuffix) "")
                       ((not (consp comint-completion-addsuffix)) " ")
                       (t (cdr comint-completion-addsuffix))))
         (completions (all-completions stub candidates)))
      (cond ((null completions)
!          (message "No completions of %s" stub)
           nil)
          ((= 1 (length completions))   ; Gotcha!
           (let ((completion (car completions)))
             (if (string-equal completion stub)
!                (message "Sole completion")
               (insert (substring completion (length stub)))
!              (message "Completed"))
             (insert suffix)
             'sole))
          (t                            ; There's no unique completion.
--- 2937,2960 ----
  
  See also `comint-dynamic-complete-filename'."
    (let* ((completion-ignore-case (memq system-type '(ms-dos windows-nt 
cygwin)))
+        (minibuffer-p (window-minibuffer-p (selected-window)))
         (suffix (cond ((not comint-completion-addsuffix) "")
                       ((not (consp comint-completion-addsuffix)) " ")
                       (t (cdr comint-completion-addsuffix))))
         (completions (all-completions stub candidates)))
      (cond ((null completions)
!          (if minibuffer-p
!              (minibuffer-message (format " [No completions of %s]" stub))
!            (message "No completions of %s" stub))
           nil)
          ((= 1 (length completions))   ; Gotcha!
           (let ((completion (car completions)))
             (if (string-equal completion stub)
!                (unless minibuffer-p
!                  (message "Sole completion"))
               (insert (substring completion (length stub)))
!              (unless minibuffer-p
!                (message "Completed")))
             (insert suffix)
             'sole))
          (t                            ; There's no unique completion.
***************
*** 2959,2973 ****
                         (member completion completions))
                    ;; It's not unique, but user wants shortest match.
                    (insert suffix)
!                   (message "Completed shortest")
                    'shortest)
                   ((or comint-completion-autolist
                        (string-equal stub completion))
                    ;; It's not unique, list possible completions.
!                   (comint-dynamic-list-completions completions)
                    'listed)
                   (t
!                   (message "Partially completed")
                    'partial)))))))
  
  
--- 2966,2982 ----
                         (member completion completions))
                    ;; It's not unique, but user wants shortest match.
                    (insert suffix)
!                   (unless minibuffer-p
!                     (message "Completed shortest"))
                    'shortest)
                   ((or comint-completion-autolist
                        (string-equal stub completion))
                    ;; It's not unique, list possible completions.
!                   (comint-dynamic-list-completions completions stub)
                    'listed)
                   (t
!                   (unless minibuffer-p
!                     (message "Partially completed"))
                    'partial)))))))
  
  
***************
*** 2985,2993 ****
         (directory (if filedir (comint-directory filedir) default-directory))
         (completions (file-name-all-completions filenondir directory)))
      (if (not completions)
!       (message "No completions of %s" filename)
        (comint-dynamic-list-completions
!        (mapcar 'comint-quote-filename completions)))))
  
  
  ;; This is bound locally in a *Completions* buffer to the list of
--- 2994,3005 ----
         (directory (if filedir (comint-directory filedir) default-directory))
         (completions (file-name-all-completions filenondir directory)))
      (if (not completions)
!       (if (window-minibuffer-p (selected-window))
!           (minibuffer-message (format " [No completions of %s]" filename))
!         (message "No completions of %s" filename))
        (comint-dynamic-list-completions
!        (mapcar 'comint-quote-filename completions)
!        filenondir))))
  
  
  ;; This is bound locally in a *Completions* buffer to the list of
***************
*** 2997,3003 ****
  
  (defvar comint-dynamic-list-completions-config nil)
  
! (defun comint-dynamic-list-completions (completions)
    "List in help buffer sorted COMPLETIONS.
  Typing SPC flushes the help buffer."
    (let ((window (get-buffer-window "*Completions*" 0)))
--- 3009,3015 ----
  
  (defvar comint-dynamic-list-completions-config nil)
  
! (defun comint-dynamic-list-completions (completions &optional 
common-substring)
    "List in help buffer sorted COMPLETIONS.
  Typing SPC flushes the help buffer."
    (let ((window (get-buffer-window "*Completions*" 0)))
***************
*** 3030,3037 ****
        (setq comint-dynamic-list-completions-config
            (current-window-configuration))
        (with-output-to-temp-buffer "*Completions*"
!       (display-completion-list completions))
!       (message "Type space to flush; repeat completion command to scroll"))
  
      ;; Read the next key, to process SPC.
      (let (key first)
--- 3042,3051 ----
        (setq comint-dynamic-list-completions-config
            (current-window-configuration))
        (with-output-to-temp-buffer "*Completions*"
!       (display-completion-list completions common-substring))
!       (if (window-minibuffer-p (selected-window))
!         (minibuffer-message " [Type space to flush; repeat completion command 
to scroll]")
!       (message "Type space to flush; repeat completion command to scroll")))
  
      ;; Read the next key, to process SPC.
      (let (key first)

Index: lisp/shell.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/shell.el,v
retrieving revision 1.158
diff -c -r1.158 shell.el
*** lisp/shell.el       8 Jan 2008 20:44:52 -0000       1.158
--- lisp/shell.el       20 Mar 2008 20:54:09 -0000
***************
*** 965,971 ****
             (save-match-data (not (string-match "[~/]" filename)))
             (eq (match-beginning 0)
                 (save-excursion (shell-backward-command 1) (point))))
!       (prog2 (message "Completing command name...")
            (shell-dynamic-complete-as-command)))))
  
  
--- 965,972 ----
             (save-match-data (not (string-match "[~/]" filename)))
             (eq (match-beginning 0)
                 (save-excursion (shell-backward-command 1) (point))))
!       (prog2 (unless (window-minibuffer-p (selected-window))
!                (message "Completing command name..."))
            (shell-dynamic-complete-as-command)))))
  
  
***************
*** 1040,1046 ****
    (interactive)
    (let ((variable (shell-match-partial-variable)))
      (if (and variable (string-match "^\\$" variable))
!       (prog2 (message "Completing variable name...")
            (shell-dynamic-complete-as-environment-variable)))))
  
  
--- 1041,1048 ----
    (interactive)
    (let ((variable (shell-match-partial-variable)))
      (if (and variable (string-match "^\\$" variable))
!       (prog2 (unless (window-minibuffer-p (selected-window))
!                (message "Completing variable name..."))
            (shell-dynamic-complete-as-environment-variable)))))

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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