From: Eshel Yaron Date: Thu, 26 Oct 2023 18:05:12 +0000 (+0200) Subject: Update 'completion-preview' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2ab29974f19b5c5a9ff93eba973657686273d498;p=dotfiles.git Update 'completion-preview' --- diff --git a/.emacs.d/lisp/completion-preview.el b/.emacs.d/lisp/completion-preview.el index c38b9c4..46b45fa 100644 --- a/.emacs.d/lisp/completion-preview.el +++ b/.emacs.d/lisp/completion-preview.el @@ -30,6 +30,15 @@ "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))) @@ -95,9 +104,11 @@ all of the functions return non-nil." (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))