Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!seismo!rochester!pt.cs.cmu.edu!k.cs.cmu.edu!rgs From: rgs@k.cs.cmu.edu.UUCP Newsgroups: comp.emacs Subject: Re: file completion in the shell buffer Message-ID: <1112@k.cs.cmu.edu> Date: Fri, 20-Mar-87 15:40:12 EST Article-I.D.: k.1112 Posted: Fri Mar 20 15:40:12 1987 Date-Received: Sun, 22-Mar-87 21:19:08 EST References: <8703201627.AA19093@arthur.cs.purdue.edu> Organization: Carnegie-Mellon University, CS/RI Lines: 137 > I am having a real hard time adjusting to the fact that I can't get > file completion in the Gnu-emacs shell buffer under 4.3bsd (Gnu 18.36). > ... > Has anyone worked with this? I ran into the same problem and took some time to try to solve it. I found it very frustrating that I could not find any standard functions that would allow me to do the job easily, but I did come to the conclusion that it was possible. The code that follows isn't pretty, since I was concentrating more on getting the thing working than on making it elegant, but it does seem to work: -------------------- File filename.el -------------------- (provide 'filename) ; Filename completion facilities. ; This package provides the function "get-file-name" which prompts ; the user for a filename given an initial prefix. Its semantics are ; not quite identical to normal filename completion for gnu-emacs, but ; tends to more resemble a cross between Gnu and Gosling emacs. ;; Robert Stockton (rgs@SPICE.CS.CMU.EDU) 11/86 ;; Created. (if (not (boundp 'file-map)) (progn (setq file-map (copy-keymap minibuffer-local-completion-map)) (define-key file-map "?" 'filename-show-completions) (define-key file-map "\^I" 'filename-do-completion) (define-key file-map " " 'filename-do-completion))) (defun get-file-name (prompt prefix) (read-from-minibuffer prompt prefix file-map nil)) (defun filename-show-completions () (interactive) (insert "\nMaking completion list...") (sit-for 0) (delete-backward-char 26) (let* ((string (buffer-string )) (dir1 (file-name-directory string)) (dir (if dir1 (expand-file-name dir1) ".")) (subname (file-name-nondirectory string)) (comp (file-name-all-completions subname dir))) (erase-buffer) (if dir1 (insert-string dir)) (insert-string subname) (if comp (with-output-to-temp-buffer " *Completions*" (display-completion-list (sort (file-name-all-completions subname dir) 'string<))) (ding) (filename-minibuffer-message "[No Completions]")))) (defun filename-do-completion () (interactive) (let* ((string (buffer-string )) (dir1 (file-name-directory string)) (dir (if dir1 (expand-file-name dir1) ".")) (subname (file-name-nondirectory string)) (comp (file-name-completion subname dir))) (erase-buffer) (if dir1 (insert dir)) (cond ((and (stringp comp) (eq (file-name-completion comp dir) t)) (insert comp) (exit-minibuffer)) ((equal comp subname) (insert subname) (if (file-exists-p (concat dir subname)) (filename-minibuffer-message "[Complete, but not unique]") (filename-show-completions))) ((stringp comp) (insert comp)) (comp (insert-string subname) (exit-minibuffer)) (t (insert subname) (ding) (filename-minibuffer-message "[No Match]"))))) (defun filename-minibuffer-message (message) (save-excursion (insert " " message)) (sit-for 2) (delete-char (+ 1 (length message)))) ---------------- End filename.el; begin shell.el extensions ---------------- ;; Robert Stockton (rgs@SPICE.CS.CMU.EDU) 11/12/86 ;; Added expand-inline-filename (analogous to GosMacs version). ;; Added shell-beginning-of-line. (require 'filename) (defun shell-beginning-of-line () "Go to the beginning of the shell command line. If the point is not within the current command line, just go the to beginning of the line instead." (interactive) (let ((start (process-mark (get-buffer-process (current-buffer))))) (if (>= (point) start) (goto-char start) (beginning-of-line)))) (defun expand-inline-filename () "Attempts to complete the filename beneath the point, prompting if necessary. Attempts to locate a valid completion for the current filename and places it back on the command line. If no unique completion is found, prompts for a completion in the minibuffer." (interactive) (require 'filename) (let (p) (save-excursion (re-search-backward "\\s ") (setq p (+ (point) 1))) (let* ((name (buffer-substring p (point))) (dir (or (file-name-directory name) "./")) (subname (file-name-nondirectory name)) (comp (file-name-completion subname dir)) (string (cond ((stringp comp) comp) (subname))) (fullstring (concat (file-name-directory name) string)) (fullname (if (eq (file-name-completion string dir) t) fullstring (get-file-name "File: " fullstring)))) (delete-region p (point)) (insert fullname)))) -------------------- End shell.el extensions -------------------- Robert Stockton ARPA: rgs@CMU-CS-SPICE.ARPA UUCP: ...!seismo!cmu-cs-k!rgs ...!seismo!rgs@CMU-CS-SPICE