From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#37086: Guile Ice-9 Readline with-readline-completion-function Date: Mon, 19 Aug 2019 23:00:56 -0400 Message-ID: <87imqs35h8.fsf@netris.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="199934"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: 37086@debbugs.gnu.org To: Matthew Henry Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Aug 20 05:02: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 1hzuPV-000pru-0g for guile-bugs@m.gmane.org; Tue, 20 Aug 2019 05:02:13 +0200 Original-Received: from localhost ([::1]:60950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzuPT-00049c-9r for guile-bugs@m.gmane.org; Mon, 19 Aug 2019 23:02:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44465) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzuPL-000489-Bh for bug-guile@gnu.org; Mon, 19 Aug 2019 23:02:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hzuPK-0008Nv-7k for bug-guile@gnu.org; Mon, 19 Aug 2019 23:02:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51918) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hzuPJ-0008No-VO for bug-guile@gnu.org; Mon, 19 Aug 2019 23:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hzuPJ-0002Mi-Nh for bug-guile@gnu.org; Mon, 19 Aug 2019 23:02:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 20 Aug 2019 03:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37086 X-GNU-PR-Package: guile Original-Received: via spool by 37086-submit@debbugs.gnu.org id=B37086.15662700947787 (code B ref 37086); Tue, 20 Aug 2019 03:02:01 +0000 Original-Received: (at 37086) by debbugs.gnu.org; 20 Aug 2019 03:01:34 +0000 Original-Received: from localhost ([127.0.0.1]:60739 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzuOr-000212-Lp for submit@debbugs.gnu.org; Mon, 19 Aug 2019 23:01:34 -0400 Original-Received: from world.peace.net ([64.112.178.59]:53364) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzuOo-0001y7-GI; Mon, 19 Aug 2019 23:01:31 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hzuOn-00073h-Bt; Mon, 19 Aug 2019 23:01:29 -0400 In-Reply-To: (Matthew Henry's message of "Mon, 19 Aug 2019 13:36:26 -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:9420 Archived-At: 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