From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Recommendation for CAPF setup when you don't know completion string in advance Date: Tue, 11 May 2021 00:04:54 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15398"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: JD Smith Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 11 06:06:13 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 1lgJev-0003tO-6v for ged-emacs-devel@m.gmane-mx.org; Tue, 11 May 2021 06:06:13 +0200 Original-Received: from localhost ([::1]:40940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgJeu-0004cO-A0 for ged-emacs-devel@m.gmane-mx.org; Tue, 11 May 2021 00:06:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgJdl-000353-J3 for emacs-devel@gnu.org; Tue, 11 May 2021 00:05:02 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:52968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgJdi-0006AK-Qe for emacs-devel@gnu.org; Tue, 11 May 2021 00:05:00 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id F26AA441209; Tue, 11 May 2021 00:04:56 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 85F0A440218; Tue, 11 May 2021 00:04:55 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1620705895; bh=8nppHfCIzPChjpJjUMDbrtVHyGSBm+egzDh0a9291WE=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=J7eso2i3Ya8bTeSZbUR6k2YImKi0p6EmyEqvo0cibbupdP/GW3xyS88kScUFHYqW3 IMCXfj7+4z/M9QoAs7J7mYXLa5hAF3NA2x2LvAgfdpUP6sPzvCxU0b3NYYVDn+I3Aw 8Qyp59T+OZllf+bcDh1x/rkGDwDOnge4Lm26oMIaZTqedqRvW2TQKyOwW9Jpvv6LR1 3KJ24gaX9JAEJqHJbhUbNaVGidMvVYqzlYJ/5jFCadExsAQDXY7hvXwypBrGrBOPee Dhct5Gch6e88Is5OtdNIEAqzGfw+Dnlj91RgMiItr7CMww6FmYdlGU4djzAdbJ1AuC kCTGvb53ZPDHg== Original-Received: from alfajor (76-10-140-76.dsl.teksavvy.com [76.10.140.76]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 563601204DC; Tue, 11 May 2021 00:04:55 -0400 (EDT) In-Reply-To: (JD Smith's message of "Mon, 10 May 2021 23:33:44 -0400") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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:269143 Archived-At: > (lambda (string pred action) > (when (no-result-yet-cached-or-cached-string-is-substring-of-string) > (if (eq action 'metadata) `(metadata =E2=80=A6) > (unless last-prefix > ;; talk to ipython and save the completion info > ) > (if (eq (car-safe action) 'boundaries) ; munge the boundaries > `(boundaries from . to) ; using saved data from ipython > (complete-with-action action completion-alist string pred))))) [...] > and iPython correctly figures out to complete just a portion of that > string; say ran -> range. I tell CAPF about these boundaries (in > this case, 9 . 0). If, however, I later call complete-with-action > (which just calls try-completion, all-completions, etc.) with the > entire line string (=E2=80=9Cfor in ran=E2=80=9D), together with a compl= etion-alist > that contains iPython=E2=80=99s sub-string completions (like =E2=80=9Cra= nge=E2=80=9D), it > thinks there is no completion. If instead I just peel off the part > of the full line that needs completing (=E2=80=9Cran=E2=80=9D) and pass = that to > complete-with-action as STRING, it recognizes that there's a good > completion now, but then _replaces the entire line_ with the result. > > How do I get > complete-with-action/try-completion/test-completion/all-completions > etc. to respect my boundaries? There's `completion-table-with-context`. Note that it comes with the following: ;; TODO: add `suffix' maybe? so you probably won't be able to use it as-is and you'll need to write your function instead. But hopefully it should be enough to get you started. It shouldn't be terribly hard. I think one problem you may encounter is that in the default UI, selecting an entry from *Completions* (e.g. with a middle click) will probably throw away the "suffix" (i.e. the text after the end of the boundary). If so, I suggest you `M-x report-emacs-bug` (tho maybe I did fix this one already; but there might be a few other such corner cases where we throw away the text after the end of the boundary). Stefan