unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: Spencer Baugh <sbaugh@janestreet.com>, Eli Zaretskii <eliz@gnu.org>
Cc: 70968@debbugs.gnu.org, monnier@iro.umontreal.ca, juri@linkov.net
Subject: bug#70968: 29.2.50; choose-completion on an emacs22-style completion deletes text after point
Date: Tue, 22 Oct 2024 01:10:49 +0100	[thread overview]
Message-ID: <1446df3a-8670-4ae5-83ad-b4421e647ef3@gutov.dev> (raw)
In-Reply-To: <8479c25d-b4ae-4e89-9880-0857a996936a@gutov.dev>

[-- Attachment #1: Type: text/plain, Size: 646 bytes --]

On 24/09/2024 03:03, Dmitry Gutov wrote:
> 
> The attached patch does not make a distinction for file name completion 
> - it just covers the core problem - but I think any UI could use the 
> addition and likewise lookup the 'file' category, and print the "hidden" 
> suffix in the Completions, and decide to drop the suffix in your first 
> scenario (file name completion with exit imminent).

Here's a halfway PoC of the UI printing the suffix based on the metadata 
property with emacs22 (without special behavior for files yet, but it 
should be straightforward to add the same set of conditions - the 
category, completion boundaries, etc).

[-- Attachment #2: completion--emacs22-adjust-metadata-with-shadow-suffix.diff --]
[-- Type: text/x-patch, Size: 4241 bytes --]

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 804afe9cb43..595fdcd2288 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2568,6 +2568,10 @@ completions--after-change
       (with-selected-window window
         (completions--deselect)))))
 
+(defface completions-ignored
+  '((t (:inherit shadow)))
+  "Face for text which was ignored by the completion style.")
+
 (defun minibuffer-completion-help (&optional start end)
   "Display a list of possible completions of the current minibuffer contents."
   (interactive)
@@ -2613,7 +2617,6 @@ minibuffer-completion-help
                                              (buffer-substring (point) end))))
                 (point)))
              (field-char (and (< field-end end) (char-after field-end)))
-             (base-position (list (+ start base-size) field-end))
              (all-md (completion--metadata (buffer-substring-no-properties
                                             start (point))
                                            base-size md
@@ -2623,6 +2626,13 @@ minibuffer-completion-help
              (aff-fun (completion-metadata-get all-md 'affixation-function))
              (sort-fun (completion-metadata-get all-md 'display-sort-function))
              (group-fun (completion-metadata-get all-md 'group-function))
+             (ignore-after-point (completion-metadata-get
+                                  all-md 'completion-ignore-after-point))
+             (base-position (list (+ start base-size)
+                                  (if ignore-after-point
+                                      (point)
+                                    field-end)))
+             (ignore-suffix (completion-metadata-get all-md 'completion-ignore-after-point))
              (mainbuf (current-buffer))
              ;; If the *Completions* buffer is shown in a new
              ;; window, mark it as softly-dedicated, so bury-buffer in
@@ -2668,6 +2678,14 @@ minibuffer-completion-help
                                             ('historical (minibuffer-sort-by-history completions))
                                             (_ (funcall completions-sort completions)))))
 
+                      (when ignore-suffix
+                        (let ((hidden-suffix (propertize (buffer-substring (point) end)
+                                                         'face
+                                                         'completions-ignored)))
+                          (setq completions
+                                (mapcar (lambda (s) (concat s hidden-suffix))
+                                        completions))))
+
                       ;; After sorting, group the candidates using the
                       ;; `group-function'.
                       (when group-fun
@@ -3778,6 +3796,13 @@ completion-emacs22-all-completions
      point
      (car (completion-boundaries beforepoint table pred "")))))
 
+(put 'emacs22 'completion--adjust-metadata 'completion--emacs22-adjust-metadata)
+
+(defun completion--emacs22-adjust-metadata (metadata)
+  `(metadata
+    (completion-ignore-after-point . t)
+    ,@(cdr metadata)))
+
 ;;; Basic completion.
 
 (defun completion--merge-suffix (completion point suffix)
diff --git a/lisp/simple.el b/lisp/simple.el
index e35cfe0479b..a495231c211 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10264,6 +10264,7 @@ choose-completion
           (base-position completion-base-position)
           (insert-function completion-list-insert-choice-function)
           (completion-no-auto-exit (if no-exit t completion-no-auto-exit))
+          (ignore-face nil)
           (choice
            (if choose-completion-deselect-if-after
                (or (get-text-property (posn-point (event-start event))
@@ -10285,6 +10286,10 @@ choose-completion
                              beg))
                (get-text-property beg 'completion--string))))))
 
+      (when (get-text-property (1- (length choice)) 'face choice)
+        (setq ignore-face (previous-single-property-change (1- (length choice)) 'face choice))
+        (setq choice (substring choice 0 ignore-face)))
+
       (unless (buffer-live-p buffer)
         (error "Destination buffer is dead"))
       (unless no-quit

  parent reply	other threads:[~2024-10-22  0:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15 20:26 bug#70968: 29.2.50; choose-completion on an emacs22-style completion deletes text after point Spencer Baugh
2024-05-16  8:13 ` Eli Zaretskii
2024-05-16 17:26   ` Dmitry Gutov
2024-05-16 18:25     ` Eli Zaretskii
2024-08-26  0:08       ` Dmitry Gutov
2024-09-07  7:30         ` Eli Zaretskii
2024-09-08  2:02           ` Dmitry Gutov
2024-09-08 11:12           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-10 16:54             ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-14  9:17               ` Eli Zaretskii
2024-09-14 15:18                 ` Dmitry Gutov
2024-09-14 16:00                   ` Eli Zaretskii
2024-09-16 19:54                 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-24  0:03                   ` Dmitry Gutov
2024-10-15 18:53                     ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-17  0:19                       ` Dmitry Gutov
2024-10-22  0:10                     ` Dmitry Gutov [this message]
2024-05-16 17:40   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-16 18:28     ` Eli Zaretskii
2024-06-20 15:45 ` Spencer Baugh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446df3a-8670-4ae5-83ad-b4421e647ef3@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=70968@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=juri@linkov.net \
    --cc=monnier@iro.umontreal.ca \
    --cc=sbaugh@janestreet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).