help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: A question about interactive


From: Drew Adams
Subject: RE: A question about interactive
Date: Fri, 22 Mar 2013 00:18:43 -0700

>>> (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 me  
> (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.

I meant this - read the file name in the `interactive' spec:

(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.
                






reply via email to

[Prev in Thread] Current Thread [Next in Thread]