From unknown Wed Jun 18 00:24:24 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#71716 <71716@debbugs.gnu.org> To: bug#71716 <71716@debbugs.gnu.org> Subject: Status: [PATCH] Add new completion-preview-insert-{word,sexp} commands Reply-To: bug#71716 <71716@debbugs.gnu.org> Date: Wed, 18 Jun 2025 07:24:24 +0000 retitle 71716 [PATCH] Add new completion-preview-insert-{word,sexp} commands reassign 71716 emacs submitter 71716 Jules Tamagnan severity 71716 normal tag 71716 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 22 05:11:46 2024 Received: (at submit) by debbugs.gnu.org; 22 Jun 2024 09:11:46 +0000 Received: from localhost ([127.0.0.1]:44414 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sKwme-0000tj-PB for submit@debbugs.gnu.org; Sat, 22 Jun 2024 05:11:45 -0400 Received: from lists.gnu.org ([209.51.188.17]:43704) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sKwmY-0000tD-Dv for submit@debbugs.gnu.org; Sat, 22 Jun 2024 05:11:41 -0400 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 1sKwmW-0002OL-Q2 for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 05:11:38 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKwmS-0004VP-T6 for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 05:11:35 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fa07e4f44eso4699665ad.2 for ; Sat, 22 Jun 2024 02:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719047491; x=1719652291; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=wMW4pGZYvGpxeSfX1Ny8i/lIyXnLsU2uCdaDoQiaLlM=; b=VKZ7kQEfpDCycRWfF8UKoL2w62pZnSySpvEm1X/BIZf8HLpa7qDCEDQe6zsmtWchBz bhXtckYIzZEQyvu3A/Rmb+vR84pCl6WzwHi0iVLcx4IIRiWzsm+KiVxof6bmtHzO0s3B PajPp2va7Nll+0iNwrUCU515+W3xVP5kOkXmPsPmzQyq5/YKI8S/8pt8AIE6AOC+JZQG bA9wBq90eoscDxMvTcpH53cf+LJjVwJRfeA8tzM6TD6Bfm6AGre7TdfHAxT7G68rjI1m SmwxFrh2yhkbEhZU3seMggK319DnYQDr5s/PgOpEnMZmv9L9CTP1a9UOey+n+A9Y60o0 wJmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719047491; x=1719652291; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wMW4pGZYvGpxeSfX1Ny8i/lIyXnLsU2uCdaDoQiaLlM=; b=NyCyGsCCeDIefGy7m7ZqIKk3kUUAx8KS+vWVUavbjt9Lzs3ig2OhiZFO2an86zX9e8 V/ln2JqzWfsJ2v9t0cNZveCyybG9kfeuQr5cmw8LbG4Mnjw+SKGMF516feq/BDJ0lFeD 4yJPUtzWnbys9Ljwg86Nr1jwelHahglaBKMoraS5q6Mq8YCJbd8hBsUbnx3JEiAexN3p d+Vx5qCgpht8tzisXRtUPVH4e82EqP+lI9m2fwODmIJj/5wzA0A+qDXT461JLK3ODICk YSN+3On1lOFSJNuHIzlhkIPQCtV0CCOswr9/KjtPh+HdoDkHiw9jOvEEpZblQZV57F5Y kdqg== X-Gm-Message-State: AOJu0YybOiJ+bTWweRfSvIkDt14jqwR54sMDp+dMbESX8ENP+9BDThCI rIPGd4ofYigxACF1yWr4AUPA1hBnCJ3JzgE6b0M7nNqyGHynsCGSG6HuuQ== X-Google-Smtp-Source: AGHT+IFSNd4x15L4OCbyE8bBlhpPfNxJ+EWwfJAlq7XJbOZXrCVPBIupm463i0jNlUP3EReeenpdpw== X-Received: by 2002:a17:903:41cb:b0:1fa:1750:132c with SMTP id d9443c01a7336-1fa1750152fmr3788505ad.5.1719047490385; Sat, 22 Jun 2024 02:11:30 -0700 (PDT) Received: from jat-framework (syn-024-043-218-043.biz.spectrum.com. [24.43.218.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9eb3219b1sm27015015ad.94.2024.06.22.02.11.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jun 2024 02:11:29 -0700 (PDT) From: Jules Tamagnan To: bug-gnu-emacs@gnu.org Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands Date: Sat, 22 Jun 2024 02:11:18 -0700 Message-ID: <87a5jd8hqh.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=jtamagnan@gmail.com; helo=mail-pl1-x630.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, 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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit 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 (--) --=-=-= Content-Type: text/plain Tags: patch * Problem Oftentimes when completing a value a user wants a small part of a completion but not the entire thing. This happens frequently when iterating on shell commands or on similar lines of code. completion-preview can help with this by quickly suggesting a sensible completion pulled from any completion-at-point function. The problem is that accepting a full completion is often inefficient because one might only want the first part of that completion. This leads to a lot of deletions after the fact. * Solution Allow inserting of partial completions when using completion-preview. For this I've added two new commands completion-preview-insert-word and completion-preview-insert-sexp which will insert the next word or sexp in the completion. For consistency with completion-preview-insert I've refactored the code so that these three commands share a common code path. * Notes - I've added new tests for this and ensured that previous ones continue to pass. - I've signed the copyright assignments and have contributed to emacs previously. * Info In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.42, cairo version 1.18.0) Repository revision: 988203fe980e3c80f736ad0b6aae9f288ebfa0f1 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101013 System Description: NixOS 24.11 (Vicuna) Configured using: 'configure --prefix=/nix/store/3riplzxicrgaff4jm49wa4vvvrd6yd1l-emacs-git-20240615.0 --disable-build-details --with-modules --with-x-toolkit=gtk3 --with-cairo --with-xft --with-compress-install --with-toolkit-scroll-bars --with-native-compilation --without-imagemagick --with-mailutils --without-small-ja-dic --with-tree-sitter --with-xinput2 --with-xwidgets --with-dbus --with-selinux' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-new-completion-preview-insert-word-sexp-commands.patch >From d78a9a4209d050dcb2a410610d70840d35b9b722 Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Sat, 22 Jun 2024 00:45:01 -0700 Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands * lisp/completion-preview.el: Add new completion-preview-insert-word and completion-preview-insert-sexp commands. * test/lisp/completion-preview-tests.el: Add tests for new commands. --- lisp/completion-preview.el | 56 +++++++++++++++++++-------- test/lisp/completion-preview-tests.el | 52 +++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 20 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index caebb9d01e3..3a7fa37afe0 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -90,7 +90,9 @@ completion-preview-commands delete-backward-char backward-delete-char-untabify analyze-text-conversion - completion-preview-complete) + completion-preview-complete + completion-preview-insert-word + completion-preview-insert-sexp) "List of commands that should trigger completion preview." :type '(repeat (function :tag "Command" :value self-insert-command)) :version "30.1") @@ -163,6 +165,8 @@ completion-preview-active-mode-map "M-i" #'completion-preview-complete ;; "M-n" #'completion-preview-next-candidate ;; "M-p" #'completion-preview-prev-candidate + ;; " " #'completion-preview-insert-word + ;; " " #'completion-preview-insert-sexp ) (defun completion-preview--ignore () @@ -444,24 +448,42 @@ completion-preview--post-command (completion-preview--show) (completion-preview-active-mode -1))))) +(defun completion-preview--insert (action) + "A helper function to insert part of the completion candidate that the +preview is showing." + (if completion-preview-active-mode + (let* ((beg (completion-preview--get 'completion-preview-beg)) + (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) + (goto-char (point-min)) + (funcall action) + (buffer-substring-no-properties (point-min) (point))))) + (completion-preview-active-mode -1) + (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))) + (user-error "No current completion preview"))) + (defun completion-preview-insert () "Insert the completion candidate that the preview is showing." (interactive) - (if completion-preview-active-mode - (let* ((pre (completion-preview--get 'completion-preview-base)) - (end (completion-preview--get 'completion-preview-end)) - (ind (completion-preview--get 'completion-preview-index)) - (all (completion-preview--get 'completion-preview-suffixes)) - (com (completion-preview--get 'completion-preview-common)) - (efn (plist-get (completion-preview--get 'completion-preview-props) - :exit-function)) - (aft (completion-preview--get 'after-string)) - (str (concat pre com (nth ind all)))) - (completion-preview-active-mode -1) - (goto-char end) - (insert (substring-no-properties aft)) - (when (functionp efn) (funcall efn str 'finished))) - (user-error "No current completion preview"))) + (completion-preview--insert #'end-of-buffer)) + +(defun completion-preview-insert-word () + "Insert the next word of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert #'forward-word)) + +(defun completion-preview-insert-sexp () + "Insert the next sexp of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert #'forward-sexp)) (defun completion-preview-complete () "Complete up to the longest common prefix of all completion candidates. @@ -583,6 +605,8 @@ completion-preview--active-p (buffer-local-value 'completion-preview-active-mode buffer)) (dolist (cmd '(completion-preview-insert + completion-preview-insert-word + completion-preview-insert-sexp completion-preview-complete completion-preview-prev-candidate completion-preview-next-candidate)) diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index 7d358d07519..dedd135da73 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -292,7 +292,7 @@ completion-preview-insert-calls-exit-function (setq-local completion-at-point-functions (list (completion-preview-tests--capf - '("foobar" "foobaz") + '("foobar-1 2" "foobarverylong") :exit-function (lambda (&rest args) (setq exit-fn-called t @@ -300,11 +300,55 @@ completion-preview-insert-calls-exit-function (insert "foo") (let ((this-command 'self-insert-command)) (completion-preview--post-command)) - (completion-preview-tests--check-preview "bar" 'completion-preview-common) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) (completion-preview-insert) - (should (string= (buffer-string) "foobar")) + (should (string= (buffer-string) "foobar-1 2")) (should-not completion-preview--overlay) (should exit-fn-called) - (should (equal exit-fn-args '("foobar" finished)))))) + (should (equal exit-fn-args '("foobar-1 2" finished)))))) + +(ert-deftest completion-preview-insert-word () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (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) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-sexp () + "Test that `completion-preview-insert-word' properly inserts just a sexp." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (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) + (should-not exit-fn-called) + (should-not exit-fn-args)))) ;;; completion-preview-tests.el ends here -- 2.45.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 22 10:05:10 2024 Received: (at 71716) by debbugs.gnu.org; 22 Jun 2024 14:05:10 +0000 Received: from localhost ([127.0.0.1]:47130 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL1Mc-0006Ye-6p for submit@debbugs.gnu.org; Sat, 22 Jun 2024 10:05:10 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:41646 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL1Ma-0006YU-1E for 71716@debbugs.gnu.org; Sat, 22 Jun 2024 10:05:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1719065107; bh=piQZDADCfgtkJJbJxC19ihJgRimuiVcK035E0yWnvxs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=CkwmE0G8kWzh5BkeF8ixJ8oB5ANzfcV1qLP1PXdGt1qbbDc+aZRY2vIbF/krplKQs 0EyD3DRDy2v8cXF1CPASVj8Aw9YEH4XnQLll0NJl07MYcyGzp/FzzZVrqj4vE7gtbq Fh+NwBYR9XPuEDd4U3OksdV4jk8bt2fNIdXz0MDiA3zvcrLCIWg0x+ePyTxjnMxEKT WuMeoJROB2d9qdRfa31PEOu2rZucJYT0sSJPKPQLMkyO7k4Clh5DrRjlSGNGGev7g1 209vcm5i8ywfYcOZmN0dBnbpvqu8hfylog8y5BwZfgW4TAXr2arTD3b6eTISrv3M2K h8cCdiryUFPOA== From: Eshel Yaron To: Jules Tamagnan Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <87a5jd8hqh.fsf@gmail.com> (Jules Tamagnan's message of "Sat, 22 Jun 2024 02:11:18 -0700") References: <87a5jd8hqh.fsf@gmail.com> Date: Sat, 22 Jun 2024 16:05:05 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) Hi Jules, Jules Tamagnan writes: > Tags: patch Thanks for the feature request and for the patch. > * Problem > > Oftentimes when completing a value a user wants a small part of a > completion but not the entire thing. This happens frequently when > iterating on shell commands or on similar lines of > code. completion-preview can help with this by quickly suggesting a > sensible completion pulled from any completion-at-point function. The > problem is that accepting a full completion is often inefficient because > one might only want the first part of that completion. This leads to a > lot of deletions after the fact. > > * Solution > > Allow inserting of partial completions when using > completion-preview. We currently have completion-preview-complete (M-i) for that: it inserts the common part (prefix) of all completion candidates. > For this I've added two new commands completion-preview-insert-word > and completion-preview-insert-sexp which will insert the next word or > sexp in the completion. 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? > For consistency with completion-preview-insert I've refactored the > code so that these three commands share a common code path. Good idea, but there are two issues with the current implementation: 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. 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. > * Notes > > - I've added new tests for this and ensured that previous ones continue > to pass. > - I've signed the copyright assignments and have contributed to emacs > previously. That's great, thanks. Eshel From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 22 14:59:45 2024 Received: (at 71716) by debbugs.gnu.org; 22 Jun 2024 18:59:45 +0000 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 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 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) 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) From: Jules Tamagnan To: Eshel Yaron Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: (Eshel Yaron's message of "Sat, 22 Jun 2024 16:05:05 +0200") References: <87a5jd8hqh.fsf@gmail.com> Date: Sat, 22 Jun 2024 11:58:33 -0700 Message-ID: <877ceg9546.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) --=-=-= 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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 22 18:01:16 2024 Received: (at 71716) by debbugs.gnu.org; 22 Jun 2024 22:01:16 +0000 Received: from localhost ([127.0.0.1]:33599 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL8nL-00065u-Il for submit@debbugs.gnu.org; Sat, 22 Jun 2024 18:01:16 -0400 Received: from mail-pf1-f178.google.com ([209.85.210.178]:53441) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL8nJ-00065c-Eq for 71716@debbugs.gnu.org; Sat, 22 Jun 2024 18:01:14 -0400 Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7065a2f4573so1106847b3a.2 for <71716@debbugs.gnu.org>; Sat, 22 Jun 2024 15:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719093607; x=1719698407; 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=eym4BzLGYD/tyi+m750GKZfbfEluDySs9rQXS7oOzVk=; b=XtY+FP5RJYTIAXoVlIiWnTurTWVeWIetBYN6NHc14TYFafAAAPi1z+dSrq2M5OPJW7 T7FU/IsisystoBlhkWyCrGX/Ptr/dUlKdjhOkOBkNgxPRFDDRr1q9Mt6SoMNE9Xgjyic Deu90M+ldNJTLnQMe4dTGVb5vRZcZsQ046T4ZOaz3SCvJ3EuA/KI6XD95qBXUAsLQDLO bGmU0O0eHf56txVuxcLv1eJVj71N8JbuSXjgV3lBaLce+uKl7rJnufgWLJLYOImwl+ba t9QMSS+GXVyEIfTnPvhY1yuYngckF0nmWToqQl2wu42FsFetiYNtStEeHslrGyFNztyB Ow5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719093607; x=1719698407; 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=eym4BzLGYD/tyi+m750GKZfbfEluDySs9rQXS7oOzVk=; b=vLl/KAIayiu+0NWejvO8/GIhBpyXGxjtnymM4RXpQSnXrmcHYtsWR/YBqavNwbW/3j lWXPe3EMPM38sIotYfMk5PBSXRAy+DMXYPD1Yfu5slDHLvXcpx6zd2ORaJefpNFDnsD5 2hhMnW8vkMEB8JpEXaYFL2a6smzWsTnsdVEeRMSXDow5EsvGOBX182+sNYg5kYqSNYEV fPIwdBXiYcLtp4y2IP6kWnAFv3LE32evPcFtJ1irhTHQPwLi9wzjQgjBSt52FPtXVp61 3aL0hKumCmJX9iqGuXmKf2/EydM6Qit3UXhuiX5TxiedjR9K5nzMxYTZNl3I+lQw0lpl c9HA== X-Gm-Message-State: AOJu0Yx2exFyBcVIXArglmNBE3GJoA49fr/cozHDwKKF3R/zv6C8xoC+ wRkv8EvgqFnGUxvnoAcl9xJPNLLvm7aFeCMfF1dQMsdG+fZ6giAS6H/Ipg== X-Google-Smtp-Source: AGHT+IFRymIHS9ZFVXx6BUHXWXESBqKys/fD9tlwTS22kfBfJlCBTJ7nPnYxPa+CpCyltyJ0X19wog== X-Received: by 2002:a05:6a00:2d5:b0:706:5aee:b987 with SMTP id d2e1a72fcca58-706746b601bmr680539b3a.22.1719093606733; Sat, 22 Jun 2024 15:00:06 -0700 (PDT) Received: from jat-framework (syn-076-081-086-146.biz.spectrum.com. [76.81.86.146]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706512900a0sm3657526b3a.149.2024.06.22.15.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jun 2024 15:00:06 -0700 (PDT) From: Jules Tamagnan To: Eshel Yaron Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <877ceg9546.fsf@gmail.com> (Jules Tamagnan's message of "Sat, 22 Jun 2024 11:58:33 -0700") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> Date: Sat, 22 Jun 2024 15:00:03 -0700 Message-ID: <874j9k8wpo.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) --=-=-= Content-Type: text/plain Hi Eshel, I've further tweaked the code to address the second point of feedback. Looking at it now it seems a bit uglier for the "standard" insert case so I'd be willing to revert that consolidation. Overall it seems to work well both in unit tests and in my personal testing. In the last message I attached a patch with only my second commit. This new patch contains of all 3 commits: 1. The initial change 2. The change to preserve the prefix and reduce flicker 3. The change to support different modes and definitions of word. This change also includes new tests. It is worth noting that this will not work as a user may expect if `forward-word` or `forward-sexp` are bound to other functions but hopefully the included helper functions can allow users to define these functions if they need. Best, Jules --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=full.patch Content-Description: Complete patch consisting of 3 commits >From d78a9a4209d050dcb2a410610d70840d35b9b722 Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Sat, 22 Jun 2024 00:45:01 -0700 Subject: [PATCH 1/3] Add new completion-preview-insert-{word,sexp} commands * lisp/completion-preview.el: Add new completion-preview-insert-word and completion-preview-insert-sexp commands. * test/lisp/completion-preview-tests.el: Add tests for new commands. --- lisp/completion-preview.el | 56 +++++++++++++++++++-------- test/lisp/completion-preview-tests.el | 52 +++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 20 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index caebb9d01e3..3a7fa37afe0 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -90,7 +90,9 @@ completion-preview-commands delete-backward-char backward-delete-char-untabify analyze-text-conversion - completion-preview-complete) + completion-preview-complete + completion-preview-insert-word + completion-preview-insert-sexp) "List of commands that should trigger completion preview." :type '(repeat (function :tag "Command" :value self-insert-command)) :version "30.1") @@ -163,6 +165,8 @@ completion-preview-active-mode-map "M-i" #'completion-preview-complete ;; "M-n" #'completion-preview-next-candidate ;; "M-p" #'completion-preview-prev-candidate + ;; " " #'completion-preview-insert-word + ;; " " #'completion-preview-insert-sexp ) (defun completion-preview--ignore () @@ -444,24 +448,42 @@ completion-preview--post-command (completion-preview--show) (completion-preview-active-mode -1))))) +(defun completion-preview--insert (action) + "A helper function to insert part of the completion candidate that the +preview is showing." + (if completion-preview-active-mode + (let* ((beg (completion-preview--get 'completion-preview-beg)) + (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) + (goto-char (point-min)) + (funcall action) + (buffer-substring-no-properties (point-min) (point))))) + (completion-preview-active-mode -1) + (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))) + (user-error "No current completion preview"))) + (defun completion-preview-insert () "Insert the completion candidate that the preview is showing." (interactive) - (if completion-preview-active-mode - (let* ((pre (completion-preview--get 'completion-preview-base)) - (end (completion-preview--get 'completion-preview-end)) - (ind (completion-preview--get 'completion-preview-index)) - (all (completion-preview--get 'completion-preview-suffixes)) - (com (completion-preview--get 'completion-preview-common)) - (efn (plist-get (completion-preview--get 'completion-preview-props) - :exit-function)) - (aft (completion-preview--get 'after-string)) - (str (concat pre com (nth ind all)))) - (completion-preview-active-mode -1) - (goto-char end) - (insert (substring-no-properties aft)) - (when (functionp efn) (funcall efn str 'finished))) - (user-error "No current completion preview"))) + (completion-preview--insert #'end-of-buffer)) + +(defun completion-preview-insert-word () + "Insert the next word of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert #'forward-word)) + +(defun completion-preview-insert-sexp () + "Insert the next sexp of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert #'forward-sexp)) (defun completion-preview-complete () "Complete up to the longest common prefix of all completion candidates. @@ -583,6 +605,8 @@ completion-preview--active-p (buffer-local-value 'completion-preview-active-mode buffer)) (dolist (cmd '(completion-preview-insert + completion-preview-insert-word + completion-preview-insert-sexp completion-preview-complete completion-preview-prev-candidate completion-preview-next-candidate)) diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index 7d358d07519..dedd135da73 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -292,7 +292,7 @@ completion-preview-insert-calls-exit-function (setq-local completion-at-point-functions (list (completion-preview-tests--capf - '("foobar" "foobaz") + '("foobar-1 2" "foobarverylong") :exit-function (lambda (&rest args) (setq exit-fn-called t @@ -300,11 +300,55 @@ completion-preview-insert-calls-exit-function (insert "foo") (let ((this-command 'self-insert-command)) (completion-preview--post-command)) - (completion-preview-tests--check-preview "bar" 'completion-preview-common) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) (completion-preview-insert) - (should (string= (buffer-string) "foobar")) + (should (string= (buffer-string) "foobar-1 2")) (should-not completion-preview--overlay) (should exit-fn-called) - (should (equal exit-fn-args '("foobar" finished)))))) + (should (equal exit-fn-args '("foobar-1 2" finished)))))) + +(ert-deftest completion-preview-insert-word () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (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) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-sexp () + "Test that `completion-preview-insert-word' properly inserts just a sexp." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (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) + (should-not exit-fn-called) + (should-not exit-fn-args)))) ;;; completion-preview-tests.el ends here -- 2.45.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/3] [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 >From 2c8ce27276405d4f541527768940a7847a6d9050 Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Sat, 22 Jun 2024 12:51:35 -0700 Subject: [PATCH 3/3] [Cont 2] Add new completion-preview-insert-{word,sexp} commands --- lisp/completion-preview.el | 27 +++++++++++----- test/lisp/completion-preview-tests.el | 45 +++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index 637778caadb..4071240df81 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -448,7 +448,25 @@ completion-preview--post-command (completion-preview--show) (completion-preview-active-mode -1))))) -(defun completion-preview--insert (action) +(defun completion-preview--determine-substring (command string) + "A helper function to determine what parts of a STRING come before and +after the point when a certain COMMAND has been performed on that STRING" + ;; Determine the parent buffer + (let ((parent-buffer (current-buffer))) + (with-temp-buffer + ;; Certain locally set variables can affect common movement + ;; commands such as `forward-word'; determine their values from + ;; the parent buffer and set them in the temporary buffer. + (let ((char-script-table (buffer-local-value 'char-script-table parent-buffer)) + (find-word-boundary-function-table (buffer-local-value 'find-word-boundary-function-table parent-buffer)) + (inhibit-field-text-motion (buffer-local-value 'inhibit-field-text-motion parent-buffer))) + (insert string) + (goto-char (point-min)) + (funcall command) + (cons (buffer-substring-no-properties (point-min) (point)) + (buffer-substring (point) (point-max))))))) + +(defun completion-preview--insert (command) "A helper function to insert part of the completion candidate that the preview is showing." (if completion-preview-active-mode @@ -457,12 +475,7 @@ completion-preview--insert (efn (plist-get (completion-preview--get 'completion-preview-props) :exit-function)) (aft (completion-preview--get 'after-string)) - (ful (with-temp-buffer - (insert aft) - (goto-char (point-min)) - (funcall action) - (cons (buffer-substring-no-properties (point-min) (point)) - (buffer-substring (point) (point-max))))) + (ful (completion-preview--determine-substring command aft)) (ins (car ful)) (suf (cdr ful))) ;; If the completion is a full completion (there is no suffix) diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index 54ba566ad3c..1c8a04c765d 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -329,6 +329,51 @@ completion-preview-insert-word (should-not exit-fn-called) (should-not exit-fn-args)))) +(ert-deftest completion-preview-insert-nonsubword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobarBar")) + (should-not completion-preview--overlay) + (should exit-fn-called) + (should (equal exit-fn-args '("foobarBar" finished)))))) + +(ert-deftest completion-preview-insert-subword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (subword-mode) + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobar")) + (completion-preview-tests--check-preview "Bar" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + (ert-deftest completion-preview-insert-sexp () "Test that `completion-preview-insert-word' properly inserts just a sexp." (let ((exit-fn-called nil) (exit-fn-args nil)) -- 2.45.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 23 04:00:29 2024 Received: (at 71716) by debbugs.gnu.org; 23 Jun 2024 08:00:29 +0000 Received: from localhost ([127.0.0.1]:49018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLI9E-0005zU-WA for submit@debbugs.gnu.org; Sun, 23 Jun 2024 04:00:29 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:41044 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLI9D-0005zM-NC for 71716@debbugs.gnu.org; Sun, 23 Jun 2024 04:00:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1719129626; bh=rZKXfPz7EIcJC6OZOfKFT7rt1nfnijg8L2/mIErw9D0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=E1m6LcNdmTZ3WoN5JKFLulgw7NXPWt1Nrx7zwXRY8Hp6192OJjibqX/JKYvow240x Rn4bC4Nttaq8Xe3bBNs03nQyW7tVAV9wUSfybdg4n0uFsQrc2y50mIeD53y/vZ/uxj M/BWFctaddbEqD+5V6OIOmwm6dpIlt7y0Mggr3KTovonidZz6ldEYkd/fdNeu2ooDl 6N3e5NBwvVaA5SOSn9L5/Ot4OfLDrrZ62pHYW6ZUhVeF6l9KNbJfR9WQgGRTRqWN6v PnvGlX0IP6hO+GWhQJ4K53LLKb8zScVP5a8Rf3EHtPhwmrgLcdJiM7RWwJX/xhAZa1 KojShScM9rpEg== From: Eshel Yaron To: Jules Tamagnan Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <874j9k8wpo.fsf@gmail.com> (Jules Tamagnan's message of "Sat, 22 Jun 2024 15:00:03 -0700") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> Date: Sun, 23 Jun 2024 10:00:24 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) Hi Jules, Jules Tamagnan writes: > Eshel Yaron writes: > >> 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`. Right. And when considering sexps, forward-sexp-function can come into play, which might take into account all sorts of buffer-local variables. > 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. I think that might be the way to go, actually. Placing the after-string insertion and subsequent deletion in an atomic change group (and using undo-amalgamate-change-group to let the user undo everything in one go) should hopefully work just as well, and that would alleviate the need to chase down and replicate complex buffer state in the temporary buffer. Jules Tamagnan writes: > I've further tweaked the code to address the second point of feedback. Thanks! > Looking at it now it seems a bit uglier for the "standard" insert case > so I'd be willing to revert that consolidation. I think that'd be best, yes. Let's keep completion-preview-insert intact for the time being and see if we there's room for cleanly consolidating it with the new commands after we get them right. > Overall it seems to work well both in unit tests and in my personal > testing. > > In the last message I attached a patch with only my second commit. This > new patch contains of all 3 commits: I'll give it a try, thanks. In the future if you could squash all changes to a single patch I think that'd make it easiest to review. Best, Eshel From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 23 18:09:58 2024 Received: (at 71716) by debbugs.gnu.org; 23 Jun 2024 22:09:59 +0000 Received: from localhost ([127.0.0.1]:53687 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLVPJ-0003ZL-6N for submit@debbugs.gnu.org; Sun, 23 Jun 2024 18:09:58 -0400 Received: from mail-pl1-f180.google.com ([209.85.214.180]:42328) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLVPG-0003Yt-8Y for 71716@debbugs.gnu.org; Sun, 23 Jun 2024 18:09:55 -0400 Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1f4a5344ec7so24173055ad.1 for <71716@debbugs.gnu.org>; Sun, 23 Jun 2024 15:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719180528; x=1719785328; darn=debbugs.gnu.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=zkslLIlpr+DhYJQurg/kQaaRa12NHPaS23jvnyCykSU=; b=XafPN2q88h/hs8KwFM9WJbfRtblgRXrRaCOjSkJZ91yGmvfducf4N/UqorNMI0VzjL X2zBeawwopyXGWXQi4sIkVuVkXRnQLJXROcNO5sVjwQ0jv8lah/6ffQyMaI5ZGgz4YkK JcpcI21k0ROs3qDSijlMMCFLKAZOn5FW4dRsx5GZKvwmkAhKMljJLyeLXI/e2g78YY7l K2ZNLTwGNLOwLL9cnhiBVvXtHpA5yvfLTLduvpG6YEpQs+3MYohpf59zyQinluZQVqvR tftVUPVGJsc6XvRMl34YQmI7gzpfLdNse3fqfRpNngLWw0UMVEpUAv4YtRqr+QCbv424 aYWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719180528; x=1719785328; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zkslLIlpr+DhYJQurg/kQaaRa12NHPaS23jvnyCykSU=; b=oruZyu07GFMZP1GPOOSt/MCUK2QafpD2yEGzT7o6I2YZrgBggoDYHtVaO9gBOqZThx enJOWxHYdkY8+15WPnxZCQiq/oMKMev/RBvZdJVTJmfo+NiJ4n3QihFlt/B7bPjUNckE 1aek4S7wiMkTPWyLPYNt0vYg4mjknl4BQ7yNU7MlewLxTiCxIJAQ8wJ8a7ig5H+UAHEH yeif7P8CVdAhCLBxqCx1ugqrv5vFFjzBuYL93Wq1bXlO8IiA+JUx6dkIaeDqLyl4NBId wW1u3Py+WrXaOyccP5TM2mae5kpyAqVKdvheWTm9qz938k2GXQGm3rb4PPZ0UqiIVNz4 bfaA== X-Gm-Message-State: AOJu0YzDHiVWxiVC68b/ex9SgRgE8Wa+3X9eLGUSMGeLCAJav1iRcuAG hPd3ufnS7WQZgLIYfGMnLa2X340iHGvci2jfoaZc4ilQgDlinYbSj7Uljg== X-Google-Smtp-Source: AGHT+IGqrdlDfjs2Di7XzuoDSoi+/oFlPlcphIfh5F0preo6YVamutu5fHPYMSPpgeJhIoi6E5qJ/A== X-Received: by 2002:a17:903:187:b0:1fa:2c79:74fe with SMTP id d9443c01a7336-1fa2c7975f8mr17237565ad.42.1719180527174; Sun, 23 Jun 2024 15:08:47 -0700 (PDT) Received: from jat-framework (c-73-189-85-43.hsd1.ca.comcast.net. [73.189.85.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9ebbb2b06sm49195045ad.262.2024.06.23.15.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jun 2024 15:08:45 -0700 (PDT) From: Jules Tamagnan To: Eshel Yaron Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: (Eshel Yaron's message of "Sun, 23 Jun 2024 10:00:24 +0200") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Date: Sun, 23 Jun 2024 15:08:43 -0700 Message-ID: <87r0cn5n2s.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) --=-=-= Content-Type: text/plain Hi Eshel, I just want to start off once again by saying thank you for the thoughtful review, help, testing, and encouragement. I'll start by responding to the previous email and then go on to explain the two attached patches. --- Eshel Yaron writes: > Right. And when considering sexps, forward-sexp-function can come into > play, which might take into account all sorts of buffer-local variables. Yeah.. I can imagine this become a frustrating game of whack-a-mole. > I think that might be the way to go, actually. Placing the after-string > insertion and subsequent deletion in an atomic change group (and using > undo-amalgamate-change-group to let the user undo everything in one go) > should hopefully work just as well, and that would alleviate the need to > chase down and replicate complex buffer state in the temporary buffer. I took a stab at implementing this. I didn't fiddle with `undo-amalgamate-change-group` but it seems like it wasn't required to get what felt like sensible behavior. > I think that'd be best, yes. Let's keep completion-preview-insert > intact for the time being and see if we there's room for cleanly > consolidating it with the new commands after we get them right. That sounds great no need to make things too complicated. > I'll give it a try, thanks. Thank you > In the future if you could squash all changes to a single patch I > think that'd make it easiest to review. That sounds great. I'll keep that in mind when presenting the next changesets. --- Okay now onto the latest patches. Both patches have reverted the changes to `completion-preview-insert` and both patches pass the same set of unit tests. The first patch `completion-preview-partial-insertion-with-temp-buffer.patch` is the same as the previous patch but with two critical changes: the revert, and the addition of a new variable `completion-preview-context-variables` which can be used to customize the list of variables to copy into the temporary buffer. The second patch `completion-preview-partial-insertion-with-region-delete.patch` is the version of the change that uses in-buffer deletion. There's not much to say here, it seems quite a bit more robust. I reckon the second patch is more in line with what you had in mind but I wanted to bring the first approach to a more acceptable state. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=completion-preview-partial-insertion-with-temp-buffer.patch Content-Description: New partial insertion functions implemented with a temporary buffer >From 89c552df4704f12bfdac8f05fd04b72bc91efccf Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Sat, 22 Jun 2024 00:45:01 -0700 Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands * lisp/completion-preview.el: Add new completion-preview-insert-word and completion-preview-insert-sexp commands. * test/lisp/completion-preview-tests.el: Add tests for new commands. --- lisp/completion-preview.el | 82 +++++++++++++++++++++- test/lisp/completion-preview-tests.el | 97 +++++++++++++++++++++++++-- 2 files changed, 174 insertions(+), 5 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index caebb9d01e3..49f40eb5a68 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -90,11 +90,22 @@ completion-preview-commands delete-backward-char backward-delete-char-untabify analyze-text-conversion - completion-preview-complete) + completion-preview-complete + completion-preview-insert-word + completion-preview-insert-sexp) "List of commands that should trigger completion preview." :type '(repeat (function :tag "Command" :value self-insert-command)) :version "30.1") +(defcustom completion-preview-context-variables '(char-script-table + forward-sexp-function + find-word-boundary-function-table + inhibit-field-text-motion) + "List of variables which can change the functionality of `forward-word' +or `forward-sexp'." + :type '(repeat (variable :tag "Variable" :value char-script-table)) + :version "30.1") + (defcustom completion-preview-minimum-symbol-length 3 "Minimum length of the symbol at point for showing completion preview. @@ -163,6 +174,8 @@ completion-preview-active-mode-map "M-i" #'completion-preview-complete ;; "M-n" #'completion-preview-next-candidate ;; "M-p" #'completion-preview-prev-candidate + ;; " " #'completion-preview-insert-word + ;; " " #'completion-preview-insert-sexp ) (defun completion-preview--ignore () @@ -463,6 +476,71 @@ completion-preview-insert (when (functionp efn) (funcall efn str 'finished))) (user-error "No current completion preview"))) +(defun completion-preview--determine-substring (command string) + "A helper function to determine what parts of a STRING come before and +after the point when a certain COMMAND has been performed on that STRING" + ;; Determine the parent buffer + (let ((parent-buffer (current-buffer))) + (with-temp-buffer + ;; Certain locally set variables can affect common movement + ;; commands such as `forward-word'; determine their values from + ;; the parent buffer and set them in the temporary buffer. + (dolist (context-variable completion-preview-context-variables) + (make-variable-buffer-local context-variable) + (set context-variable (buffer-local-value context-variable parent-buffer))) + + (insert string) + (goto-char (point-min)) + (funcall command) + (cons (buffer-substring-no-properties (point-min) (point)) + (buffer-substring (point) (point-max)))))) + +(defun completion-preview--insert-partial (command) + "A helper function to insert part of the completion candidate that the +preview is showing." + (if completion-preview-active-mode + (let* ((beg (completion-preview--get 'completion-preview-beg)) + (end (completion-preview--get 'completion-preview-end)) + (efn (plist-get (completion-preview--get 'completion-preview-props) + :exit-function)) + (aft (completion-preview--get 'after-string)) + (ful (completion-preview--determine-substring command aft)) + (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 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-word () + "Insert the next word of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert-partial #'forward-word)) + +(defun completion-preview-insert-sexp () + "Insert the next sexp of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert-partial #'forward-sexp)) + (defun completion-preview-complete () "Complete up to the longest common prefix of all completion candidates. @@ -583,6 +661,8 @@ completion-preview--active-p (buffer-local-value 'completion-preview-active-mode buffer)) (dolist (cmd '(completion-preview-insert + completion-preview-insert-word + completion-preview-insert-sexp completion-preview-complete completion-preview-prev-candidate completion-preview-next-candidate)) diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index 7d358d07519..1c8a04c765d 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -292,7 +292,7 @@ completion-preview-insert-calls-exit-function (setq-local completion-at-point-functions (list (completion-preview-tests--capf - '("foobar" "foobaz") + '("foobar-1 2" "foobarverylong") :exit-function (lambda (&rest args) (setq exit-fn-called t @@ -300,11 +300,100 @@ completion-preview-insert-calls-exit-function (insert "foo") (let ((this-command 'self-insert-command)) (completion-preview--post-command)) - (completion-preview-tests--check-preview "bar" 'completion-preview-common) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) (completion-preview-insert) - (should (string= (buffer-string) "foobar")) + (should (string= (buffer-string) "foobar-1 2")) (should-not completion-preview--overlay) (should exit-fn-called) - (should (equal exit-fn-args '("foobar" finished)))))) + (should (equal exit-fn-args '("foobar-1 2" finished)))))) + +(ert-deftest completion-preview-insert-word () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobar")) + (completion-preview-tests--check-preview "-1 2" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-nonsubword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobarBar")) + (should-not completion-preview--overlay) + (should exit-fn-called) + (should (equal exit-fn-args '("foobarBar" finished)))))) + +(ert-deftest completion-preview-insert-subword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (subword-mode) + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobar")) + (completion-preview-tests--check-preview "Bar" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-sexp () + "Test that `completion-preview-insert-word' properly inserts just a sexp." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) + (completion-preview-insert-sexp) + (should (string= (buffer-string) "foobar-1")) + (completion-preview-tests--check-preview " 2" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) ;;; completion-preview-tests.el ends here -- 2.45.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=completion-preview-partial-insertion-with-region-delete.patch Content-Description: New partial insertion functions implemented with in-buffer deletion >From 7fd70fb330e0623636729657b17a9cdac3841a3d Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Sat, 22 Jun 2024 00:45:01 -0700 Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands * lisp/completion-preview.el: Add new completion-preview-insert-word and completion-preview-insert-sexp commands. * test/lisp/completion-preview-tests.el: Add tests for new commands. --- lisp/completion-preview.el | 59 +++++++++++++++- test/lisp/completion-preview-tests.el | 97 +++++++++++++++++++++++++-- 2 files changed, 151 insertions(+), 5 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index caebb9d01e3..e94baab4508 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -90,7 +90,9 @@ completion-preview-commands delete-backward-char backward-delete-char-untabify analyze-text-conversion - completion-preview-complete) + completion-preview-complete + completion-preview-insert-word + completion-preview-insert-sexp) "List of commands that should trigger completion preview." :type '(repeat (function :tag "Command" :value self-insert-command)) :version "30.1") @@ -163,6 +165,8 @@ completion-preview-active-mode-map "M-i" #'completion-preview-complete ;; "M-n" #'completion-preview-next-candidate ;; "M-p" #'completion-preview-prev-candidate + ;; " " #'completion-preview-insert-word + ;; " " #'completion-preview-insert-sexp ) (defun completion-preview--ignore () @@ -463,6 +467,57 @@ completion-preview-insert (when (functionp efn) (funcall efn str 'finished))) (user-error "No current completion preview"))) +(defun completion-preview--insert-partial (command) + "A helper function to insert part of the completion candidate that the +preview is showing." + (if completion-preview-active-mode + (let* ((beg (completion-preview--get 'completion-preview-beg)) + (end (completion-preview--get 'completion-preview-end)) + (efn (plist-get (completion-preview--get 'completion-preview-props) + :exit-function)) + (aft (completion-preview--get 'after-string)) + (new-end) + (full-end)) + ;; Insert the new text + (goto-char end) + (insert aft) + (setq full-end (point)) + + ;; Use the movement command to go to a new location in the buffer + (goto-char end) + (funcall command) + (setq new-end (point)) + + (if (< new-end full-end) + ;; The movement command has not taken us to the end of the + ;; initial insertion this means that a partial completion + ;; occured. + (progn + (completion-preview--inhibit-update) + ;; If we are not inserting a full completion update the preview + (overlay-put (completion-preview--make-overlay + new-end (propertize (delete-and-extract-region full-end new-end) + 'mouse-face 'completion-preview-highlight + 'keymap completion-preview--mouse-map)) + 'completion-preview-end new-end)) + ;; The movement command has taken us to the end of the + ;; completion or past it which signifies a full completion. + (goto-char full-end) + (completion-preview-active-mode -1) + (when (functionp efn) + (funcall efn (concat (buffer-substring-no-properties beg end) aft) 'finished)))) + (user-error "No current completion preview"))) + +(defun completion-preview-insert-word () + "Insert the next word of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert-partial #'forward-word)) + +(defun completion-preview-insert-sexp () + "Insert the next sexp of the completion candidate that the preview is showing." + (interactive) + (completion-preview--insert-partial #'forward-sexp)) + (defun completion-preview-complete () "Complete up to the longest common prefix of all completion candidates. @@ -583,6 +638,8 @@ completion-preview--active-p (buffer-local-value 'completion-preview-active-mode buffer)) (dolist (cmd '(completion-preview-insert + completion-preview-insert-word + completion-preview-insert-sexp completion-preview-complete completion-preview-prev-candidate completion-preview-next-candidate)) diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index 7d358d07519..1c8a04c765d 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -292,7 +292,7 @@ completion-preview-insert-calls-exit-function (setq-local completion-at-point-functions (list (completion-preview-tests--capf - '("foobar" "foobaz") + '("foobar-1 2" "foobarverylong") :exit-function (lambda (&rest args) (setq exit-fn-called t @@ -300,11 +300,100 @@ completion-preview-insert-calls-exit-function (insert "foo") (let ((this-command 'self-insert-command)) (completion-preview--post-command)) - (completion-preview-tests--check-preview "bar" 'completion-preview-common) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) (completion-preview-insert) - (should (string= (buffer-string) "foobar")) + (should (string= (buffer-string) "foobar-1 2")) (should-not completion-preview--overlay) (should exit-fn-called) - (should (equal exit-fn-args '("foobar" finished)))))) + (should (equal exit-fn-args '("foobar-1 2" finished)))))) + +(ert-deftest completion-preview-insert-word () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobar")) + (completion-preview-tests--check-preview "-1 2" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-nonsubword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobarBar")) + (should-not completion-preview--overlay) + (should exit-fn-called) + (should (equal exit-fn-args '("foobarBar" finished)))))) + +(ert-deftest completion-preview-insert-subword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (subword-mode) + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobar")) + (completion-preview-tests--check-preview "Bar" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-sexp () + "Test that `completion-preview-insert-word' properly inserts just a sexp." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) + (completion-preview-insert-sexp) + (should (string= (buffer-string) "foobar-1")) + (completion-preview-tests--check-preview " 2" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) ;;; completion-preview-tests.el ends here -- 2.45.1 --=-=-= Content-Type: text/plain Best, Jules --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 23 20:46:17 2024 Received: (at 71716) by debbugs.gnu.org; 24 Jun 2024 00:46:17 +0000 Received: from localhost ([127.0.0.1]:58938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLXqb-0003Ud-8d for submit@debbugs.gnu.org; Sun, 23 Jun 2024 20:46:17 -0400 Received: from mail-pg1-f173.google.com ([209.85.215.173]:58391) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLXqY-0003U6-Qy for 71716@debbugs.gnu.org; Sun, 23 Jun 2024 20:46:15 -0400 Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-709423bc2e5so2902268a12.0 for <71716@debbugs.gnu.org>; Sun, 23 Jun 2024 17:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719189908; x=1719794708; 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=KCid06Jts5pt9QkhuwZikWRU9RSnc7q2Z/zWqHMOAHo=; b=FzjoRrNm+NkKpfl/EJWsTHfOez+8fYr+WMVIU5pF9NqhOlk+I/LFc1HRzL19eE1vnw RbaGEhBHjzOGpZ2BRU+90yJTKz3RmxNgZz1t9idEr1WKw8moUoqNLosYeAUrg6EqXiQ1 NrZq928+nPyymlRp0AWpUerZAR9d82TJX6t6oBIH21uzxb3V89wvP4MSrODoyszRAaXp ELz3ABPO6blfw1Xl+XBQu7PEsOO8EN2+qGaEFBj9l2uFVkqj1Vf+sfo8Bv5s7VoUJfFL vtE4L172TgTGeG4tme61CKGzDZx6fLSU4n4VAGZYUjZTqoGzzSOaIDmMLTgDXFy9SKvk nCfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719189908; x=1719794708; 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=KCid06Jts5pt9QkhuwZikWRU9RSnc7q2Z/zWqHMOAHo=; b=f9OK+x089LnK6twXyrHaoZcaEDnAIVvTRjSFUdA612V/RgI+LRI69gZJypOZ8smEvC JKhyAAM+LGSGrR/92KTQCV5lYWet6VvTjyl0M5GbgHmZ2NXTcCviZ3lWFb49fJCSfRBv GHDPu94IUQJy9OHDTeVUyqO0mNd2uKV1JfCGab5iERFvWSl1Fex0npMkfIJtjIrKxV2C noho3t8YtuaM6rHBM02AB03v46An12v5Y0nl1PKQXB5+sdOsWNu+0zFCgo1P+BJHxlG3 e6FVslSY7fifNa1LLk/QddNFpqCjjIdl4SUPSUdnqiFW0cm8qfkNw0Sdwc4DrDkvv0IV sijA== X-Gm-Message-State: AOJu0YxqCpoF1hzsADq3qtCP6m0ichitQZt7GjOzLYGc1vT3JVS8xIsK 0t8oElnDSDc2qR9eau7FLstpJ6aHaWKSvbiLdyIJzogw6RzMwe8V0zKHKg== X-Google-Smtp-Source: AGHT+IGb99MO37mGIwxcQ7apap5EKIoJpSO4K//2Q9cxXP/rOZK1G9LKkR+rJSMx9yJPVa+PjHTLEw== X-Received: by 2002:a05:6a20:6720:b0:1bd:be0:7fbe with SMTP id adf61e73a8af0-1bd0be0820dmr730343637.12.1719189907760; Sun, 23 Jun 2024 17:45:07 -0700 (PDT) Received: from jat-framework (c-73-189-85-43.hsd1.ca.comcast.net. [73.189.85.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c819a8c846sm5358115a91.26.2024.06.23.17.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jun 2024 17:45:07 -0700 (PDT) From: Jules Tamagnan To: Eshel Yaron Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <87r0cn5n2s.fsf@gmail.com> (Jules Tamagnan's message of "Sun, 23 Jun 2024 15:08:43 -0700") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> Date: Sun, 23 Jun 2024 17:45:05 -0700 Message-ID: <87msnb5fu6.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) Jules Tamagnan writes: > The second patch > `completion-preview-partial-insertion-with-region-delete.patch` is the > version of the change that uses in-buffer deletion. There's not much to > say here, it seems quite a bit more robust. I guess one thing to mention is that the use of `full-end` and `new-end` could be replaced by `(+ (length aft) end)` and `(point)` respectively which I had originally avoided to reduce calculations but might better fit the style of the code. Another idea would be to add a test proving that `(completion-preview--insert-partial #'end-of-buffer)` will never place the point too far. I have tested this on my own but haven't written a test for it. There are surely other style comments too, maybe the use of whitespace within a function is considered bad form? As always open to any and all feedback. Thanks in advance. Best, Jules From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 24 07:49:21 2024 Received: (at 71716) by debbugs.gnu.org; 24 Jun 2024 11:49:21 +0000 Received: from localhost ([127.0.0.1]:53917 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLiCG-0008FB-OH for submit@debbugs.gnu.org; Mon, 24 Jun 2024 07:49:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60536) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLiCE-0008En-Un for 71716@debbugs.gnu.org; Mon, 24 Jun 2024 07:49:19 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLiC8-0003Dv-Gu; Mon, 24 Jun 2024 07:49:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=F2+3uTPFrPewcqdAFbSmSdyhkHDNA7TmM3TOQxfAYRs=; b=Z3vBzqYnD9Nw 3jNticZeyOfD4tl+Le4QQfjUoZUlmOdOCn/ZRzgHNajU4lO1t66qhZHcmMNX35YQsh1q9bJbIxQz2 g9kg4rWDHb2SsJvzuY9wV/CPct4ziUjLCTGfzT9HdANIRjQs5GWYceJ6wqn+G1iDjY4fzUTckHmHZ 8LUbc6rfbC3MG7Z0ojaw+KnL6tQRjDGWjkGe/JJd5CwPSPEkbdeyT3UXew8ctbwZPdSDGp4bCMsTg 14GWE3IZ54fzc7+Y+uczwuRFdftbojQTKsPY9gb5xYDRfr5NXXF83dzV87g/lYZVvKkf5c34wMoWj iBIqAfJerTsmDl6l6tI/zw==; Date: Mon, 24 Jun 2024 14:49:10 +0300 Message-Id: <86zfrablxl.fsf@gnu.org> From: Eli Zaretskii To: Jules Tamagnan In-Reply-To: <87r0cn5n2s.fsf@gmail.com> (message from Jules Tamagnan on Sun, 23 Jun 2024 15:08:43 -0700) Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 71716 Cc: 71716@debbugs.gnu.org, me@eshelyaron.com 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: -3.3 (---) > Cc: 71716@debbugs.gnu.org > From: Jules Tamagnan > Date: Sun, 23 Jun 2024 15:08:43 -0700 > > +(defcustom completion-preview-context-variables '(char-script-table > + forward-sexp-function > + find-word-boundary-function-table > + inhibit-field-text-motion) > + "List of variables which can change the functionality of `forward-word' > +or `forward-sexp'." > + :type '(repeat (variable :tag "Variable" :value char-script-table)) > + :version "30.1") I don't think we will install new features on the emacs-30 branch, so this :version tag should be updated. And the previous one as well, I guess. > +(defun completion-preview--determine-substring (command string) > + "A helper function to determine what parts of a STRING come before and > +after the point when a certain COMMAND has been performed on that STRING" The first line of a doc string should be a single complete sentence. That's because some help commands, like "M-x apropos", show only the first line of the doc strings. From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 24 08:44:03 2024 Received: (at 71716) by debbugs.gnu.org; 24 Jun 2024 12:44:03 +0000 Received: from localhost ([127.0.0.1]:55990 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLj3C-0001uL-R9 for submit@debbugs.gnu.org; Mon, 24 Jun 2024 08:44:03 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:52388 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLj3A-0001tn-Oz for 71716@debbugs.gnu.org; Mon, 24 Jun 2024 08:44:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1719233039; bh=66TYMPNVawPdFKOm0j+hTN7N783Q07s9yI+ucTBYwoU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=dyJ3bG0dnc4eK09brA/wRkJGgIktgheYHLFMFT0OjfOqzOq3Hnrl+ayLMGUrPUuv5 1TGdKGN3lEH1n9hPbI0VzA9PbBw7SxH7RfvGXg/hq6oorikb5tk4nu0jjye0aOxwlM oUZZb8pxgzViPzDn59HaoD5YsdT8IIqk7AXqrt5OPNEBweNqT5vC8vNycQB8oLkwXQ STrFqPk8zHJXvc7/EoJ+64HiQG97rpqa3aDaWpGg9Kxm9UpF+FS3EkG6EBz1pPoQAX vXZQ1RHU/MtELuxf1gEWz75bcOj8LT+FZqjLqm+9iUXT77CrBweAGBHw7u9HKxGsZ3 PxxZoCO8ObnsA== From: Eshel Yaron To: Jules Tamagnan Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <87r0cn5n2s.fsf@gmail.com> (Jules Tamagnan's message of "Sun, 23 Jun 2024 15:08:43 -0700") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> X-Hashcash: 1:20:240624:jtamagnan@gmail.com::xf7NIMI3OdzzIDOt:WJu X-Hashcash: 1:20:240624:71716@debbugs.gnu.org::OIc32FxbywapWX7e:7Woo Date: Mon, 24 Jun 2024 14:43:56 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) Jules Tamagnan writes: > Hi Eshel, > > I just want to start off once again by saying thank you for the > thoughtful review, help, testing, and encouragement. Gladly, I appreciate your contribution and I'm happy to help with it. > The first patch > `completion-preview-partial-insertion-with-temp-buffer.patch` is the > same as the previous patch but with two critical changes: the revert, > and the addition of a new variable > `completion-preview-context-variables` which can be used to customize > the list of variables to copy into the temporary buffer. > > The second patch > `completion-preview-partial-insertion-with-region-delete.patch` is the > version of the change that uses in-buffer deletion. There's not much to > say here, it seems quite a bit more robust. > > I reckon the second patch is more in line with what you had in mind but > I wanted to bring the first approach to a more acceptable state. Thanks for that, the second patch is looking pretty good. I'm including some comments below, some of these are nits that I can fix myself later. One important point is that I'm a bit hesitant about adding the sexp variant, rather then defining only completion-preview-insert-word, and mentioning in the documentation that other variants are trivial to define (and how). The reason is that I don't have a good idea of when a completion candidate would span multiple sexps (if you have such an example, please share it), so I'm not sure how much utility this command would bring in practice. > From 7fd70fb330e0623636729657b17a9cdac3841a3d Mon Sep 17 00:00:00 2001 > From: Jules Tamagnan > Date: Sat, 22 Jun 2024 00:45:01 -0700 > Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands > > * lisp/completion-preview.el: Add new completion-preview-insert-word and > completion-preview-insert-sexp commands. > * test/lisp/completion-preview-tests.el: Add tests for new commands. It's best to single-quote symbols in the commit message, like 'this'. > +(defun completion-preview--insert-partial (command) This should be a public function (no --), to indicate that it's fine for users to use it in their own command definitions. So either completion-preview-insert-partial or completion-preview-partial-insert. (I tend to prefer the latter, but both work.) Also, COMMAND should instead be FUN or FUNC, since the argument doesn't have to be command, any motion function would do. Lastly this command should also take &rest args and pass them to the function argument, to facilitate writing something like (c-p-partial-insert #'forward-word 2) to complete two words. > + "A helper function to insert part of the completion candidate that the > +preview is showing." The first line of the docstring should be a full sentence. We also want to describe accurately enough what this function does for users to be able to leverage it in their definitions. I suggest: --8<---------------cut here---------------start------------->8--- (defun completion-preview-partial-insert (fun &rest args) "Insert part of the current completion preview candidate. This function calls FUN with arguments ARGS, after temporarily inserting the entire current completion preview candidate. FUN should move point: if it moves point forward into the completion text, this function inserts the prefix of the completion candidate up to that point. Beyond moving point, FUN should not modify the current buffer." --8<---------------cut here---------------end--------------->8--- > + (if completion-preview-active-mode > + (let* ((beg (completion-preview--get 'completion-preview-beg)) > + (end (completion-preview--get 'completion-preview-end)) > + (efn (plist-get (completion-preview--get 'completion-preview-props) > + :exit-function)) > + (aft (completion-preview--get 'after-string)) > + (new-end) > + (full-end)) > + ;; Insert the new text > + (goto-char end) > + (insert aft) Better strip text properties from AFT before inserting it here. > + (setq full-end (point)) > + > + ;; Use the movement command to go to a new location in the buffer > + (goto-char end) > + (funcall command) > + (setq new-end (point)) We should ensure that new-end isn't smaller then end, otherwise the deletion below won't do the right thing. > + (if (< new-end full-end) > + ;; The movement command has not taken us to the end of the > + ;; initial insertion this means that a partial completion > + ;; occured. > + (progn > + (completion-preview--inhibit-update) > + ;; If we are not inserting a full completion update the preview > + (overlay-put (completion-preview--make-overlay > + new-end (propertize (delete-and-extract-region full-end new-end) > + 'mouse-face 'completion-preview-highlight > + 'keymap completion-preview--mouse-map)) > + 'completion-preview-end new-end)) > + ;; The movement command has taken us to the end of the > + ;; completion or past it which signifies a full completion. > + (goto-char full-end) > + (completion-preview-active-mode -1) > + (when (functionp efn) > + (funcall efn (concat (buffer-substring-no-properties beg end) aft) 'finished)))) > + (user-error "No current completion preview"))) This is a nice use of delete-and-extract-region, but the insertion and deletion must be inside an atomic-change-group, so we don't leave AFT inserted in case the motion function signals an error. This is also where we need to add an undo-amalgamate-change-group, to prevent undo from seeing an unwanted intermediate step in case an undo-boundary is created between the insertion and the deletion. So the structure should be something like: --8<---------------cut here---------------start------------->8--- (atomic-change-group (let ((change-group (prepare-change-group))) ;; Insert, ;; Move, ;; Delete. (undo-amalgamate-change-group change-group))) --8<---------------cut here---------------end--------------->8--- > +(defun completion-preview-insert-word () > + "Insert the next word of the completion candidate that the preview is showing." > + (interactive) > + (completion-preview--insert-partial #'forward-word)) This should handle an optional numeric argument, like forward-word does. Finally, we should document completion-preview-insert-word in the Commentary section. Here's the text I'd like to add, you can include it the patch (and change it as you see fit) or I'll add it later: --8<---------------cut here---------------start------------->8--- ;; You can also insert only the first word of the completion candidate ;; with the command `completion-preview-insert-word'. With a numeric ;; prefix argument, it inserts that many words instead of just the one. ;; This command is not bound by default, but you may want to bind it to ;; M-f (or remap `forward-word') in `completion-preview-active-mode-map' ;; since it's very much like a `forward-word' that also moves "into" the ;; completion preview. --8<---------------cut here---------------end--------------->8--- Best, Eshel From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 24 13:17:45 2024 Received: (at 71716) by debbugs.gnu.org; 24 Jun 2024 17:17:45 +0000 Received: from localhost ([127.0.0.1]:35152 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLnK4-0005Xg-8I for submit@debbugs.gnu.org; Mon, 24 Jun 2024 13:17:45 -0400 Received: from mail-pf1-f170.google.com ([209.85.210.170]:59480) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLnK1-0005XT-FR for 71716@debbugs.gnu.org; Mon, 24 Jun 2024 13:17:43 -0400 Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7066c9741fbso2030049b3a.2 for <71716@debbugs.gnu.org>; Mon, 24 Jun 2024 10:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719249394; x=1719854194; 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=DLujXGRUryiQ3Pc8LR/MlUi4fBBKPcKCcCF66eQQ9Xg=; b=NJjZoRwbujPgI+t7LHCXIuyfAYA/m4cB6WOvOxcYbBeKTqTXC5rlhzv4JAS8EVMhmT XFmUJFIwUa4vIfNUm6oTqWotedMfoCijAWVRNZ0ePmHLLY1Ahab2cd6S5yUvhuzsx+sr D7YGzwb3zD+aET4JksGPO2rTBlI4qfTg2qNeheYJwlysJkqaYVgO52CJOR8ieqpXNTan E7hyg7vKb1cwwmdgzrmkU1B+p/mQDmltRvLAsTVebEeQt3ipJ4j3pCvmRCxawTFHxysW qz1DlQ044fxAyhXkDmSDN5WSrw0sPn2FbLkRvbpV4X/xnzPQnRnXuZP0XnwU3Z2OySeZ JfFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719249394; x=1719854194; 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=DLujXGRUryiQ3Pc8LR/MlUi4fBBKPcKCcCF66eQQ9Xg=; b=Ru8mjTPkse6gritQBM6qrLDbQY52LXXCmiWghDO9oBvxF6UpMgflh3YGEYgUKLzRE2 qLmz1GZHZQTnRKBwPf54WNnS2PsPMduutHatZDXy5U7DOnISke9Y9ofwzMeoIzP2Wwi+ 19u/o+ZwIMqcW0t1EiRFAv1nWFO76SCrnspF4fiPlHcMfZ3OAiDtVkRMbcEmzjaTLM5M o0N0h2Z2odwV0c2p+SSEu2n8DoTkJ5wqxTAW26tWyHs64mOdw+Z8r3948uO4fuCcB4hb oYBi94jh7z5qfShzxb3O2/4uKJHd1Xncpd9t8+dP6HFt8hFhlb72xnqWCoVd8UDR6fCk Fl0g== X-Gm-Message-State: AOJu0YxiG+VdkwaTh4scdWcj5gaI+pU8uIn4sSSonTWlKZskCMTKKiT/ 59mgniDtayc2Fqv5I8exOqnvrM9q090l8cSLjPKZqXgCYoDXnmC8WINHhg== X-Google-Smtp-Source: AGHT+IGOqWt/pqMQ80mN7JHqThCJXamgNn5c1wSgewjX9WyHfAusNTRbi9JioCIQX/hq30B9aAd+tA== X-Received: by 2002:a05:6a20:49a8:b0:1b8:b8bd:9427 with SMTP id adf61e73a8af0-1bcf7fb9c91mr5941310637.50.1719249393800; Mon, 24 Jun 2024 10:16:33 -0700 (PDT) Received: from jat-framework (c-73-189-85-43.hsd1.ca.comcast.net. [73.189.85.43]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7065129012asm6662576b3a.146.2024.06.24.10.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 10:16:33 -0700 (PDT) From: Jules Tamagnan To: Eshel Yaron Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: (Eshel Yaron's message of "Mon, 24 Jun 2024 14:43:56 +0200") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> Date: Mon, 24 Jun 2024 10:16:31 -0700 Message-ID: <87bk3q5ki8.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) --=-=-= Content-Type: text/plain Eshel Yaron writes: > One important point is that I'm a bit hesitant about adding the sexp > variant, rather then defining only completion-preview-insert-word, and > mentioning in the documentation that other variants are trivial to > define (and how). The reason is that I don't have a good idea of when > a completion candidate would span multiple sexps (if you have such an > example, please share it), so I'm not sure how much utility this > command would bring in practice. The use case that I have for the sexp variant is when completing eshell history. Both because: parts of shell commands such as file names can be considered sexp's, but also because eshell itself can interpret "full" elisp forms. On a similar note. Some similar tools additionally define a `forward-char` variant. This is not something that I've found a need for personally but would be willing to add for completeness. >> From 7fd70fb330e0623636729657b17a9cdac3841a3d Mon Sep 17 00:00:00 2001 >> From: Jules Tamagnan >> Date: Sat, 22 Jun 2024 00:45:01 -0700 >> Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands >> >> * lisp/completion-preview.el: Add new completion-preview-insert-word and >> completion-preview-insert-sexp commands. >> * test/lisp/completion-preview-tests.el: Add tests for new commands. > > It's best to single-quote symbols in the commit message, like 'this'. Thank you. Done >> +(defun completion-preview--insert-partial (command) > > This should be a public function (no --), to indicate that it's fine for > users to use it in their own command definitions. So either > completion-preview-insert-partial or completion-preview-partial-insert. > (I tend to prefer the latter, but both work.) Thank you. Done > Also, COMMAND should instead be FUN or FUNC, since the argument doesn't > have to be command, any motion function would do. Thank you. Done > Lastly this command should also take &rest args and pass them to the > function argument, to facilitate writing something like > (c-p-partial-insert #'forward-word 2) to complete two words. Thank you. Done Another idea would be to turn `c-p-partial-insert` into a macro that uses the `interactive-form` function to generate a sensible insert-partial function. I'm more than happy to take this tweak on as well. > The first line of the docstring should be a full sentence. We also want > to describe accurately enough what this function does for users to be > able to leverage it in their definitions. I suggest: > > (defun completion-preview-partial-insert (fun &rest args) > "Insert part of the current completion preview candidate. > This function calls FUN with arguments ARGS, after temporarily inserting > the entire current completion preview candidate. FUN should move point: > if it moves point forward into the completion text, this function > inserts the prefix of the completion candidate up to that point. > Beyond moving point, FUN should not modify the current buffer." Thank you. Done > Better strip text properties from AFT before inserting it here. Thank you. Done There were two ways of implementing this that I could think of. 1. Insert with properties, set `suf` to delete-and-extract-region to preserve the properties, use `(set-text-properties end (point) nil)` to remove the text properties from the deletion. 2. Insert without text properties, use `delete-region`, set `suf` to a substring of `aft` directly Both seem to work equally well, I've gone with option 2 because it seems more consistent with what you had suggested. > We should ensure that new-end isn't smaller then end, otherwise the > deletion below won't do the right thing. Thank you. Done > This is a nice use of delete-and-extract-region, but the insertion and > deletion must be inside an atomic-change-group, so we don't leave AFT > inserted in case the motion function signals an error. This is also > where we need to add an undo-amalgamate-change-group, to prevent undo > from seeing an unwanted intermediate step in case an undo-boundary is > created between the insertion and the deletion. So the structure should > be something like: > > (atomic-change-group > (let ((change-group (prepare-change-group))) > ;; Insert, > ;; Move, > ;; Delete. > (undo-amalgamate-change-group change-group))) Thank you. Done I'm glad to better understand how this works now. >> +(defun completion-preview-insert-word () >> + "Insert the next word of the completion candidate that the preview is showing." >> + (interactive) >> + (completion-preview--insert-partial #'forward-word)) > > This should handle an optional numeric argument, like forward-word does. Thank you. Done > Finally, we should document completion-preview-insert-word in the > Commentary section. Here's the text I'd like to add, you can include it > the patch (and change it as you see fit) or I'll add it later: > > ;; You can also insert only the first word of the completion candidate > ;; with the command `completion-preview-insert-word'. With a numeric > ;; prefix argument, it inserts that many words instead of just the one. > ;; This command is not bound by default, but you may want to bind it to > ;; M-f (or remap `forward-word') in `completion-preview-active-mode-map' > ;; since it's very much like a `forward-word' that also moves "into" the > ;; completion preview. Thank you. Done At the end of the paragraph I've additionally added a brief note about the `sexp` variant. > Best, > > Eshel Best, Jules --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=completion-preview-partial-insertion.patch Content-Description: Full patch with addressed comments >From 74d8efceaf8f64f7cf61e36f8a5e8a4fc86e558d Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Mon, 24 Jun 2024 08:53:23 -0700 Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands * lisp/completion-preview.el: Add new 'completion-preview-insert-word' and 'completion-preview-insert-sexp' commands. * test/lisp/completion-preview-tests.el: Add tests for new commands. --- lisp/completion-preview.el | 82 +++++++++++++++++++++- test/lisp/completion-preview-tests.el | 97 +++++++++++++++++++++++++-- 2 files changed, 174 insertions(+), 5 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index caebb9d01e3..14c28b0c76b 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -49,6 +49,16 @@ ;; prefix (so nothing is underlined in the preview), it displays a list ;; of all matching completion candidates. ;; +;; You can also insert only the first word of the completion candidate +;; with the command `completion-preview-insert-word'. With a numeric +;; prefix argument, it inserts that many words instead of just the one. +;; This command is not bound by default, but you may want to bind it to +;; M-f (or remap `forward-word') in `completion-preview-active-mode-map' +;; since it's very much like a `forward-word' that also moves "into" the +;; completion preview. A similar command, +;; `completion-preview-insert-sexp', exists for the `forward-sexp' +;; command. +;; ;; If you set the user option `completion-preview-exact-match-only' to ;; non-nil, Completion Preview mode only suggests a completion ;; candidate when its the only possible completion for the (partial) @@ -90,7 +100,9 @@ completion-preview-commands delete-backward-char backward-delete-char-untabify analyze-text-conversion - completion-preview-complete) + completion-preview-complete + completion-preview-insert-word + completion-preview-insert-sexp) "List of commands that should trigger completion preview." :type '(repeat (function :tag "Command" :value self-insert-command)) :version "30.1") @@ -163,6 +175,8 @@ completion-preview-active-mode-map "M-i" #'completion-preview-complete ;; "M-n" #'completion-preview-next-candidate ;; "M-p" #'completion-preview-prev-candidate + ;; " " #'completion-preview-insert-word + ;; " " #'completion-preview-insert-sexp ) (defun completion-preview--ignore () @@ -463,6 +477,70 @@ completion-preview-insert (when (functionp efn) (funcall efn str 'finished))) (user-error "No current completion preview"))) +(defun completion-preview-partial-insert (function &rest args) + "Insert part of the current completion preview candidate. +This function calls FUN with arguments ARGS, after temporarily inserting +the entire current completion preview candidate. FUN should move point: +if it moves point forward into the completion text, this function +inserts the prefix of the completion candidate up to that point. Beyond +moving point, FUN should not modify the current buffer." + (if completion-preview-active-mode + (let* ((beg (completion-preview--get 'completion-preview-beg)) + (end (completion-preview--get 'completion-preview-end)) + (efn (plist-get (completion-preview--get 'completion-preview-props) + :exit-function)) + (aft (completion-preview--get 'after-string)) + (suf)) + ;; Perform the insertion + (atomic-change-group + (let ((change-group (prepare-change-group))) + ;; Insert full completion + (goto-char end) + (insert (substring-no-properties aft)) + ;; Move forward within the completion + (goto-char end) + (apply function args) + (when (< (point) end) + ;; If the movement function brought us backwards lurch + ;; forward to the original end + (goto-char end)) + ;; Delete. + (when (< (point) (+ end (length aft))) + (delete-region (+ end (length aft)) (point)) + (setq suf (substring aft (- (point) (+ end (length aft))) nil))) + ;; Combine into one change group + (undo-amalgamate-change-group change-group))) + ;; Perform any cleanup actions + (if suf + ;; The movement function has not taken us to the end of the + ;; initial insertion this means that a partial completion + ;; occured. + (progn + (completion-preview--inhibit-update) + ;; If we are not inserting a full completion update the preview + (overlay-put (completion-preview--make-overlay + (point) (propertize suf + 'mouse-face 'completion-preview-highlight + 'keymap completion-preview--mouse-map)) + 'completion-preview-end (point))) + ;; The movement function has taken us to the end of the + ;; completion or past it which signifies a full completion. + (goto-char (+ end (length aft))) + (completion-preview-active-mode -1) + (when (functionp efn) + (funcall efn (buffer-substring-no-properties beg (point)) 'finished)))) + (user-error "No current completion preview"))) + +(defun completion-preview-insert-word (&optional arg) + "Insert the next word of the completion candidate that the preview is showing." + (interactive "^p") + (completion-preview-partial-insert #'forward-word arg)) + +(defun completion-preview-insert-sexp (&optional arg interactive) + "Insert the next sexp of the completion candidate that the preview is showing." + (interactive "^p\nd") + (completion-preview-partial-insert #'forward-sexp arg interactive)) + (defun completion-preview-complete () "Complete up to the longest common prefix of all completion candidates. @@ -583,6 +661,8 @@ completion-preview--active-p (buffer-local-value 'completion-preview-active-mode buffer)) (dolist (cmd '(completion-preview-insert + completion-preview-insert-word + completion-preview-insert-sexp completion-preview-complete completion-preview-prev-candidate completion-preview-next-candidate)) diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index 7d358d07519..1c8a04c765d 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -292,7 +292,7 @@ completion-preview-insert-calls-exit-function (setq-local completion-at-point-functions (list (completion-preview-tests--capf - '("foobar" "foobaz") + '("foobar-1 2" "foobarverylong") :exit-function (lambda (&rest args) (setq exit-fn-called t @@ -300,11 +300,100 @@ completion-preview-insert-calls-exit-function (insert "foo") (let ((this-command 'self-insert-command)) (completion-preview--post-command)) - (completion-preview-tests--check-preview "bar" 'completion-preview-common) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) (completion-preview-insert) - (should (string= (buffer-string) "foobar")) + (should (string= (buffer-string) "foobar-1 2")) (should-not completion-preview--overlay) (should exit-fn-called) - (should (equal exit-fn-args '("foobar" finished)))))) + (should (equal exit-fn-args '("foobar-1 2" finished)))))) + +(ert-deftest completion-preview-insert-word () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobar")) + (completion-preview-tests--check-preview "-1 2" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-nonsubword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobarBar")) + (should-not completion-preview--overlay) + (should exit-fn-called) + (should (equal exit-fn-args '("foobarBar" finished)))))) + +(ert-deftest completion-preview-insert-subword () + "Test that `completion-preview-insert-word' properly inserts just a word." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (subword-mode) + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobarBar" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "barBar" 'completion-preview-common) + (completion-preview-insert-word) + (should (string= (buffer-string) "foobar")) + (completion-preview-tests--check-preview "Bar" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) + +(ert-deftest completion-preview-insert-sexp () + "Test that `completion-preview-insert-word' properly inserts just a sexp." + (let ((exit-fn-called nil) (exit-fn-args nil)) + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar-1 2" "foobarverylong") + :exit-function + (lambda (&rest args) + (setq exit-fn-called t + exit-fn-args args))))) + (insert "foo") + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "bar-1 2" 'completion-preview-common) + (completion-preview-insert-sexp) + (should (string= (buffer-string) "foobar-1")) + (completion-preview-tests--check-preview " 2" 'completion-preview) + (should-not exit-fn-called) + (should-not exit-fn-args)))) ;;; completion-preview-tests.el ends here -- 2.45.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 24 14:12:28 2024 Received: (at 71716) by debbugs.gnu.org; 24 Jun 2024 18:12:28 +0000 Received: from localhost ([127.0.0.1]:35336 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLoB2-0001M8-99 for submit@debbugs.gnu.org; Mon, 24 Jun 2024 14:12:28 -0400 Received: from mail-pl1-f172.google.com ([209.85.214.172]:56646) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLoB0-0001Lt-7a for 71716@debbugs.gnu.org; Mon, 24 Jun 2024 14:12:26 -0400 Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f480624d0fso36098595ad.1 for <71716@debbugs.gnu.org>; Mon, 24 Jun 2024 11:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719252679; x=1719857479; 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=jv6XmND2+x0HrkaZS3UzABnFz8DudO0SzYEKDkZFNn4=; b=e7RoLCU+KZ5cghsRVSOq1ngUqXY/ooN7kmIz67JaK/XNkgA6jStyShZWO/r1kP4Tb+ TxoMkuVwgHqN6GA/K3eS1TSa8QijHnxtmy1lGsF95vCq6OmXhBhJEuXWnX+AZ2uIkeqr 2V2oJ5yWx47hPypcuSWFGjsAFvu644MZl+SYh9WpR5lIqJvcF3YpCekayZpVa9QXW59S 3jc0eAmzbauCjexf+Xf26KuJkN/boF1cjvkuWREoZYtZ2Dz2dKEBd4fVZoJccgz3N+Qw KD4maFtEGSW/xP046n6SZChO/ZShRvSj2Qn4MOnNLYmLBh4vgxPuWl2fqGjPABQQTAXe xRrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719252679; x=1719857479; 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=jv6XmND2+x0HrkaZS3UzABnFz8DudO0SzYEKDkZFNn4=; b=FWtcWlMcK0AQS2sSydhCHjwrTGwZ5ExWp6CMfLzMdQ/BkGfUHMxAh0wHQ1kaMcum2v enVvmQ9njve/5lI8Yf3S5eHlHTAv+8Gj8Qy8XHbumB9j4lCDHIj1iZyhQTUJphgjCTM1 gtM8UOUT8KJBhKX4Uq5jN1B3IEilDxE+a/G2rl55EkchIE1uzSOeWOkF+VYKjCvJbzRI HVYSL29xcXk/NMCES78+QEGy9dq1Lnbo7xYnYID9hhDUaE36EU7mmnMAznlAvndNBspi oqgC5wavr7WyKcEQUc2tiv4b6hzn1tk49pp/ZQ+cxFXJWLOzK0sODusX8b40OtkpI0LW CHPA== X-Gm-Message-State: AOJu0Yx3FI0O+oNfh4rMC/hjF4WrnHFGhiyjOnpnjLlDxuAhBGzjlCkr gUl6vKdf1V+G0wuIvtpH5JBZRrexVNnC2U5BX/LBOfKWbw7wPC9F X-Google-Smtp-Source: AGHT+IE+RdREhawzCbz9hUoWdJhKA36VrBEPKvdBbQt6WHxxDeO/kYRWsgpU0oxr9dkhk/amLEx0Vw== X-Received: by 2002:a17:903:41cd:b0:1f9:9768:ea88 with SMTP id d9443c01a7336-1fa24019ee7mr61439565ad.38.1719252678709; Mon, 24 Jun 2024 11:11:18 -0700 (PDT) Received: from jat-framework (c-73-189-85-43.hsd1.ca.comcast.net. [73.189.85.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9eb3205e8sm65822895ad.68.2024.06.24.11.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 11:11:18 -0700 (PDT) From: Jules Tamagnan To: Eli Zaretskii Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <86zfrablxl.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 24 Jun 2024 14:49:10 +0300") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> <86zfrablxl.fsf@gnu.org> Date: Mon, 24 Jun 2024 11:11:16 -0700 Message-ID: <877cee5hyz.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@debbugs.gnu.org, me@eshelyaron.com 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 (-) Hi Eli, Thank you for the review, I really appreciate it. Eli Zaretskii writes: >> Cc: 71716@debbugs.gnu.org >> From: Jules Tamagnan >> Date: Sun, 23 Jun 2024 15:08:43 -0700 >> >> +(defcustom completion-preview-context-variables '(char-script-table >> + forward-sexp-function >> + find-word-boundary-function-table >> + inhibit-field-text-motion) >> + "List of variables which can change the functionality of `forward-word' >> +or `forward-sexp'." >> + :type '(repeat (variable :tag "Variable" :value char-script-table)) >> + :version "30.1") > > I don't think we will install new features on the emacs-30 branch, so > this :version tag should be updated. And the previous one as well, I > guess. My latest patch for this change actually removed this variable entirely but I'll keep this in mind going forward. >> +(defun completion-preview--determine-substring (command string) >> + "A helper function to determine what parts of a STRING come before and >> +after the point when a certain COMMAND has been performed on that STRING" > > The first line of a doc string should be a single complete sentence. > That's because some help commands, like "M-x apropos", show only the > first line of the doc strings. Similarly, I've removed this function definition but will keep this in mind. Thank you. Best, Jules From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 26 07:41:40 2024 Received: (at 71716) by debbugs.gnu.org; 26 Jun 2024 11:41:40 +0000 Received: from localhost ([127.0.0.1]:38689 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMR1v-0005wC-OR for submit@debbugs.gnu.org; Wed, 26 Jun 2024 07:41:40 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:42572 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMR1t-0005w3-Tr for 71716@debbugs.gnu.org; Wed, 26 Jun 2024 07:41:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1719402094; bh=p8/QSqm47WHY+NDd9tuD77dAIjxl5kdsAL36oeT801o=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=waWKnxuSrZq8TPLkNtX2YvStA4A8cN/HTsJvgd0abzOQsNHyriSUM0fs5Jnq174Ld t+fhGfFBoU2Y2Rm8BX8foqPGhbN2Xk01fX1KD/RfoyQgKbqUUAS5YW87sR7tTby5Jq 6YoC0IIjCEqby6ghDiyFQ5ZRjRB2xrwshjVBZWIO3F9yCaa4fp9Bcvrxse+jN57m2u EqrMS/z0TN9D430UNEsC6vInBwudGZ4zpkHxjDt9GFaCf8sFg1MNCYhejQA+NlbDVz SJqwZHo7z3oFmfYApzmsWpBvkUJvGCFC6Q1B3aXvhz2GqooD6BT8IGRdfcfwMr2Euo DhzRwwGRp+zuQ== From: Eshel Yaron To: Jules Tamagnan Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <87bk3q5ki8.fsf@gmail.com> (Jules Tamagnan's message of "Mon, 24 Jun 2024 10:16:31 -0700") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> <87bk3q5ki8.fsf@gmail.com> X-Hashcash: 1:20:240626:jtamagnan@gmail.com::dSKBq7BsccbvNkpV:0Ih7 X-Hashcash: 1:20:240626:71716@debbugs.gnu.org::AzQa7x+FF/YnFseW:4lpT Date: Wed, 26 Jun 2024 13:41:32 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) Hi Jules, Jules Tamagnan writes: > Eshel Yaron writes: > >> One important point is that I'm a bit hesitant about adding the sexp >> variant, rather then defining only completion-preview-insert-word, and >> mentioning in the documentation that other variants are trivial to >> define (and how). The reason is that I don't have a good idea of when >> a completion candidate would span multiple sexps (if you have such an >> example, please share it), so I'm not sure how much utility this >> command would bring in practice. > > The use case that I have for the sexp variant is when completing eshell > history. Both because: parts of shell commands such as file names can be > considered sexp's, but also because eshell itself can interpret "full" > elisp forms. Thanks, I tried it out with cape-history from cape.el and I can see how it may be useful for such use cases. [...] > Another idea would be to turn `c-p-partial-insert` into a macro that > uses the `interactive-form` function to generate a sensible > insert-partial function. I'm more than happy to take this tweak on as > well. That may be a nice addition. In particular we could have a macro that defines a partial insertion command, and takes care of setting the completion-predicate of the defined command such that it's only available when the completion preview is active. [...] > From 74d8efceaf8f64f7cf61e36f8a5e8a4fc86e558d Mon Sep 17 00:00:00 2001 > From: Jules Tamagnan > Date: Mon, 24 Jun 2024 08:53:23 -0700 > Subject: [PATCH] Add new completion-preview-insert-{word,sexp} commands Thank you, pushed to master as commit b3017e7c252, after some tweaks to the commit message. I've also pushed a follow up commit (9cb2a204088) with some minor refinements, see the commit message for details. One notable change is that completion-preview-partial-insert does not force point to the position of the preview overlay ("end") before calling the motion function. This makes completion-preview-insert-word behave more like forward-word when point is in the middle of a multi-word symbol, with the completion preview at the end of that symbol. I've added another test case that demonstrates this behavior. Could you please give it a try to make sure that everything still works as you expect? Thanks, Eshel From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 27 02:54:57 2024 Received: (at 71716) by debbugs.gnu.org; 27 Jun 2024 06:54:57 +0000 Received: from localhost ([127.0.0.1]:40833 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMj21-00023f-3c for submit@debbugs.gnu.org; Thu, 27 Jun 2024 02:54:57 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:40061) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMj1y-00023G-Bx for 71716@debbugs.gnu.org; Thu, 27 Jun 2024 02:54:55 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 07FBD40003; Thu, 27 Jun 2024 06:54:43 +0000 (UTC) From: Juri Linkov To: Jules Tamagnan Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <87bk3q5ki8.fsf@gmail.com> (Jules Tamagnan's message of "Mon, 24 Jun 2024 10:16:31 -0700") Organization: LINKOV.NET References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> <87bk3q5ki8.fsf@gmail.com> Date: Thu, 27 Jun 2024 09:33:04 +0300 Message-ID: <86r0cjdjpz.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@debbugs.gnu.org, Eshel Yaron 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.7 (-) > +;; This command is not bound by default, but you may want to bind it to > +;; M-f (or remap `forward-word') in `completion-preview-active-mode-map' > +;; since it's very much like a `forward-word' that also moves "into" the > +;; completion preview. Also this is very much like 'C-w' in Isearch (isearch-yank-word-or-char), and 'C-w' does nothing without the region, only raises an error "The mark is not set now, so there is no region". So 'C-w' could be bound by default. From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 27 14:55:07 2024 Received: (at 71716) by debbugs.gnu.org; 27 Jun 2024 18:55:07 +0000 Received: from localhost ([127.0.0.1]:43352 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMuGx-0001Vs-1L for submit@debbugs.gnu.org; Thu, 27 Jun 2024 14:55:07 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:33624 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMuGu-0001Vh-DQ for 71716@debbugs.gnu.org; Thu, 27 Jun 2024 14:55:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1719514500; bh=66oaCTO1GlSFUg9iJy+PNZQi3JSIxAH6uC+uyEwsC2M=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=wHlN21O8aNWgdtZXQ1f6rKjQe4xsu/5q4k5anWEd6SF9ZROWgByS1r3umfIEGT3gC a+XUME52xfq/82xDxymVpfRnlV/p2nHF6MwwLSTmZ+yNhf3QC8Hx2ta94qab2+Zb0W gs2Jg9uVklhNuOzYda5GMmpfRN98flACwsk6RYBHUiXZ0U1L5ZXSV+fo08dZ3EEhaL igLhYAAnHm3ALNTAre40JTVF0pPJP63YqcXmlEQd5KIKNQw/5N4EAzg5LpzXjc5Lih 0J19+YvuZTVk9+jAnDuB5Zjbklh9YjmcipJQlQUDBw7o2F2GD6kvHOYcTvIAKwjxdx HiPZGyi05IwUg== From: Eshel Yaron To: Juri Linkov Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <86r0cjdjpz.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 27 Jun 2024 09:33:04 +0300") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> <87bk3q5ki8.fsf@gmail.com> <86r0cjdjpz.fsf@mail.linkov.net> Date: Thu, 27 Jun 2024 20:31:59 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@debbugs.gnu.org, Jules Tamagnan 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 (-) Hi Juri, Juri Linkov writes: >> +;; This command is not bound by default, but you may want to bind it to >> +;; M-f (or remap `forward-word') in `completion-preview-active-mode-map' >> +;; since it's very much like a `forward-word' that also moves "into" the >> +;; completion preview. > > Also this is very much like 'C-w' in Isearch (isearch-yank-word-or-char), > and 'C-w' does nothing without the region, only raises an error > "The mark is not set now, so there is no region". > So 'C-w' could be bound by default. Thanks, that's an interesting suggestion. I prefer not to bind completion-preview-insert-word by default right away, because Completion Preview mode should by default be unintrusive, and bindings in completion-preview-active-mode-map override bindings that users may have in place when the preview appears. But if you use this binding and find it convenient, feel free to add such a recommendation to the commentary. Best, Eshel From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 28 01:50:11 2024 Received: (at 71716) by debbugs.gnu.org; 28 Jun 2024 05:50:11 +0000 Received: from localhost ([127.0.0.1]:51349 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sN4Ut-0000Ns-8e for submit@debbugs.gnu.org; Fri, 28 Jun 2024 01:50:11 -0400 Received: from mail-pj1-f52.google.com ([209.85.216.52]:61901) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sN4Uq-0000Nb-Ux for 71716@debbugs.gnu.org; Fri, 28 Jun 2024 01:50:09 -0400 Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2c889d6995aso167010a91.3 for <71716@debbugs.gnu.org>; Thu, 27 Jun 2024 22:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719553744; x=1720158544; 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=eZCUQrFHkK8qcdomb9fM9hQk/XNYKthLN0HRRxg+kzc=; b=nRTg24lKBhovbbJDNSTZBKDi813RDKaYTnpBqPSbqoGmBIfbbKjQVLr/swpyPWDK2/ pGsWAch+pMFOWQEJ5W33gyzcjhPFJyt5MOgaZ6DO/C4RDC4uV2oyqrF0zjtWwpauY6zW G3opTnyAUmeDy5LjuXTWHAwv6icxXZ7nQM8zxKZo7CuZUposuD4/XZwLN8S3ptJT7/sF QN6d3XJmi9DHKF1HBU7aKK4WAV2y4MxA2/xNCjyuY7RsAYkmlNexf6TA9KoaLcyZnrkX HgnWidhaLe/c/pcWOaAVk/eAdtUoOoPikOe4tXj3nj/jyPmDRpIDyNrJwyM9nbypbH+0 VZ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719553744; x=1720158544; 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=eZCUQrFHkK8qcdomb9fM9hQk/XNYKthLN0HRRxg+kzc=; b=F+543jnLWV9EFqk2QDqx+vyEYY26aS8pkuLZzuO45daEV/n5HRufOJsSot4HRlNS0i v26m/H6mg0np42QAPibV+PJRLQMh5hXDjd7+Lx7Kb4dDzzPrSFWfGc95s8BQp5UsqQUr hYeiiImQLr20AF92qqW+yYOA1f3+mvTEOIl7C2DFjBgDhJsrSiBK+yzMXhWg2gTzICjc xuI3c0uervS5DcIqQSWJZRJCf/0b7kgBwugf8LOqLWJ/QN1gYK6OlBV5XszYhKCEWmlx thFQrHxBKtNFT3tB/BAWSZ3olpp8JFU0i+7VYVslZHlSgiP3ovkd8lNf1DZMD92uu3/C D+jw== X-Gm-Message-State: AOJu0Yz55zUBqXwIj66Hd5jv125RIPDxQJgINjjFEo0naid1umsKzl2G Th8h8YeH88aurb9BP1OnD+TMTqXJKmbl0bumqcQpBOpShNgei0O8P7K8bA== X-Google-Smtp-Source: AGHT+IFpZKNnC9IxNJvZkRUaSjlvc3V3puJizdJ+cQRV+t1K1kC0t/Hx9myos5jyLafKn9aWOB0PZw== X-Received: by 2002:a17:90a:7c06:b0:2c2:fe3d:3453 with SMTP id 98e67ed59e1d1-2c86124c9f7mr12785211a91.18.1719553743999; Thu, 27 Jun 2024 22:49:03 -0700 (PDT) Received: from jat-framework (c-73-189-85-43.hsd1.ca.comcast.net. [73.189.85.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce17b9fsm763459a91.9.2024.06.27.22.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:49:03 -0700 (PDT) From: Jules Tamagnan To: Eshel Yaron Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: (Eshel Yaron's message of "Wed, 26 Jun 2024 13:41:32 +0200") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> <87bk3q5ki8.fsf@gmail.com> Date: Thu, 27 Jun 2024 22:49:02 -0700 Message-ID: <87r0chty5t.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) Eshel Yaron writes: > Thank you, pushed to master as commit b3017e7c252, after some tweaks to > the commit message. I've also pushed a follow up commit (9cb2a204088) > with some minor refinements, see the commit message for details. One > notable change is that completion-preview-partial-insert does not force > point to the position of the preview overlay ("end") before calling the > motion function. This makes completion-preview-insert-word behave more > like forward-word when point is in the middle of a multi-word symbol, > with the completion preview at the end of that symbol. I've added > another test case that demonstrates this behavior. > > Could you please give it a try to make sure that everything still works > as you expect? > > Thanks, > > Eshel I've taken this change around the block since yesterday and everything seems to be working exactly as I would expect it to. I've also reviewed the cleanup that you did and tried to take some notes, especially on the commit message. Thanks again for all of the work that you put into creating this packaging in the first place, helping me through my change, and cleaning up the rough edges in the aftermath. Best, Jules From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 28 11:00:20 2024 Received: (at 71716) by debbugs.gnu.org; 28 Jun 2024 15:00:20 +0000 Received: from localhost ([127.0.0.1]:46075 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sND5I-0005y7-7L for submit@debbugs.gnu.org; Fri, 28 Jun 2024 11:00:20 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:34146 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sND5G-0005xu-OU; Fri, 28 Jun 2024 11:00:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1719586817; bh=+fBzWTlmTUEHVcfk1OxhT7DI9M1MOKTa62vUPj1yZIY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=ICar2CHuBTO+IilVPzyDXz7Rglv/h/GlCPfejJQLvBFHDPKeQIHw9prgiRiKePYWa BNUlAVB9o6fPAbt0CqeiU5COrzUkV/4gBPEAvZTPS1wv5adStGM1gnm7audYJx/Ahg e43HYBbManv/b2eCMy2qcG6c1BDcFCj8J+JAf4KWE91P3RCeY+W2hx1LP85T20V47C g6UIFNRcY5yln3Us80zNEkJtLZR4Vf6MiFGziP0oCEGL1EaclJmte6HMyKfBfw/WRz nFo2h6Sc8y8UpmYfFKvmGHLWy1uolJgmPpu9u1on03QeB9TgLM6Z70oav6AnKkOcwY 12BNMCI6hcoOQ== From: Eshel Yaron To: Jules Tamagnan Subject: Re: bug#71716: [PATCH] Add new completion-preview-insert-{word, sexp} commands In-Reply-To: <87r0chty5t.fsf@gmail.com> (Jules Tamagnan's message of "Thu, 27 Jun 2024 22:49:02 -0700") References: <87a5jd8hqh.fsf@gmail.com> <877ceg9546.fsf@gmail.com> <874j9k8wpo.fsf@gmail.com> <87r0cn5n2s.fsf@gmail.com> <87bk3q5ki8.fsf@gmail.com> <87r0chty5t.fsf@gmail.com> X-Hashcash: 1:20:240628:jtamagnan@gmail.com::vySGYWXU41tZmWf0:OrQ X-Hashcash: 1:20:240628:71716@debbugs.gnu.org::Y8DCdxHjRuoJyvia:06L+ Date: Fri, 28 Jun 2024 17:00:15 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71716 Cc: 71716@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 (-) close 71716 31.1 quit Jules Tamagnan writes: > Eshel Yaron writes: > >> Thank you, pushed to master as commit b3017e7c252, after some tweaks to >> the commit message. I've also pushed a follow up commit (9cb2a204088) >> with some minor refinements, see the commit message for details. One >> notable change is that completion-preview-partial-insert does not force >> point to the position of the preview overlay ("end") before calling the >> motion function. This makes completion-preview-insert-word behave more >> like forward-word when point is in the middle of a multi-word symbol, >> with the completion preview at the end of that symbol. I've added >> another test case that demonstrates this behavior. >> >> Could you please give it a try to make sure that everything still works >> as you expect? >> >> Thanks, >> >> Eshel > > I've taken this change around the block since yesterday and everything > seems to be working exactly as I would expect it to. Great, I'm therefore closing this bug. > I've also reviewed the cleanup that you did and tried to take some > notes, especially on the commit message. There was actually one more small issue that I now fixed in commit 5e3b94e1bec - in case completion-preview-insert-word would just move word without leaving anything inserted, it would still record an unwanted undo operation (that just inserts and deletes everything again, basically a no-op). Now we avoid recording anything in buffer-undo-list if we're only moving point. > Thanks again for all of the work that you put into creating this > packaging in the first place, helping me through my change, and > cleaning up the rough edges in the aftermath. Thank you for this nice contribution! Eshel From unknown Wed Jun 18 00:24:24 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 27 Jul 2024 11:24:06 +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