home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / emacs / 2938 < prev    next >
Encoding:
Text File  |  1992-08-23  |  2.7 KB  |  63 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!wupost!sdd.hp.com!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.emacs
  4. Subject: Re: small question about going into directories with find-file
  5. Message-ID: <179io1INNh0v@early-bird.think.com>
  6. Date: 24 Aug 92 02:49:37 GMT
  7. References: <1992Aug21.153958.3937@colorado.edu> <173nldINNmrv@early-bird.think.com> <1992Aug23.165129.10498@colorado.edu>
  8. Organization: Thinking Machines Corporation, Cambridge MA, USA
  9. Lines: 51
  10. NNTP-Posting-Host: gandalf.think.com
  11.  
  12. In article <1992Aug23.165129.10498@colorado.edu> ejh@khonshu.colorado.edu (Edward J. Hartnett) writes:
  13. >In article <173nldINNmrv@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
  14. >>When you use find-file right after starting Emacs, the current buffer
  15. >>doesn't have a pathname, so your response is used as is.  But when you're
  16. >>in a buffer with a file it defaults to the buffer pathname.
  17. >Right, but that's really my question: why doesn't it take the current
  18. >buffer's pathname as the file that I want to open, and thus go into
  19. >dired in that directory?
  20.  
  21. You said this happens when you're in a buffer for a file, not a directory.
  22. In that case, "the current buffer's pathname" includes the file name.  So
  23. when you don't type anything, it means you want to open the current file
  24. again.
  25.  
  26. >>This behavior is implemented in the C routine that implements the
  27. >>read-file-name function.  It occurs whenever the third argument (the
  28. >>default value) is nil, as it is when it's called from call-interactively's
  29. >>processing of the interactive "F" argument type.  To fix it from Lisp you
  30. >>can change find-file so that it calls read-file-name explicitly to get its
  31. >>argument, and passes an explicit third argument of the current
  32. >directory.
  33. >
  34. >This last paragraph sailed about 4 inches above my head! What are the
  35. >first two arguments?
  36.  
  37. From "C-h d read-file-name":
  38.  
  39.     read-file-name:
  40.     Read file name, prompting with PROMPT and completing in directory DIR.
  41.     Value is not expanded!  You must call expand-file-name yourself.
  42.     Default name to DEFAULT if user enters a null string.
  43.     Fourth arg MUSTMATCH non-nil means require existing file's name.
  44.  
  45. So, the first two arguments are the prompt and the directory.  Thus, you
  46. would use
  47.  
  48.     (read-file-name "Find file: " nil default-directory)
  49.  
  50. to read the argument.  Here's the complete patch:
  51.  
  52. (defun find-file (filename)
  53.   "Edit file FILENAME.
  54. Switch to a buffer visiting file FILENAME,
  55. creating one if none already exists."
  56.   (interactive (list (read-file-name "Find file: " nil default-directory)))
  57.   (switch-to-buffer (find-file-noselect filename)))
  58. -- 
  59. Barry Margolin
  60. System Manager, Thinking Machines Corp.
  61.  
  62. barmar@think.com          {uunet,harvard}!think!barmar
  63.