From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jules Tamagnan Newsgroups: gmane.emacs.bugs Subject: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands Date: Sat, 22 Jun 2024 11:58:33 -0700 Message-ID: <877ceg9546.fsf@gmail.com> References: <87a5jd8hqh.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1861"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 71716@debbugs.gnu.org To: Eshel Yaron Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 22 21:00:17 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1sL5yD-0000GT-3g for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Jun 2024 21:00:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sL5y0-0000g1-6s; Sat, 22 Jun 2024 15:00:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sL5xz-0000fg-0H for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 15:00:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sL5xy-0001db-Iq for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 15:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sL5xy-0000Bn-Eb for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 15:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jules Tamagnan Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Jun 2024 19:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71716 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 71716-submit@debbugs.gnu.org id=B71716.1719082785641 (code B ref 71716); Sat, 22 Jun 2024 19:00:02 +0000 Original-Received: (at 71716) by debbugs.gnu.org; 22 Jun 2024 18:59:45 +0000 Original-Received: from localhost ([127.0.0.1]:56698 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL5xg-0000AF-NU for submit@debbugs.gnu.org; Sat, 22 Jun 2024 14:59:45 -0400 Original-Received: from mail-pg1-f175.google.com ([209.85.215.175]:61896) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL5xe-00009y-UN for 71716@debbugs.gnu.org; Sat, 22 Jun 2024 14:59:43 -0400 Original-Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-6eab07ae82bso2169620a12.3 for <71716@debbugs.gnu.org>; Sat, 22 Jun 2024 11:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719082717; x=1719687517; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=JiFkIH4ed3f3BtRWv5StPHLbpgY9ufmLJRd6jaLnEtw=; b=QAG8qdLk3l05bRpeVvX931H6ujpSpPo/Ngr4izQ7TfJHuHtQdmwS+eYDawXnDLWgMH MKV9+jN9O7dESIp4tzugYYNLQF3dysJa7rp2qbAKgnPKgfwS1L03tbbIx9rEM2p2it0f 9OVBb/3TsbrnLyJnlkNu+m2NC8+kjYmwPOn4kpwB+NE9PGYkNb28mRh2R7ad8mRBx5lq 2oRq6W5/fpup7kowkUtTUKQuaMbJbT+snfr3JfyqmhLMilJ/omPLfZEH8hgnGVZABpB5 b9QUTKZUh2PUz2KI+ZDA6BvgDgZojXnNTuymJEAY1CECeWUb8LZn1oUI7S0pprNS7pub dNtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719082717; x=1719687517; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JiFkIH4ed3f3BtRWv5StPHLbpgY9ufmLJRd6jaLnEtw=; b=UVz6LgNGOPnUyFVpmdfKPzW/CdPfzv/RXwnprUif2VAwPoJZGPaKgr6r+Ssuo38SKB RuZuej8AbAHFTo6hHHQA88TfONbThm6crxL9BnOEdS+OeBJZd/1i4mlpVZj81b6vIq7F gyeJ5Q72zs5h1X4n+cXzI/yU3RpEGgHo3j71LrmmMIxwBuQfE+tc2PGOTGoyvKwntTch 5hkny35B06B165tgcCpGHffb3a4tTlFdusrY2Ih9dWuaT+pYMGaWV+UnTFMon/GXU/j5 XIh7x0vXBtqpoSCdgzEeq4D2J77L9EeN7Rs65Arc0vdIVZa9Xf83rmx+7Fl0+Aw/gdCO E4Vg== X-Gm-Message-State: AOJu0Yykcetdvu2qYG4+6PPH/1UJeTH+U4Foqakx+A2S8JP9P03SGgjo +3/us139k0PXzEXItbPahaPejAsS1pAONGxvgwnPT3/rXLeYkD1DkZ0UcA== X-Google-Smtp-Source: AGHT+IGS0zUMeNjmvRq3+mNiGOD3wz1ryW6/4mDvMG91G2pYDCqiyQXm5pqz37P/0Fm7CY99eygK1Q== X-Received: by 2002:a17:903:186:b0:1f9:c6e8:27b0 with SMTP id d9443c01a7336-1fa23edcf59mr5383035ad.26.1719082716385; Sat, 22 Jun 2024 11:58:36 -0700 (PDT) Original-Received: from jat-framework (syn-024-043-218-040.biz.spectrum.com. [24.43.218.40]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9eb3d5bf2sm34191815ad.189.2024.06.22.11.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jun 2024 11:58:36 -0700 (PDT) In-Reply-To: (Eshel Yaron's message of "Sat, 22 Jun 2024 16:05:05 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287733 Archived-At: --=-=-= Content-Type: text/plain Hi Eshel, Eshel Yaron writes: > Thanks for the feature request and for the patch. Thanks for the incredibly quick feedback and thoughtful comments. I really appreciate it. I've attached a patch addressing the first comment and will post an additional patch for a possible fix to the second comment. > That sounds interesting. The ELPA package capf-autosuggest.el provided > a similar feature, IIRC. I'd like to get a better understanding of the > use case though: when would you use one of these commands instead of > completion-preview-complete? This is a functionality that I got used to when I tried using some other packages. One issue that I have with completion on the "common" part of candidates is that oftentimes when using thing functionality in my shell I have so many candidates from my history that the common part is relatively useless. Generally I'd say that I'm so comfortable navigating with forward-word and forward-sexp that this using M-f and C-M-f for this is second nature to me. Given that this is also implemented in `capf-autosuggest` and `github-copilot` I imagine that others might feel the same way. > 1. AFAICT, unlike completion-preview-insert, these new commands should > preserve (the rest of) the completion preview. So instead of > dismissing the preview by disabling completion-preview-active-mode > and then relying on the subsequent post-command-hook to recreate the > preview, I think these commands should modify (e.g. remove a word > from the start of) the after-string property of the preview overlay, > and inhibit a subsequent update of the preview, like we do in > completion-preview-complete. That way we avoid recomputing the > completion candidates, which may lead to a flicker in this case. Ahh that is a really good point, thank you. > 2. The temporary buffer where the motion command is executed has a > different major mode than the original buffer, so they might have > different notions of words/sexps. I was thinking about that when implementing this, even further one could have locally changed the value of `find-word-boundary-function-table` outside of `subword-mode`. One idea I had thought of was inserting the complete after-string and performing character deletions until the suffix was removed but this felt like an even worse solution. Maybe, in the temporary buffer, we can bind `find-word-boundary-function-table` to the parent buffer's value. I need to hop on a flight but can implement this in a third patch. - Jules --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Cont-Add-new-completion-preview-insert-word-sexp-com.patch Content-Description: Follow on patch to address comment 1 >From 1bbcc10c5b23d63dc8454113403c2d834a69d803 Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Sat, 22 Jun 2024 11:40:09 -0700 Subject: [PATCH 2/2] [Cont] Add new completion-preview-insert-{word,sexp} commands --- lisp/completion-preview.el | 37 ++++++++++++++++++++------- test/lisp/completion-preview-tests.el | 4 +-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index 3a7fa37afe0..637778caadb 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -456,18 +456,37 @@ completion-preview--insert (end (completion-preview--get 'completion-preview-end)) (efn (plist-get (completion-preview--get 'completion-preview-props) :exit-function)) - (ful (completion-preview--get 'after-string)) - (aft (with-temp-buffer - (insert ful) + (aft (completion-preview--get 'after-string)) + (ful (with-temp-buffer + (insert aft) (goto-char (point-min)) (funcall action) - (buffer-substring-no-properties (point-min) (point))))) - (completion-preview-active-mode -1) + (cons (buffer-substring-no-properties (point-min) (point)) + (buffer-substring (point) (point-max))))) + (ins (car ful)) + (suf (cdr ful))) + ;; If the completion is a full completion (there is no suffix) + ;; deactivate the preview + (when (string-empty-p suf) + (completion-preview-active-mode -1)) + + ;; Insert the new text (goto-char end) - (insert aft) - (when (and (functionp efn) (string= ful aft)) - ;; If we've inserted a full completion call the exit-function - (funcall efn (concat (buffer-substring-no-properties beg end) aft) 'finished))) + (insert ins) + + ;; If we are not inserting a full completion update the preview + (when (not (string-empty-p suf)) + (let ((pos (point))) + (completion-preview--inhibit-update) + (overlay-put (completion-preview--make-overlay + pos (propertize suf + 'mouse-face 'completion-preview-highlight + 'keymap completion-preview--mouse-map)) + 'completion-preview-end pos))) + + ;; If we've inserted a full completion call the exit-function + (when (and (functionp efn) (string-empty-p suf)) + (funcall efn (concat (buffer-substring-no-properties beg end) ins) 'finished))) (user-error "No current completion preview"))) (defun completion-preview-insert () diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index dedd135da73..54ba566ad3c 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -325,7 +325,7 @@ completion-preview-insert-word (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) (completion-preview-insert-word) (should (string= (buffer-string) "foobar")) - (should-not completion-preview--overlay) + (completion-preview-tests--check-preview "-1 2" 'completion-preview) (should-not exit-fn-called) (should-not exit-fn-args)))) @@ -347,7 +347,7 @@ completion-preview-insert-sexp (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) (completion-preview-insert-sexp) (should (string= (buffer-string) "foobar-1")) - (should-not completion-preview--overlay) + (completion-preview-tests--check-preview " 2" 'completion-preview) (should-not exit-fn-called) (should-not exit-fn-args)))) -- 2.45.1 --=-=-=--