home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / shel-comp2.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  2.0 KB  |  63 lines

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!think!mintaka!mintaka.lcs.mit.edu!sra Mon Mar 19 12:41:53 1990
  2. ;Article 825 of gnu.emacs.bug:
  3. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!think!mintaka!mintaka.lcs.mit.edu!sra
  4. ;>From sra@lcs.mit.edu (Rob Austein)
  5. ;Newsgroups: gnu.emacs.bug
  6. ;Subject: Completing filenames in shell-mode
  7. ;Message-ID: <1990Mar16.054548.26107@mintaka.lcs.mit.edu>
  8. ;Date: 16 Mar 90 05:45:48 GMT
  9. ;Sender: news@mintaka.lcs.mit.edu
  10. ;Distribution: gnu
  11. ;Organization: ITS Preservation Society
  12. ;Lines: 47
  13. ;
  14. ;Here's a feature I've wanted for a while.  The following hack allows
  15. ;filename completion in a shell-mode buffer.  The behavior is basicly
  16. ;like tcsh's completion.  It doesn't do pop-up windows because there's
  17. ;no good way to clean them up automaticly except from the minibuffer.
  18.  
  19. ;;; allspice.lcs.mit.edu:/u/sra/shell-file-complete.el, 15-Mar-1990 21:50, sra
  20.  
  21. (defvar shell-filename-chars
  22.   "/~a-zA-Z0-9---_#=+.,"
  23.   "*Characters that shell-filename-complete considers legitimate.")
  24.  
  25. (defun shell-filename-complete ()
  26.   (interactive)
  27.   (let (start name directory file completion)
  28.     (save-excursion
  29.       (beginning-of-line)
  30.       (setq start (point)))
  31.     (save-excursion
  32.       (skip-chars-backward shell-filename-chars start)
  33.       (setq start (point)))
  34.     (setq name (buffer-substring start (point))
  35.       directory (file-name-directory name)
  36.       file (file-name-nondirectory name))
  37.     (cond
  38.      ((string= name "")
  39.       (beep))
  40.      ((and directory (not (file-directory-p directory)))
  41.       (beep))
  42.      ((not (setq completion
  43.          (file-name-completion file (or directory default-directory))))
  44.       (beep))
  45.      ((eq t completion)
  46.       (message "[Sole completion]"))
  47.      ((string= completion file)
  48.       (message
  49.        (mapconcat 'identity
  50.           (file-name-all-completions
  51.            file (or directory default-directory)) " ")))
  52.      (t
  53.       (insert (substring completion (length file)))))))
  54.  
  55. (setq shell-mode-hook
  56.       (function
  57.        (lambda ()
  58.      (define-key shell-mode-map "\C-c\C-i" 'shell-filename-complete))))
  59.  
  60. ;--Rob Austein
  61.  
  62.  
  63.