* `read-file-name' with history?
@ 2010-11-16 20:54 Elena
2010-12-10 4:13 ` Drew Adams
0 siblings, 1 reply; 5+ messages in thread
From: Elena @ 2010-11-16 20:54 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
unlike `read-string', `read-file-name' lacks an history parameter. Is
there a way to achieve such behavior?
Since `read-string' is a built-in function in C source code, I can't
examine it (well, I could examine the C sources, but I think it would
be a little difficult).
Any help? Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: `read-file-name' with history?
2010-11-16 20:54 `read-file-name' with history? Elena
@ 2010-12-10 4:13 ` Drew Adams
2010-12-10 8:49 ` egarrulo
0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2010-12-10 4:13 UTC (permalink / raw)
To: 'Elena', help-gnu-emacs
> unlike `read-string', `read-file-name' lacks an history parameter. Is
> there a way to achieve such behavior?
Correct, there is no history parameter. But it does use a history list:
`file-name-history'.
To achieve a file-name reading behavior with an arbitrary history list, you
would need to write your own file-name reading function and bind it to the
variable `read-file-name-function'. Then let-bind that var around a call to
`read-file-name.
> Since `read-string' is a built-in function in C source code, I can't
> examine it (well, I could examine the C sources, but I think it would
> be a little difficult).
What is the question here? What is the relation to your question about
`read-file-name''s history parameter?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: `read-file-name' with history?
2010-12-10 4:13 ` Drew Adams
@ 2010-12-10 8:49 ` egarrulo
2010-12-10 15:39 ` Drew Adams
0 siblings, 1 reply; 5+ messages in thread
From: egarrulo @ 2010-12-10 8:49 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
Hello Drew,
2010/12/10 Drew Adams <drew.adams@oracle.com>:
>> unlike `read-string', `read-file-name' lacks an history parameter. Is
>> there a way to achieve such behavior?
>
> Correct, there is no history parameter. But it does use a history list:
> `file-name-history'.
>
> To achieve a file-name reading behavior with an arbitrary history list, you
> would need to write your own file-name reading function and bind it to the
> variable `read-file-name-function'. Then let-bind that var around a call to
> `read-file-name.
>
>> Since `read-string' is a built-in function in C source code, I can't
>> examine it (well, I could examine the C sources, but I think it would
>> be a little difficult).
>
> What is the question here? What is the relation to your question about
> `read-file-name''s history parameter?
My problem is that writing such a function is beyond my current
capabilities. I usually manage to achieve such goals by modifying
some existing Lisp code. In this case, however, no Lisp code is
available. That's why I was asking for pointers.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: `read-file-name' with history?
2010-12-10 8:49 ` egarrulo
@ 2010-12-10 15:39 ` Drew Adams
2010-12-10 16:05 ` egarrulo
0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2010-12-10 15:39 UTC (permalink / raw)
To: 'egarrulo'; +Cc: help-gnu-emacs
> >> unlike `read-string', `read-file-name' lacks an history
> >> parameter. Is there a way to achieve such behavior?
> >
> > Correct, there is no history parameter. But it does use a
> > history list: `file-name-history'.
> >
> > To achieve a file-name reading behavior with an arbitrary
> > history list, you would need to write your own file-name
> > reading function and bind it to the variable
> > `read-file-name-function'. Then let-bind that var around
> > a call to `read-file-name.
> >
> >> Since `read-string' is a built-in function in C source
> >> code, I can't examine it (well, I could examine the C
> >> sources, but I think it would be a little difficult).
> >
> > What is the question here? What is the relation to your
> > question about `read-file-name''s history parameter?
>
> My problem is that writing such a function is beyond my current
> capabilities. I usually manage to achieve such goals by modifying
> some existing Lisp code. In this case, however, no Lisp code is
> available. That's why I was asking for pointers.
OK, but the Lisp code for `read-file-name' is available.
From there you can see that `file-name-history' is used.
Instead of defining your own function for `read-file-name-function', you can
also just define a function that explicitly adds whatever file name is read to a
history that you pass it. In order to not also add that name to the regular
`file-name-history' you need to bind that var so it gets restored when your
function exits. For example:
(defvar my-history () "Once upon a time...")
(defun my-read-file-name (prompt &optional dir default-filename
mustmatch initial predicate history)
(let* ((file-name-history file-name-history)
(file (read-file-name prompt dir default-filename
mustmatch initial predicate)))
(add-to-list history file)
file))
Now try:
(my-read-file-name "File: " nil nil t nil nil 'my-history)
C-h v my-history
C-h v file-name-history
And compare with: (read-file-name "File: " nil nil t)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: `read-file-name' with history?
2010-12-10 15:39 ` Drew Adams
@ 2010-12-10 16:05 ` egarrulo
0 siblings, 0 replies; 5+ messages in thread
From: egarrulo @ 2010-12-10 16:05 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
Thank you Drew. Another guy kindly sent me another implementation of
`read-file-name' with history. I'll study both examples.
Indeed you are right: `read-file-name' is defined into "minibuffer.el"
in Emacs 23.2. I'm using Emacs 22.3, where it is defined in C source,
therefore I didn't notice.
Have a nice day ;-)
Elena
2010/12/10 Drew Adams <drew.adams@oracle.com>:
>> >> unlike `read-string', `read-file-name' lacks an history
>> >> parameter. Is there a way to achieve such behavior?
>> >
>> > Correct, there is no history parameter. But it does use a
>> > history list: `file-name-history'.
>> >
>> > To achieve a file-name reading behavior with an arbitrary
>> > history list, you would need to write your own file-name
>> > reading function and bind it to the variable
>> > `read-file-name-function'. Then let-bind that var around
>> > a call to `read-file-name.
>> >
>> >> Since `read-string' is a built-in function in C source
>> >> code, I can't examine it (well, I could examine the C
>> >> sources, but I think it would be a little difficult).
>> >
>> > What is the question here? What is the relation to your
>> > question about `read-file-name''s history parameter?
>>
>> My problem is that writing such a function is beyond my current
>> capabilities. I usually manage to achieve such goals by modifying
>> some existing Lisp code. In this case, however, no Lisp code is
>> available. That's why I was asking for pointers.
>
> OK, but the Lisp code for `read-file-name' is available.
> From there you can see that `file-name-history' is used.
>
> Instead of defining your own function for `read-file-name-function', you can
> also just define a function that explicitly adds whatever file name is read to a
> history that you pass it. In order to not also add that name to the regular
> `file-name-history' you need to bind that var so it gets restored when your
> function exits. For example:
>
> (defvar my-history () "Once upon a time...")
>
> (defun my-read-file-name (prompt &optional dir default-filename
> mustmatch initial predicate history)
> (let* ((file-name-history file-name-history)
> (file (read-file-name prompt dir default-filename
> mustmatch initial predicate)))
> (add-to-list history file)
> file))
>
> Now try:
> (my-read-file-name "File: " nil nil t nil nil 'my-history)
>
> C-h v my-history
> C-h v file-name-history
>
> And compare with: (read-file-name "File: " nil nil t)
>
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-12-10 16:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-16 20:54 `read-file-name' with history? Elena
2010-12-10 4:13 ` Drew Adams
2010-12-10 8:49 ` egarrulo
2010-12-10 15:39 ` Drew Adams
2010-12-10 16:05 ` egarrulo
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).