[comp.emacs] better insert file name function

kautz@allegra.UUCP (09/10/87)

Here's a simple but very useful function for use in shell mode.  Like
an earlier submission, it reads a file name in the minibuffer and then
inserts it into the current buffer.  The extra feature is that it does
not include the entire path prefix on the file name unless it is
necessary.

Your shell mode hook should include something like:

   (local-set-key "\C-c\C-f" 'insert-file-name-tail)

The function is simply:

(defun insert-file-name-tail (name) 
 "Prompts for a file or directory name and inserts that name after point.
 Does not include unnecessary directory path prefixes.
 The name may be non-existent.  Useful in Shell mode."  
   (interactive "FInsert file name: ")
   (if (string-match (concat "^" default-directory) name)
      (setq name (substring name (match-end 0))))
   (insert name))