From unknown Tue Jun 17 20:10:28 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#37086 <37086@debbugs.gnu.org> To: bug#37086 <37086@debbugs.gnu.org> Subject: Status: Guile Ice-9 Readline with-readline-completion-function Reply-To: bug#37086 <37086@debbugs.gnu.org> Date: Wed, 18 Jun 2025 03:10:28 +0000 retitle 37086 Guile Ice-9 Readline with-readline-completion-function reassign 37086 guile submitter 37086 Matthew Henry severity 37086 normal tag 37086 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 19 14:01:28 2019 Received: (at submit) by debbugs.gnu.org; 19 Aug 2019 18:01:28 +0000 Received: from localhost ([127.0.0.1]:60503 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzlyC-0005fX-9f for submit@debbugs.gnu.org; Mon, 19 Aug 2019 14:01:28 -0400 Received: from lists.gnu.org ([209.51.188.17]:36621) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzlaG-000553-C8 for submit@debbugs.gnu.org; Mon, 19 Aug 2019 13:36:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49215) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzlaF-0008WP-4W for bug-guile@gnu.org; Mon, 19 Aug 2019 13:36:43 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hzlaE-0005Hq-0K for bug-guile@gnu.org; Mon, 19 Aug 2019 13:36:43 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:38828) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hzlaD-0005H8-Pt for bug-guile@gnu.org; Mon, 19 Aug 2019 13:36:41 -0400 Received: by mail-wm1-x334.google.com with SMTP id m125so281664wmm.3 for ; Mon, 19 Aug 2019 10:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=UHtTIvkK9eUO08eBxn0XcxwSOyc40yzsf/0eOicrjc4=; b=LhgpORkSC+v+I3qEPS+7EiBTQ/GxppOTFqJSNxPMf2uoUvkCCj21tK4oauosTJWT5e 9vdKQUnmY23QqG34IBWMkB+P+7e13hh4JYmkF2D4phrZOoplQih1zsLEeKpMkDHv4VA3 JDCW2JUzJUAMQdm6QKQH5BlkhqWGzqh48TAA6uwPOGG7rKwuoFygalxb6vOyX2c8SYlv N3yW0geU02bOwzEU9SfWBBMH9jCc85G5f9Oq4+kpA7Y3EGNOTAOMtUeh5HIMJ1y41EQJ DOfCCLcSL0VCRkzAolssZsqvGC2ba7p2ba8J3GcF+ZamnqXXTn7PlvDbolQdV5ioHKkN 1Awg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=UHtTIvkK9eUO08eBxn0XcxwSOyc40yzsf/0eOicrjc4=; b=Ba5TwBgz36qFv+gArmS34Mf4E87WkNYay0L/XkjFi04XW2M5riJHsRQvfkXvsET9Od JLWEzbTovvvp1YZU88DhrueJtAqgoIbccUgBqJQzBI6ihSSa+asjllh1MORvPm71XLYK tzd1c6sbLFY0dlP/jQloZKQWLx130hPZX+unQm3wD4badEqdqn56FgEJhWEk2k1WAqFQ XQLXggnkUafbVqd7GRKZF18F8jrO7QRWFy9ldm6HmiYSgfSmGnkOwKZfqceX/AEAp22M tT5cTsBASsamQ8VwzAUwX2VnW7Jg6WIM45j//4T9PrwiZmxwsU+oadYP1qpx7GHB0MW8 pPBQ== X-Gm-Message-State: APjAAAVpOlAaEeSgCOwpldM963nJwy/8k8LxVnOLNbcP8vN2ytRk1Om+ kVaMjfmL5FWYkihbyu3Ai8sBAY4ba4nbUCTwmVxV+4EK X-Google-Smtp-Source: APXvYqxv1UAYj9Lc1pIst2sECvH7fxY9frFo/XaVB33rNjfljyke/0PqB6aQTmo8XarCZfPrXrc9toVBto1uG0kEAMM= X-Received: by 2002:a7b:c091:: with SMTP id r17mr20275184wmh.74.1566236199566; Mon, 19 Aug 2019 10:36:39 -0700 (PDT) MIME-Version: 1.0 From: Matthew Henry Date: Mon, 19 Aug 2019 13:36:26 -0400 Message-ID: Subject: Guile Ice-9 Readline with-readline-completion-function To: bug-guile@gnu.org Content-Type: multipart/mixed; boundary="0000000000004f623705907bc88d" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::334 X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 19 Aug 2019 14:01:26 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --0000000000004f623705907bc88d Content-Type: text/plain; charset="UTF-8" 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 --0000000000004f623705907bc88d Content-Type: application/octet-stream; name="readline-completion-bug.scm" Content-Disposition: attachment; filename="readline-completion-bug.scm" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jzio0fke0 KHVzZS1tb2R1bGVzIChpY2UtOSByZWFkbGluZSkpCgood2l0aC1yZWFkbGluZS1jb21wbGV0aW9u LWZ1bmN0aW9uCiAobWFrZS1jb21wbGV0aW9uLWZ1bmN0aW9uICcoIm9uZSIgInR3byIgInRocmVl IikpCiAocmVhZGxpbmUgIlByb21wdDogIikpCg== --0000000000004f623705907bc88d-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 19 21:07:36 2019 Received: (at 37086) by debbugs.gnu.org; 20 Aug 2019 01:07:36 +0000 Received: from localhost ([127.0.0.1]:60660 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzsca-000290-G3 for submit@debbugs.gnu.org; Mon, 19 Aug 2019 21:07:36 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40224) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzrlV-0000p0-KC for 37086@debbugs.gnu.org; Mon, 19 Aug 2019 20:12:46 -0400 Received: by mail-wm1-f65.google.com with SMTP id v19so1015905wmj.5 for <37086@debbugs.gnu.org>; Mon, 19 Aug 2019 17:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=YlWLaApuWST3h9MRZshkTwucvg3eSSJvsO3GvxDoCQ0=; b=uURNApnCl6lp3UBj6UrhPedAyxQ9u+9f4CGkZvK9Mk2OdAKg0pp0DQLtk6Rni7AREt fHVm0IdPsRLNVlPU08iMTGy62/M419sUyZjs4GyJf/+6ZuNMW2upi4WRNFqXKseDdFcP 7CEDwAIafd4UznSbHOBSfd9Izs3wxyNo95u0UiCfoTI1BSJxhq0OC4mMIJ3tQ2U2DLfT +cgehiZW2sw1fas3JP/PT5hIf7SYqJte6j6QcX2fFci71gclChM4NZGT2FreYkia5aNH SYzB+8v5m/JsX/JKxRcw7vfbXbqeO8fkhK50P+zrc47/PsNUKj+z5VpifMXOoMjLpgDh 45Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=YlWLaApuWST3h9MRZshkTwucvg3eSSJvsO3GvxDoCQ0=; b=ev6jdHlGJp5yUR3vmcpAcb80qiOFV/A/vvv7AF8wEzt1JTS55VAK9DkexFbE4Tnxtz 12f8+q7JTEFr8gyIyLzH5cCzKRLF/3XXfYxbJ0pD1xQgc6j6S9Lv+uq67OA8SfN/GaR8 j+6p26YRHb4Ecq3SFT9Lm5CYulzUjEoOv2+QVxl+S9OS7fvL6MTzvwdj/jkdkPsja7Vp YXUrscz/7sU5+u9S4tps6N1EMMOKxJMqXYXoIy1RdBruMDNpK9RASTrE6iDyzLeIrFzu Tn662EbQ3Tr5k7KZ9OvpUKMJZPEU8w2JfIJH/LSaTWPyYJmEzKFLV+DlfrHWcKvDiAIZ VBEQ== X-Gm-Message-State: APjAAAUQcGAw7Fbh7I/Rpzpb9zoB1xOUir75/GbNDWA5XPM+qSg/bhG5 VaGZNtyAyXTnSeMh1p1KNMD7HXOdNuPpyyLZO2VKFP7B X-Google-Smtp-Source: APXvYqwf4JBZeEOFwY5d9j6PpXxINqA2XW6a2bbykY1YWL0NSHV6Oy9qRppXZ2aLaI+KhBZf33wTrlWxinogq4Uivmw= X-Received: by 2002:a1c:790b:: with SMTP id l11mr23331328wme.3.1566259959562; Mon, 19 Aug 2019 17:12:39 -0700 (PDT) MIME-Version: 1.0 From: Matthew Henry Date: Mon, 19 Aug 2019 20:12:27 -0400 Message-ID: Subject: Guile Ice-9 Readline with-readline-completion-function To: 37086@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 37086 X-Mailman-Approved-At: Mon, 19 Aug 2019 21:07:35 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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) From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 19 23:01:34 2019 Received: (at 37086) by debbugs.gnu.org; 20 Aug 2019 03:01:34 +0000 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 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 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 From: Mark H Weaver To: Matthew Henry Subject: Re: bug#37086: Guile Ice-9 Readline with-readline-completion-function References: Date: Mon, 19 Aug 2019 23:00:56 -0400 In-Reply-To: (Matthew Henry's message of "Mon, 19 Aug 2019 13:36:26 -0400") Message-ID: <87imqs35h8.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 37086 Cc: 37086@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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 From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 20 10:33:24 2019 Received: (at 37086) by debbugs.gnu.org; 20 Aug 2019 14:33:24 +0000 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 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 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) MIME-Version: 1.0 References: <87imqs35h8.fsf@netris.org> In-Reply-To: <87imqs35h8.fsf@netris.org> From: Matthew Henry Date: Tue, 20 Aug 2019 07:35:21 -0400 Message-ID: Subject: Re: bug#37086: Guile Ice-9 Readline with-readline-completion-function To: Mark H Weaver Content-Type: multipart/alternative; boundary="000000000000bd385a05908ada55" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 37086 X-Mailman-Approved-At: Tue, 20 Aug 2019 10:33:22 -0400 Cc: 37086@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --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-- From unknown Tue Jun 17 20:10:28 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 18 Sep 2019 11:24:11 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator