Thanks Drew ... After defining f this way (defun f (file) (interactive (list (read-file-name "Filename: " "c:/")) (insert file)) when I run f M-x f - it asks for the file name but it does not insert into the buffer. I was not able to read about this in C-h-f interactive - Can you explain what's happening here - interactive is supposed to take in a string as its argument -how is it working with a list? Regards, Kashyap On Fri, Mar 22, 2013 at 12:48 PM, Drew Adams wrote: > >>> (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. > > > > >