* A question about interactive
@ 2013-03-21 6:46 C K Kashyap
2013-03-21 13:24 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: C K Kashyap @ 2013-03-21 6:46 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 491 bytes --]
Here's what I want to do - I'd like to write utility functions in
different el files and store them in a particular directory. then write a
function in .emacs - say - my-script-load ... What I'd like it to do is
this
(defun my-script-load (script-name)
(interactive "fEnter script name: ")
(load 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?
Regards,
Kashyap
[-- Attachment #2: Type: text/html, Size: 718 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: A question about interactive
2013-03-21 6:46 A question about interactive C K Kashyap
@ 2013-03-21 13:24 ` Drew Adams
2013-03-22 6:59 ` C K Kashyap
0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2013-03-21 13:24 UTC (permalink / raw)
To: 'C K Kashyap', help-gnu-emacs
> Here's what I want to do - I'd like to write utility
> functions in different el files and store them in a
> particular directory. then write a function in .emacs
> - say - my-script-load ... What I'd like it to do is
> this: (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'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: A question about interactive
2013-03-21 13:24 ` Drew Adams
@ 2013-03-22 6:59 ` C K Kashyap
2013-03-22 7:18 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: C K Kashyap @ 2013-03-22 6:59 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 983 bytes --]
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.
Regards,
Kashyap
On Thu, Mar 21, 2013 at 6:54 PM, Drew Adams <drew.adams@oracle.com> wrote:
> > Here's what I want to do - I'd like to write utility
> > functions in different el files and store them in a
> > particular directory. then write a function in .emacs
> > - say - my-script-load ... What I'd like it to do is
> > this: (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'.
>
>
[-- Attachment #2: Type: text/html, Size: 1640 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: A question about interactive
2013-03-22 6:59 ` C K Kashyap
@ 2013-03-22 7:18 ` Drew Adams
2013-03-22 11:24 ` C K Kashyap
0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2013-03-22 7:18 UTC (permalink / raw)
To: 'C K Kashyap'; +Cc: help-gnu-emacs
>>> (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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: A question about interactive
2013-03-22 7:18 ` Drew Adams
@ 2013-03-22 11:24 ` C K Kashyap
2013-03-22 14:45 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: C K Kashyap @ 2013-03-22 11:24 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1760 bytes --]
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 <drew.adams@oracle.com> 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.
>
>
>
>
>
[-- Attachment #2: Type: text/html, Size: 3206 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: A question about interactive
2013-03-22 11:24 ` C K Kashyap
@ 2013-03-22 14:45 ` Drew Adams
0 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2013-03-22 14:45 UTC (permalink / raw)
To: 'C K Kashyap'; +Cc: help-gnu-emacs
>> (interactive (list (read-file-name "Filename: " "c:/"))
There should have been another `)' at the end of that; sorry.
> when I run f M-x f - it asks for the file name but it does
> not insert into the buffer.
It inserts the file name. FILE is a file name. Maybe you are looking for
`insert-file', which inserts file contents, and not `insert' (which you had in
your code).
> 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?
In the Elisp manual, use `i interactive' to find node `Using Interactive'. Read
the 3rd bullet about argument ARG-DESCRIPTOR.
The manual is your friend. Please look there first. Use `i' to find stuff.
Use `C-s' or `C-M-s' to search if you cannot find something using `i'.
Use `report-emacs-bug' if you cannot easily find something that is in the
manual, e.g., if you think another index entry should be added.
Please use plain text (not HTML) for the Emacs help list. Thx.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-03-22 14:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-21 6:46 A question about interactive C K Kashyap
2013-03-21 13:24 ` Drew Adams
2013-03-22 6:59 ` C K Kashyap
2013-03-22 7:18 ` Drew Adams
2013-03-22 11:24 ` C K Kashyap
2013-03-22 14:45 ` Drew Adams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).