From dabd42adc78ef3c3e8f40f913325941246993628 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Wed, 18 Sep 2024 08:52:54 -0400 Subject: [PATCH] Preserve suffix in emacs22 style --- lisp/minibuffer.el | 14 ++++++++++++-- lisp/simple.el | 11 +++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 804afe9cb43..a28041751aa 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3771,10 +3771,20 @@ completion-emacs22-try-completion (setq suffix (substring suffix 1))) (cons (concat completion suffix) (length completion)))))) +(defface completions-ignored + '((t (:inherit shadow))) + "Face for text which was ignored by the completion style.") + (defun completion-emacs22-all-completions (string table pred point) - (let ((beforepoint (substring string 0 point))) + (let ((beforepoint (substring string 0 point)) + (suffix (propertize (substring string point) 'face 'completions-ignored))) (completion-hilit-commonality - (all-completions beforepoint table pred) + (mapcar + (lambda (elem) + (let ((s (concat elem suffix))) + (put-text-property 0 1 'completion-position-after-insert (length elem) s) + s)) + (all-completions beforepoint table pred)) point (car (completion-boundaries beforepoint table pred ""))))) diff --git a/lisp/simple.el b/lisp/simple.el index e35cfe0479b..881eb51e57a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10371,10 +10371,13 @@ choose-completion-string ;; comes from buffer-substring-no-properties. ;;(remove-text-properties 0 (length choice) '(mouse-face nil) choice) ;; Insert the completion into the buffer where it was requested. - (funcall (or insert-function completion-list-insert-choice-function) - (or (car base-position) (point)) - (or (cadr base-position) (point)) - choice) + (let ((beg (or (car base-position) (point))) + (end (or (cadr base-position) (point)))) + (funcall (or insert-function completion-list-insert-choice-function) + beg end choice) + (unless (string-empty-p choice) + (when-let ((pos (get-text-property 0 'completion-position-after-insert choice))) + (goto-char (+ pos beg))))) ;; Update point in the window that BUFFER is showing in. (let ((window (get-buffer-window buffer t))) (set-window-point window (point))) -- 2.39.3