home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!wupost!sdd.hp.com!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.emacs
- Subject: Re: small question about going into directories with find-file
- Message-ID: <179io1INNh0v@early-bird.think.com>
- Date: 24 Aug 92 02:49:37 GMT
- References: <1992Aug21.153958.3937@colorado.edu> <173nldINNmrv@early-bird.think.com> <1992Aug23.165129.10498@colorado.edu>
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 51
- NNTP-Posting-Host: gandalf.think.com
-
- In article <1992Aug23.165129.10498@colorado.edu> ejh@khonshu.colorado.edu (Edward J. Hartnett) writes:
- >In article <173nldINNmrv@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
- >>When you use find-file right after starting Emacs, the current buffer
- >>doesn't have a pathname, so your response is used as is. But when you're
- >>in a buffer with a file it defaults to the buffer pathname.
- >Right, but that's really my question: why doesn't it take the current
- >buffer's pathname as the file that I want to open, and thus go into
- >dired in that directory?
-
- You said this happens when you're in a buffer for a file, not a directory.
- In that case, "the current buffer's pathname" includes the file name. So
- when you don't type anything, it means you want to open the current file
- again.
-
- >>This behavior is implemented in the C routine that implements the
- >>read-file-name function. It occurs whenever the third argument (the
- >>default value) is nil, as it is when it's called from call-interactively's
- >>processing of the interactive "F" argument type. To fix it from Lisp you
- >>can change find-file so that it calls read-file-name explicitly to get its
- >>argument, and passes an explicit third argument of the current
- >directory.
- >
- >This last paragraph sailed about 4 inches above my head! What are the
- >first two arguments?
-
- From "C-h d read-file-name":
-
- read-file-name:
- Read file name, prompting with PROMPT and completing in directory DIR.
- Value is not expanded! You must call expand-file-name yourself.
- Default name to DEFAULT if user enters a null string.
- Fourth arg MUSTMATCH non-nil means require existing file's name.
-
- So, the first two arguments are the prompt and the directory. Thus, you
- would use
-
- (read-file-name "Find file: " nil default-directory)
-
- to read the argument. Here's the complete patch:
-
- (defun find-file (filename)
- "Edit file FILENAME.
- Switch to a buffer visiting file FILENAME,
- creating one if none already exists."
- (interactive (list (read-file-name "Find file: " nil default-directory)))
- (switch-to-buffer (find-file-noselect filename)))
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-