diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 144cda8cfdc..d8952094196 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2551,6 +2551,25 @@ completions--after-change (with-selected-window window (completions--deselect))))) +(defun completions--count-common-spans (str) + (let ((pos 0) + prev-pos + value + (sum 0)) + (while pos + (when prev-pos + (cl-incf sum (- pos prev-pos))) + (if (and (setq value (get-text-property pos 'face str)) + (if (listp value) + (memq 'completions-common-part value) + (eq 'completions-common-part value))) + (setq prev-pos pos) + (setq prev-pos nil)) + (setq pos (next-single-property-change pos 'face str)) + (when (and (not pos) prev-pos) + (cl-incf sum (- (length str) prev-pos)))) + sum)) + (defun minibuffer-completion-help (&optional start end) "Display a list of possible completions of the current minibuffer contents." (interactive) @@ -2706,6 +2725,10 @@ minibuffer-completion-help ;; but that clashed with another existing marker. (cl-decf (nth 1 base-position) (- end start (length choice))) + ;; Completion style that doesn't match suffix. + (unless (> (completions--count-common-spans choice) + (- (point) start)) + (setq end (point))) ;; FIXME: Use `md' to do quoting&terminator here. (completion--replace start (min end (point-max)) choice) (let* ((minibuffer-completion-table ctable)