"In-buffer completion preview."
:group 'completion)
+(defcustom completion-preview-exact-match-only nil
+ "Whether to show completion preview only when there is an exact match.
+
+If this option is non-nil, Completion Preview mode only shows the
+preview overlay when there is exactly one completion candidate
+that matches the symbol at point, otherwise it shows the top
+candidate also when there are multiple matching candidates."
+ :type 'boolean)
+
(defcustom completion-preview-commands '(self-insert-command)
"List of commands that should trigger completion preview."
:type '(repeat (function :tag "Command" :value self-insert-command)))
(when last
(setcdr last nil)
(let* ((sorted (funcall sort-fn all))
+ (multi (cadr sorted)) ; multiple candidates
(cand (car sorted)))
- (when (string-prefix-p string cand)
- (let* ((face (if (cadr sorted) 'completion-preview 'completion-preview-exact))
+ (when (and (not (and multi completion-preview-exact-match-only))
+ (string-prefix-p string cand))
+ (let* ((face (if multi 'completion-preview 'completion-preview-exact))
(after (propertize (substring cand (length string)) 'face face)))
(unless (string-empty-p after)
(add-text-properties 0 1 '(cursor 1) after))