From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Matthew Henry Newsgroups: gmane.lisp.guile.bugs Subject: bug#37086: Guile Ice-9 Readline with-readline-completion-function Date: Tue, 20 Aug 2019 07:35:21 -0400 Message-ID: References: <87imqs35h8.fsf@netris.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000bd385a05908ada55" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="138723"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 37086@debbugs.gnu.org To: Mark H Weaver Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Aug 20 16:34:14 2019 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i05DB-000ZxJ-1v for guile-bugs@m.gmane.org; Tue, 20 Aug 2019 16:34:13 +0200 Original-Received: from localhost ([::1]:38028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i05D9-0004Ms-Tt for guile-bugs@m.gmane.org; Tue, 20 Aug 2019 10:34:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54841) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i05D2-0004Kq-Fd for bug-guile@gnu.org; Tue, 20 Aug 2019 10:34:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i05D0-0004Vi-Vv for bug-guile@gnu.org; Tue, 20 Aug 2019 10:34:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52943) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i05D0-0004VU-TA for bug-guile@gnu.org; Tue, 20 Aug 2019 10:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i05D0-00076g-HK for bug-guile@gnu.org; Tue, 20 Aug 2019 10:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matthew Henry Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 20 Aug 2019 14:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37086 X-GNU-PR-Package: guile X-GNU-PR-Keywords: notabug Original-Received: via spool by 37086-submit@debbugs.gnu.org id=B37086.156631160427241 (code B ref 37086); Tue, 20 Aug 2019 14:34:02 +0000 Original-Received: (at 37086) by debbugs.gnu.org; 20 Aug 2019 14:33:24 +0000 Original-Received: from localhost ([127.0.0.1]:33531 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i05CO-00075I-2W for submit@debbugs.gnu.org; Tue, 20 Aug 2019 10:33:24 -0400 Original-Received: from mail-wr1-f46.google.com ([209.85.221.46]:43138) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i02QN-0004g2-9C for 37086@debbugs.gnu.org; Tue, 20 Aug 2019 07:35:40 -0400 Original-Received: by mail-wr1-f46.google.com with SMTP id y8so12015970wrn.10 for <37086@debbugs.gnu.org>; Tue, 20 Aug 2019 04:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IJgtVm0rTa7X64F4oRhID1IBq0Ore0aji+DvjHXec70=; b=OVG4KO8pT+xF3KO2chShHavEYO6UebVt80F1s/Gw3n0GzEsHt2xhFp9YuOiMPs4/kg kURdx2/7UrLO2TnOPSiRmU8ySsiaoRJIxP0qIMLt+I0M8MKtHEJC+Dl9HcXttwDa/7R1 IR0MQJw9D3yPABOEVsPoxshqFw6ygS5DPJeYgYuAlDI9fVUUdF6wTmBjZYlYgOf1Lkm3 qxcXHNPy8CE8qoe2MMiBSAzxAyju2axyzzi3Z8Kp8679wLJCkuqEfqlN1GeCUG0EOzoh M9EKToaIDViiynKc+dFIFCRcpl607YQVpA5BUqPHqgyv9p8LXK5O28fiUZnGEctlsM6J X96w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IJgtVm0rTa7X64F4oRhID1IBq0Ore0aji+DvjHXec70=; b=cWfXb6uZ/XA4TDRewb2ZSiakF99MhKsdXRMkCBaDLeD54XH1T9m3TtIckOtwL4IXoM Hc046NqLN4MWW8vokinsihLMnVOrFtoA0Mp5qgbzcZRizPdKp0cPPm6ctN2Prp4Gbo4J mgAkZ8vpn7WqYPq5keT7M3pPLDgAAlDe/Uk0kIDsNy9XCPXrfx5Dn6IbGP+6OZ3y5mnI quhC2wCSYTk7OuZZpB8IHv7/4zdjSNToA1cWyAx8D/GqdC2HL5jQKtLGfTIMdmjyB7hD HVqwM4Le6aRp2Y+nJb2hBVFlnKLjY1Fc9VYGRevGFPFL9lID+Xcna/pc/epjMsim+rmN L+6A== X-Gm-Message-State: APjAAAWszmUjIojLx0Nw9KolPMUSvotPqC6oH5oa6WsGQHNEM7erXIl/ jXmYrQsIbnnmM289YMs23w35VTz+JUfZElkAAndm0g== X-Google-Smtp-Source: APXvYqw2H7RroCB44W7nFQnOxkxNOJvUo3bmWHeWfbB8buxmkQ4Fa9jgDOaW2d7VyjIyLJ1zjKCQO/LNWyt9TdqViNA= X-Received: by 2002:adf:8043:: with SMTP id 61mr34177923wrk.115.1566300933272; Tue, 20 Aug 2019 04:35:33 -0700 (PDT) In-Reply-To: <87imqs35h8.fsf@netris.org> X-Mailman-Approved-At: Tue, 20 Aug 2019 10:33:22 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:9421 Archived-At: --000000000000bd385a05908ada55 Content-Type: text/plain; charset="UTF-8" Ah gotcha. Thanks! On Mon, Aug 19, 2019 at 11:01 PM Mark H Weaver wrote: > tags 37086 + notabug > close 37086 > thanks > > Hi Matthew, > > Matthew Henry 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 > --000000000000bd385a05908ada55 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Ah gotcha.=C2=A0 Thanks!

On Mon, Aug 19, 2019 at 11:01 = PM Mark H Weaver <mhw@netris.org&g= t; wrote:
tags 3= 7086 + notabug
close 37086
thanks

Hi Matthew,

Matthew Henry <m= cthenry@gmail.com> writes:

> Seen in: guile (GNU Guile) 2.2.4
>
> When using the with-readline-completion-function, the passed readline<= br> > 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<= br> > has defined with-readline-completion-function as a function instead of=
> as a macro.=C2=A0 The readline provided in thunk is executed before th= e
> 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.=C2=A0 You can= see
> that it's autocompleting Guile functions and variables (the defaul= t
> 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=C2=A0 =C2=A0the-scm-module=C2=A0 =C2=A0thread-exited?= =C2=A0 =C2=A0thunk?
> the-root-module=C2=A0 thread?=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 throw<= br> > Prompt: th
>
> (use-modules (ice-9 readline))
>
> (with-readline-completion-function
>=C2=A0 (make-completion-function '("one" "two" = "three"))
>=C2=A0 (readline "Prompt: "))

The problem is that 'with-readline-completion-function' expects a "thunk" as the second argument.=C2=A0 A "thunk" is a pr= ocedure that takes no
arguments.=C2=A0 Typically this means that you wrap the relevant code withi= n
(lambda () ...), like this:

=C2=A0 (use-modules (ice-9 readline))

=C2=A0 (with-readline-completion-function
=C2=A0 =C2=A0(make-completion-function '("one" "two"= ; "three"))
=C2=A0 =C2=A0(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 = ...)
>=C2=A0 =C2=A0"With @var{completer} as readline completion function= , call @var{expr ...}."
>=C2=A0 =C2=A0(let ((old-completer *readline-completion-function*))
>=C2=A0 =C2=A0 =C2=A0(dynamic-wind
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda ()
>=C2=A0 =C2=A0 =C2=A0(set! *readline-completion-function* completer)) >=C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda () expr ...)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda ()
>=C2=A0 =C2=A0 =C2=A0(set! *readline-completion-function* old-completer)= ))))
>
> (export with-readline-completion-function)

This is fine, but it's a different API.=C2=A0 It's true that you ne= ed 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.

=C2=A0 =C2=A0Happy hacking!
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Mark
--000000000000bd385a05908ada55--