|
From: | C K Kashyap |
Subject: | Re: A question about interactive |
Date: | Fri, 22 Mar 2013 16:54:13 +0530 |
>>> (interactive "fEnter script name: ")
>>> Now, the problem is that the ineractive "f" seems to
>>> use the current buffer location as the starting point.
>>> How can I change that?
>>
>> In the `interactive' spec, let-bind `default-directory'
>> and then read the file name with `read-file-name'.
>> See the doc for `interactive'.
>
> Thanks a lot Drew ... using read-file-name worked for meI meant this - read the file name in the `interactive' spec:
> (defun f ()
> (interactive)
> (setq fn (read-file-name "Enter filename" "C:/"))
> (insert fn))
>
> I did not have to do the let-binding of default-directory -
> actually I do not know how to do it either. It'll be great if
> you could show me what you meant.
(defun f (file)
(interactive (list (read-file-name "Filename: " "c:/"))
(insert file))
I misled you wrt `default-directory'. There's no need to let-bind
`default-directory' around `read-file-name', since you can just pass the value
as the optional second arg, as you did. I forgot about that. I was thinking of
this (equivalent, but unnecessary):
(let ((default-directory "c:/"))
(read-file-name "Filename: "))
Sorry for the extra noise.
[Prev in Thread] | Current Thread | [Next in Thread] |