GNU bug report logs -
#37086
Guile Ice-9 Readline with-readline-completion-function
Previous Next
Reported by: Matthew Henry <mcthenry <at> gmail.com>
Date: Mon, 19 Aug 2019 18:02:02 UTC
Severity: normal
Tags: notabug
Done: Mark H Weaver <mhw <at> netris.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37086 in the body.
You can then email your comments to 37086 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-guile <at> gnu.org
:
bug#37086
; Package
guile
.
(Mon, 19 Aug 2019 18:02:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Matthew Henry <mcthenry <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-guile <at> gnu.org
.
(Mon, 19 Aug 2019 18:02:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Seen in: guile (GNU Guile) 2.2.4
When using the with-readline-completion-function, the passed readline
uses the default (apropos) completion function instead of the one
provided to with-readline-completion-function.
I believe that this is because root/guile-readline/ice-9/readline.scm
has defined with-readline-completion-function as a function instead of
as a macro. The readline provided in thunk is executed before the
body of with-readline-completion-function executes and overrides
*readline-completion-function*.
As an aside, I think the API would be better if the completion
function could be provided to readline directly.
Attached is a sample program.
Below is sample output of a run of the attached program. You can see
that it's autocompleting Guile functions and variables (the default
apropos completion) rather than the provided one which should have had
only 3 options with just one starting in "th".
;;;;;;;;;;;;;;;;;;;;;;;;;;;
Prompt:
Display all 1859 possibilities? (y or n)
Prompt: th
the-eof-object the-scm-module thread-exited? thunk?
the-root-module thread? throw
Prompt: th
[readline-completion-bug.scm (application/octet-stream, attachment)]
Information forwarded
to
bug-guile <at> gnu.org
:
bug#37086
; Package
guile
.
(Tue, 20 Aug 2019 01:08:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 37086 <at> debbugs.gnu.org (full text, mbox):
I'm early in my Scheme journey, but here's a suggested fix:
(define-syntax-rule (with-readline-completion-function completer expr ...)
"With @var{completer} as readline completion function, call @var{expr ...}."
(let ((old-completer *readline-completion-function*))
(dynamic-wind
(lambda ()
(set! *readline-completion-function* completer))
(lambda () expr ...)
(lambda ()
(set! *readline-completion-function* old-completer)))))
(export with-readline-completion-function)
Information forwarded
to
bug-guile <at> gnu.org
:
bug#37086
; Package
guile
.
(Tue, 20 Aug 2019 03:02:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 37086 <at> debbugs.gnu.org (full text, mbox):
tags 37086 + notabug
close 37086
thanks
Hi Matthew,
Matthew Henry <mcthenry <at> gmail.com> writes:
> Seen in: guile (GNU Guile) 2.2.4
>
> When using the with-readline-completion-function, the passed readline
> uses the default (apropos) completion function instead of the one
> provided to with-readline-completion-function.
>
> I believe that this is because root/guile-readline/ice-9/readline.scm
> has defined with-readline-completion-function as a function instead of
> as a macro. The readline provided in thunk is executed before the
> body of with-readline-completion-function executes and overrides
> *readline-completion-function*.
>
> As an aside, I think the API would be better if the completion
> function could be provided to readline directly.
>
> Attached is a sample program.
>
> Below is sample output of a run of the attached program. You can see
> that it's autocompleting Guile functions and variables (the default
> apropos completion) rather than the provided one which should have had
> only 3 options with just one starting in "th".
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;
> Prompt:
> Display all 1859 possibilities? (y or n)
> Prompt: th
> the-eof-object the-scm-module thread-exited? thunk?
> the-root-module thread? throw
> Prompt: th
>
> (use-modules (ice-9 readline))
>
> (with-readline-completion-function
> (make-completion-function '("one" "two" "three"))
> (readline "Prompt: "))
The problem is that 'with-readline-completion-function' expects a
"thunk" as the second argument. A "thunk" is a procedure that takes no
arguments. Typically this means that you wrap the relevant code within
(lambda () ...), like this:
(use-modules (ice-9 readline))
(with-readline-completion-function
(make-completion-function '("one" "two" "three"))
(lambda () (readline "Prompt: ")))
> I'm early in my Scheme journey, but here's a suggested fix:
>
> (define-syntax-rule (with-readline-completion-function completer expr ...)
> "With @var{completer} as readline completion function, call @var{expr ...}."
> (let ((old-completer *readline-completion-function*))
> (dynamic-wind
> (lambda ()
> (set! *readline-completion-function* completer))
> (lambda () expr ...)
> (lambda ()
> (set! *readline-completion-function* old-completer)))))
>
> (export with-readline-completion-function)
This is fine, but it's a different API. It's true that you need to use
a macro if you want to avoid wrapping the body within (lambda () ...),
but just like 'dynamic-wind' itself, 'with-readline-completion-function'
was designed to be an ordinary procedure that accepts the body
expression(s) as a THUNK.
Happy hacking!
Mark
Added tag(s) notabug.
Request was from
Mark H Weaver <mhw <at> netris.org>
to
control <at> debbugs.gnu.org
.
(Tue, 20 Aug 2019 03:02:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
37086 <at> debbugs.gnu.org and Matthew Henry <mcthenry <at> gmail.com>
Request was from
Mark H Weaver <mhw <at> netris.org>
to
control <at> debbugs.gnu.org
.
(Tue, 20 Aug 2019 03:02:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-guile <at> gnu.org
:
bug#37086
; Package
guile
.
(Tue, 20 Aug 2019 14:34:02 GMT)
Full text and
rfc822 format available.
Message #18 received at 37086 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Ah gotcha. Thanks!
On Mon, Aug 19, 2019 at 11:01 PM Mark H Weaver <mhw <at> netris.org> wrote:
> tags 37086 + notabug
> close 37086
> thanks
>
> Hi Matthew,
>
> Matthew Henry <mcthenry <at> gmail.com> writes:
>
> > Seen in: guile (GNU Guile) 2.2.4
> >
> > When using the with-readline-completion-function, the passed readline
> > uses the default (apropos) completion function instead of the one
> > provided to with-readline-completion-function.
> >
> > I believe that this is because root/guile-readline/ice-9/readline.scm
> > has defined with-readline-completion-function as a function instead of
> > as a macro. The readline provided in thunk is executed before the
> > body of with-readline-completion-function executes and overrides
> > *readline-completion-function*.
> >
> > As an aside, I think the API would be better if the completion
> > function could be provided to readline directly.
> >
> > Attached is a sample program.
> >
> > Below is sample output of a run of the attached program. You can see
> > that it's autocompleting Guile functions and variables (the default
> > apropos completion) rather than the provided one which should have had
> > only 3 options with just one starting in "th".
> >
> > ;;;;;;;;;;;;;;;;;;;;;;;;;;;
> > Prompt:
> > Display all 1859 possibilities? (y or n)
> > Prompt: th
> > the-eof-object the-scm-module thread-exited? thunk?
> > the-root-module thread? throw
> > Prompt: th
> >
> > (use-modules (ice-9 readline))
> >
> > (with-readline-completion-function
> > (make-completion-function '("one" "two" "three"))
> > (readline "Prompt: "))
>
> The problem is that 'with-readline-completion-function' expects a
> "thunk" as the second argument. A "thunk" is a procedure that takes no
> arguments. Typically this means that you wrap the relevant code within
> (lambda () ...), like this:
>
> (use-modules (ice-9 readline))
>
> (with-readline-completion-function
> (make-completion-function '("one" "two" "three"))
> (lambda () (readline "Prompt: ")))
>
> > I'm early in my Scheme journey, but here's a suggested fix:
> >
> > (define-syntax-rule (with-readline-completion-function completer expr
> ...)
> > "With @var{completer} as readline completion function, call @var{expr
> ...}."
> > (let ((old-completer *readline-completion-function*))
> > (dynamic-wind
> > (lambda ()
> > (set! *readline-completion-function* completer))
> > (lambda () expr ...)
> > (lambda ()
> > (set! *readline-completion-function* old-completer)))))
> >
> > (export with-readline-completion-function)
>
> This is fine, but it's a different API. It's true that you need to use
> a macro if you want to avoid wrapping the body within (lambda () ...),
> but just like 'dynamic-wind' itself, 'with-readline-completion-function'
> was designed to be an ordinary procedure that accepts the body
> expression(s) as a THUNK.
>
> Happy hacking!
> Mark
>
[Message part 2 (text/html, inline)]
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 18 Sep 2019 11:24:11 GMT)
Full text and
rfc822 format available.
This bug report was last modified 5 years and 273 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.