'((t :underline t :inherit completion-preview))
"Face for exact completion preview overlay.")
-(defvar-keymap completion-preview-active-mode-map
- :doc "Keymap for Completion Preview Active mode."
- "C-M-i" #'completion-preview-insert)
-
(defvar-local completion-preview--overlay nil)
(defun completion-preview--sort-by-length-alpha (elems)
(while-no-input
(completion-preview-show))))
+(defun completion-preview--insert ()
+ "Insert the completion preview suggestion."
+ (let ((after (substring-no-properties
+ (overlay-get completion-preview--overlay 'after-string)))
+ (string (overlay-get completion-preview--overlay
+ 'completion-preview-string))
+ (plist (overlay-get completion-preview--overlay
+ 'completion-preview-plist)))
+ (completion-preview-active-mode -1)
+ (insert after)
+ (when-let ((exit-fn (plist-get plist :exit-function)))
+ (funcall exit-fn string 'finished))))
+
+(defun completion-preview-insert-function ()
+ "Return a function inserting the completion preview."
+ #'completion-preview--insert)
+
(define-minor-mode completion-preview-active-mode
"Mode for when the completion preview is active."
:interactive nil
- (unless completion-preview-active-mode (completion-preview-hide))
- (force-mode-line-update))
-
-(defun completion-preview-insert ()
- "Insert the completion preview suggestion."
- (interactive)
(if completion-preview-active-mode
- (let ((after (substring-no-properties
- (overlay-get completion-preview--overlay 'after-string)))
- (string (overlay-get completion-preview--overlay
- 'completion-preview-string))
- (plist (overlay-get completion-preview--overlay
- 'completion-preview-plist)))
- (completion-preview-active-mode -1)
- (insert after)
- (when-let ((exit-fn (plist-get plist :exit-function)))
- (funcall exit-fn string 'finished)))
- (user-error "No active completion preview")))
+ (add-hook 'completion-at-point-functions
+ #'completion-preview-insert-function -1 t)
+ (remove-hook 'completion-at-point-functions
+ #'completion-preview-insert-function t)
+ (completion-preview-hide)))
;;;###autoload
(define-minor-mode completion-preview-mode