From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Re: Recommendation for CAPF setup when you don't know completion string in advance Date: Sat, 3 Apr 2021 22:52:25 -0400 Message-ID: <4B051055-CC87-419A-A106-C5F2A7674869@gmail.com> References: Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_A8512FFD-4BB5-484A-A6D1-28D1EE9EC265" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9582"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 04 04:53:09 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lSssu-0002NJ-Dc for ged-emacs-devel@m.gmane-mx.org; Sun, 04 Apr 2021 04:53:08 +0200 Original-Received: from localhost ([::1]:38450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSsst-0002ZU-Dv for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Apr 2021 22:53:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSssI-000298-Vb for emacs-devel@gnu.org; Sat, 03 Apr 2021 22:52:31 -0400 Original-Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]:35621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSssH-00021y-1m for emacs-devel@gnu.org; Sat, 03 Apr 2021 22:52:30 -0400 Original-Received: by mail-qv1-xf32.google.com with SMTP id x27so4164509qvd.2 for ; Sat, 03 Apr 2021 19:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=Dyx/GQmr85OVyiCBX50RpWVNrnvHnGLyd/jV1pxh7hg=; b=FAnxORmiIKxfcacPucKEm+/dRABeNE11Y6k5LpMPplcQ9sRLa0P3yBtI6qCgYbHjxs mjPQbKLmhlVOYIWRqBcMU0NS2H9zdEP+Y+lcQc6sVW+Z0F07OFSy/ugXb2RBevwxpv8n a59VraCC6er+5Z25xSw/ljEFHvkHAssNtkTk+h2j9UVlrRgy1pBk/8hID1b5QWT8kInv rgkvFLffvtYSUosNq0bwOEBMzpMhzYc9KqkDvpAOqwZrcLg34zZEHfbmAWEMiio1apQY rgTO8BF1JaFDBvTpPwecGCC0rXeiLdMECZME+T5S2fo0sHfMnOn7deR6jIXlS+9Loi+J R4Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=Dyx/GQmr85OVyiCBX50RpWVNrnvHnGLyd/jV1pxh7hg=; b=POw7dVxazmL31nE+hEPlfyp9TpVnaYlUkMOIgpl795felsKQtfaKy3BzUlkOAgkA3q tz27/Y9jkfkt6E+pEr6+vp787nDHX1L337zp5+3l03rJ/wVgS5l/4cwxCG4d9L8RoXGd bsaqZE1pitpry9sotlR5cI3beIFdxnQHIAXcBMnJyHIqSbr34EA4J1rdcvyvRVUdPAzp f2em/mpdsm3VKlLtyONipKp9YvQsWKITKZpkPnSTi3QMmLfO0qZd6ygeVBM1KSLm+w0o 3AXXrzMI6qM/GohAB++nK2CApaE0Jgfmq39LS9HRV3glB3sNKNI3Yo70Sj5Ve4HRD4PK eLwQ== X-Gm-Message-State: AOAM530J22XxQ1Rn9t5ln/w7u7V/aRty2RBZ7xb9hTwPyZ4jJUXotgyH WxlrMnYKJ8fMbnpnGGtDzjs= X-Google-Smtp-Source: ABdhPJyDSY3Yr2kNnzZ6cpWwUSmtoKCE15dsbNHmZ78XNZoT1SUeHrw+SfvEloI+QMOsI3+25CL43Q== X-Received: by 2002:a05:6214:d47:: with SMTP id 7mr18598839qvr.48.1617504747828; Sat, 03 Apr 2021 19:52:27 -0700 (PDT) Original-Received: from [192.168.0.113] (cm-134-228-54-223.buckeyecom.net. [134.228.54.223]) by smtp.gmail.com with ESMTPSA id o197sm10810007qka.26.2021.04.03.19.52.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Apr 2021 19:52:27 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3608.120.23.2.4) Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=jdtsmith@gmail.com; helo=mail-qv1-xf32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:267376 Archived-At: --Apple-Mail=_A8512FFD-4BB5-484A-A6D1-28D1EE9EC265 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Apr 3, 2021, at 7:49 PM, Stefan Monnier = wrote: >=20 >> So it=E2=80=99s a quandary: I won=E2=80=99t yet know `beg=E2=80=99 = and `end=E2=80=99 until _after_ >> interacting with iPython. Is there any way to =E2=80=9Crevise=E2=80=9D= =E2=80=98beg=E2=80=99 and =E2=80=98end=E2=80=99 in >> a collection function returned from a CAPF? >=20 > Make your CAPF function return a beg..end that covers "the whole line" > and which returns a completion table in the form of a function. > That function will then defer to the iPython code for the grunt of its > work and will return the "real" boundaries via the > `completion-boundaries` method. This will probably require some = caching > in the completion table so we don't call iPython too many times for > a single completion (like once for `completion-boundaries`, once for > `try-completion`, once for `all-completions`, etc=E2=80=A6). Thank you, that sounds quite promising. I=E2=80=99ve started sketching = out a mash-up of `completion-table-with-cache=E2=80=99 and = `python-shell-completion-at-point=E2=80=99 and it seems it should work = out. =20 There=E2=80=99s one thing I=E2=80=99m unclear on: how long does the = completion engine in Emacs hold on to a collection aka "completion = table" function? I=E2=80=99d expect this function to live only = throughout a single =E2=80=9Cevent" of completion (M-tab or what have = you). But if that is indeed the case, I=E2=80=99m confused by why = `completion-table-with-cache=E2=80=99 needs to test: (string-prefix-p last-arg arg ignore-case) Won=E2=80=99t this _always_ be true for the custom-wrapped closure which = `completion-table-with-cache=E2=80=99 constructs? In other words, I can = see two possibilities: The cache is there simply to prevent the multiple subsequent collection = function calls with the various action flags '(lambda, t, nil, = boundaries, metadata) from repeating the expensive completion results = lookup. The cache must guard against _future_ calls of the collection function = providing yet other not-yet-conceived-of completion strings. =20 If #1 is true, wouldn=E2=80=99t all of these calls provide the same = completion string? And if #2 is true, why does the completion engine = =E2=80=9Chold on=E2=80=9D to a bespoke completion table function beyond = the initial completion event which created it? =20 Probably I=E2=80=99m missing the real #3. This is relevant here for = deciding when to re-consult IPython for new completion data.=20 --Apple-Mail=_A8512FFD-4BB5-484A-A6D1-28D1EE9EC265 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Apr 3, 2021, at 7:49 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

So it=E2=80=99s a = quandary: I won=E2=80=99t yet know `beg=E2=80=99 and `end=E2=80=99 until = _after_
interacting with iPython.  Is there any way = to =E2=80=9Crevise=E2=80=9D =E2=80=98beg=E2=80=99 and =E2=80=98end=E2=80=99= in
a collection function returned from a CAPF?

Make your CAPF function return a = beg..end that covers "the whole line"
and which returns a = completion table in the form of a function.
That function = will then defer to the iPython code for the grunt of its
work and will return the "real" boundaries via the
`completion-boundaries` method.  This will probably = require some caching
in the completion table so we don't = call iPython too many times for
a single completion (like = once for `completion-boundaries`, once for
`try-completion`,= once for `all-completions`, etc=E2=80=A6).

Thank you, = that sounds quite promising.  I=E2=80=99ve started sketching out a = mash-up of `completion-table-with-cache=E2=80=99 and = `python-shell-completion-at-point=E2=80=99 and it seems it should work = out.  

There=E2=80=99s one = thing I=E2=80=99m unclear on: how long does the completion engine in = Emacs hold on to a collection aka "completion table" function? =  I=E2=80=99d expect this function to live only throughout a single = =E2=80=9Cevent" of completion (M-tab or what have you).  But if = that is indeed the case, I=E2=80=99m confused by why `completion-table-with-cache=E2=80=99 needs to = test:

= (string-prefix-p last-arg arg = ignore-case)

Won=E2=80=99t this _always_ be true for the custom-wrapped = closure which `completion-table-with-cache=E2=80=99 constructs?  In other words, I = can see two possibilities:

  1. The cache is = there simply to prevent the multiple subsequent collection = function calls with the various action flags '(lambda, t, nil, = boundaries, metadata) from repeating the expensive completion results = lookup.
  2. The = cache must guard against _future_ calls of the = collection function providing yet other not-yet-conceived-of completion = strings.  

If #1 is true, wouldn=E2=80=99t all of these calls provide = the same completion string? And if #2 is true, why does the completion = engine =E2=80=9Chold on=E2=80=9D to a bespoke completion table = function beyond the initial completion event which created it? =  

Probably I=E2=80=99m missing the real #3.  This is = relevant here for deciding when to re-consult IPython for new = completion data. 

= --Apple-Mail=_A8512FFD-4BB5-484A-A6D1-28D1EE9EC265--