Make package-lint happy
Also bumping version to 1.2
This commit is contained in:
parent
ef8c36c6d8
commit
88e4fce36c
1 changed files with 60 additions and 60 deletions
|
@ -5,8 +5,8 @@
|
|||
;; Author: Adam Kruszewski <adam@kruszewski.name>
|
||||
;; Maintainer: Adam Kruszewski <adam@kruszewski.name>
|
||||
;; Created: 2023
|
||||
;; Version: 1.1
|
||||
;; Package-Requires: ((emacs "27.1") (corfu "0.36"))
|
||||
;; Version: 1.2
|
||||
;; Package-Requires: ((emacs "28.1") (corfu "0.36"))
|
||||
;; Homepage: https://code.bsdgeek.org/adam/corfu-candidate-overlay/
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
@ -39,16 +39,16 @@
|
|||
|
||||
(require 'corfu)
|
||||
|
||||
(defvar-local corfu--candidate-overlay nil
|
||||
(defvar-local corfu-candidate-overlay--overlay nil
|
||||
"Overlay for Corfu candidates display when typing.")
|
||||
|
||||
(defvar-local corfu--candidate-last-point nil
|
||||
(defvar-local corfu-candidate-overlay--last-point nil
|
||||
"Last point location when the overlay was calculated for.")
|
||||
|
||||
(defvar corfu--candidate-overlay-map nil
|
||||
(defvar corfu-candidate-overlay-map nil
|
||||
"Keymap to dismiss the Corfu candidate overlay.")
|
||||
|
||||
(defcustom corfu-overlay-auto-commands
|
||||
(defcustom corfu-candidate-overlay-auto-commands
|
||||
'("delete-backward-char\\'" "backward-delete-char-untabify")
|
||||
"Additional commands apart from ``corfu-auto-commands'' which initiate
|
||||
completion candidate overlay."
|
||||
|
@ -66,68 +66,68 @@
|
|||
'((t (:inherit 'corfu-candidate-overlay-face :underline t)))
|
||||
"Face used for the overlay when there is only one candidate.")
|
||||
|
||||
(defun corfu--candiate-overlay-prepare (position)
|
||||
(defun corfu-candidate-overlay--prepare (position)
|
||||
"Sets the default properties of the candidates overlay.
|
||||
The overlay can be dismissed with a mouse click."
|
||||
(when (not corfu--candidate-overlay-map)
|
||||
(setq corfu--candidate-overlay-map (make-sparse-keymap))
|
||||
(define-key corfu--candidate-overlay-map (kbd "<mouse-1>")
|
||||
(when (not corfu-candidate-overlay-map)
|
||||
(setq corfu-candidate-overlay-map (make-sparse-keymap))
|
||||
(define-key corfu-candidate-overlay-map (kbd "<mouse-1>")
|
||||
(lambda ()
|
||||
(interactive)
|
||||
(delete-overlay corfu--candidate-overlay))))
|
||||
(delete-overlay corfu-candidate-overlay--overlay))))
|
||||
|
||||
(if corfu--candidate-overlay
|
||||
(move-overlay corfu--candidate-overlay position position)
|
||||
(if corfu-candidate-overlay--overlay
|
||||
(move-overlay corfu-candidate-overlay--overlay position position)
|
||||
(progn
|
||||
(setq corfu--candidate-overlay (make-overlay position position nil))
|
||||
(setq corfu-candidate-overlay--overlay (make-overlay position position nil))
|
||||
;; priority of 1k is the value used by Corfu.
|
||||
(overlay-put corfu--candidate-overlay 'priority 1000))))
|
||||
(overlay-put corfu-candidate-overlay--overlay 'priority 1000))))
|
||||
|
||||
(defun corfu--get-overlay-property (property)
|
||||
(defun corfu-candidate-overlay--get-overlay-property (property)
|
||||
"Returns the value of overlays' property"
|
||||
(overlay-get corfu--candidate-overlay property))
|
||||
(overlay-get corfu-candidate-overlay--overlay property))
|
||||
|
||||
(defun corfu--set-overlay-property (property value)
|
||||
(defun corfu-candidate-overlay--set-overlay-property (property value)
|
||||
"Returns the value of overlays' property"
|
||||
(overlay-put corfu--candidate-overlay property value))
|
||||
(overlay-put corfu-candidate-overlay--overlay property value))
|
||||
|
||||
(defun corfu--candidate-overlay-update (position prefix candidate how-many-candidates)
|
||||
(defun corfu-candidate-overlay--update (position prefix candidate how-many-candidates)
|
||||
"Updates the candidate overlay with the first candidate found by Corfu."
|
||||
(corfu--candiate-overlay-prepare position)
|
||||
(corfu-candidate-overlay--prepare position)
|
||||
|
||||
(unless (string-empty-p candidate)
|
||||
(add-text-properties 0 1 '(cursor 1) candidate))
|
||||
|
||||
(overlay-put corfu--candidate-overlay 'window (selected-window))
|
||||
(overlay-put corfu-candidate-overlay--overlay 'window (selected-window))
|
||||
;; we store the whole candidate and prefix as a property to use when
|
||||
;; deleting characters in quick succession so the backend will not
|
||||
;; keep-up. We will need to use those stored values then to still
|
||||
;; show the overlay with a meaningful suggestion
|
||||
;; (i.e. the last one found)
|
||||
(corfu--set-overlay-property 'corfu-candidate candidate)
|
||||
(corfu--set-overlay-property 'corfu-prefix prefix)
|
||||
(corfu--set-overlay-property 'corfu-count how-many-candidates)
|
||||
(corfu-candidate-overlay--set-overlay-property 'corfu-candidate candidate)
|
||||
(corfu-candidate-overlay--set-overlay-property 'corfu-prefix prefix)
|
||||
(corfu-candidate-overlay--set-overlay-property 'corfu-count how-many-candidates)
|
||||
;; and here is the candidate string as it will be rendered by Emacs.
|
||||
(corfu--set-overlay-property 'after-string
|
||||
(corfu-candidate-overlay--set-overlay-property 'after-string
|
||||
(propertize
|
||||
candidate
|
||||
'face (if (= how-many-candidates 1)
|
||||
'corfu-candidate-overlay-face-exact-match
|
||||
'corfu-candidate-overlay-face)
|
||||
'keymap corfu--candidate-overlay-map)))
|
||||
'keymap corfu-candidate-overlay-map)))
|
||||
|
||||
(defun corfu-hide-candidate-overlay ()
|
||||
(defun corfu-candidate-overlay--hide ()
|
||||
"Hide the candidate overlay."
|
||||
(when (and
|
||||
corfu--candidate-overlay
|
||||
(overlayp corfu--candidate-overlay))
|
||||
corfu-candidate-overlay--overlay
|
||||
(overlayp corfu-candidate-overlay--overlay))
|
||||
;; 'invisible property doesn't work really; deleting the overlay
|
||||
;; would need to recreate the object on basically each keystroke
|
||||
;; and I don't like the perspective of it, would also flicker
|
||||
;; for sure - so we keep the one overlay and we clear the contents.
|
||||
(corfu--set-overlay-property 'after-string "")))
|
||||
(corfu-candidate-overlay--set-overlay-property 'after-string "")))
|
||||
|
||||
(defun corfu-show-candidate-overlay ()
|
||||
(defun corfu-candidate-overlay--show ()
|
||||
"Computes completion candidates just like Corfu and updats the candidate
|
||||
overlay to reflect the first one. Uses different face when there is only
|
||||
one candidate available (defaults to underline)."
|
||||
|
@ -135,7 +135,7 @@
|
|||
(run-hook-wrapped 'completion-at-point-functions #'corfu--capf-wrapper))))
|
||||
|
||||
(if (not value)
|
||||
(corfu-hide-candidate-overlay) ;; when empty, we hide the overlay.
|
||||
(corfu-candidate-overlay--hide) ;; when empty, we hide the overlay.
|
||||
(pcase value ;; when not, we check the completion data.
|
||||
(`(,fun ,beg ,end ,table . ,plist)
|
||||
(let ((completion-in-region-mode-predicate
|
||||
|
@ -171,17 +171,17 @@
|
|||
;; could see strage results when typing the first character.
|
||||
(string-prefix-p prefix candidate))
|
||||
;; and finally we update the overlay.
|
||||
(corfu--candidate-overlay-update
|
||||
(corfu-candidate-overlay--update
|
||||
end ;; we anchor the overlay to the end position as cursor is there.
|
||||
prefix
|
||||
suffix
|
||||
how-many-candidates)
|
||||
;; hide if the above ``if-condition'' is not met.
|
||||
(corfu-hide-candidate-overlay)))
|
||||
(corfu-candidate-overlay--hide)))
|
||||
;; hide if there is no corfu--candidates at all (equals nil).
|
||||
(corfu-hide-candidate-overlay)))))))))
|
||||
(corfu-candidate-overlay--hide)))))))))
|
||||
|
||||
(defun corfu--candidate-overlay-pre-command ()
|
||||
(defun corfu-candidate-overlay--pre-command ()
|
||||
"Pre command hook to hide the overlay if the command is not insert or delete.
|
||||
Otherwise the overlay can influence movement commands (i.e. the cursor is
|
||||
considered to be located at the end of the overlay, so line movement will
|
||||
|
@ -192,7 +192,7 @@
|
|||
(let* ((is-insert-command
|
||||
(corfu--match-symbol-p corfu-auto-commands this-command))
|
||||
(is-delete-command
|
||||
(corfu--match-symbol-p corfu-overlay-auto-commands this-command)))
|
||||
(corfu--match-symbol-p corfu-candidate-overlay-auto-commands this-command)))
|
||||
;; first we check the short-circuit conditions
|
||||
;; to exit as early as possible, so when we know the overlay
|
||||
;; would not be present -- we don't check anything else.
|
||||
|
@ -218,9 +218,9 @@
|
|||
(not (or
|
||||
is-insert-command
|
||||
is-delete-command))))
|
||||
(corfu-hide-candidate-overlay)))))
|
||||
(corfu-candidate-overlay--hide)))))
|
||||
|
||||
(defun corfu--candidate-overlay-post-command ()
|
||||
(defun corfu-candidate-overlay--post-command ()
|
||||
"Post command hook updating the candidate overlay when user inserts character
|
||||
and the cursor is at the end of word."
|
||||
;; We should not throw an error here, as Emacs will disable
|
||||
|
@ -232,7 +232,7 @@
|
|||
(let* ((is-insert-command
|
||||
(corfu--match-symbol-p corfu-auto-commands this-command))
|
||||
(is-delete-command
|
||||
(corfu--match-symbol-p corfu-overlay-auto-commands this-command)))
|
||||
(corfu--match-symbol-p corfu-candidate-overlay-auto-commands this-command)))
|
||||
;; short-circuit conditions -- the earlier we return if don't need to do
|
||||
;; anything the better.
|
||||
(if (and
|
||||
|
@ -242,8 +242,8 @@
|
|||
;; corfu menu needs to be hidden
|
||||
(not (and (frame-live-p corfu--frame) (frame-visible-p corfu--frame)))
|
||||
(not (and ;; do not update if the point have not moved.
|
||||
corfu--candidate-last-point
|
||||
(= corfu--candidate-last-point (point))))
|
||||
corfu-candidate-overlay--last-point
|
||||
(= corfu-candidate-overlay--last-point (point))))
|
||||
(or ;; do not update if it is not one of the insert or delete commands.
|
||||
is-insert-command
|
||||
is-delete-command))
|
||||
|
@ -263,15 +263,15 @@
|
|||
;; then the overlay will often not update and will interfere with the typing.
|
||||
;; That's why we operate on stored prefix and candidate giving an illusion
|
||||
;; of updating the overlay -- but using the previous auto suggestion candidate.
|
||||
(when corfu--candidate-overlay ;; need overlay active
|
||||
(when corfu-candidate-overlay--overlay ;; need overlay active
|
||||
(let* ((candidate
|
||||
(corfu--get-overlay-property 'corfu-candidate))
|
||||
(corfu-candidate-overlay--get-overlay-property 'corfu-candidate))
|
||||
(prefix
|
||||
(corfu--get-overlay-property 'corfu-prefix))
|
||||
(corfu-candidate-overlay--get-overlay-property 'corfu-prefix))
|
||||
(count
|
||||
(corfu--get-overlay-property 'corfu-count))
|
||||
(corfu-candidate-overlay--get-overlay-property 'corfu-count))
|
||||
(previous-text
|
||||
(corfu--get-overlay-property 'after-string)))
|
||||
(corfu-candidate-overlay--get-overlay-property 'after-string)))
|
||||
;; We need to deal with the overlay and stored candidate differently
|
||||
;; when inserting and deleting (i.e. we need to shift one characte from or to
|
||||
;; prefix to/from candidate)
|
||||
|
@ -281,7 +281,7 @@
|
|||
(if (length> prefix 0)
|
||||
;; we still have some characters present in the prefix,
|
||||
;; so we'll borrow one and move to the candidate.
|
||||
(corfu--candidate-overlay-update
|
||||
(corfu-candidate-overlay--update
|
||||
(point) ;; move to current cursor's position
|
||||
(substring prefix 0 (- (length prefix) 1 ))
|
||||
(concat (substring prefix (- (length prefix) 1)) candidate)
|
||||
|
@ -289,7 +289,7 @@
|
|||
;; if the length of prefix is zero then we can only hide
|
||||
;; the overlay as we are removing past the current word
|
||||
;; boundary.
|
||||
(corfu-hide-candidate-overlay)))
|
||||
(corfu-candidate-overlay--hide)))
|
||||
;; Inserting character - we still update using historical data
|
||||
;; in case the corfu backend would get interrupted;
|
||||
;; Here we "borrow" a character from the candidate and append it to the prefix.
|
||||
|
@ -297,7 +297,7 @@
|
|||
(if (and
|
||||
(not (string-empty-p previous-text))
|
||||
(length> candidate 1))
|
||||
(corfu--candidate-overlay-update
|
||||
(corfu-candidate-overlay--update
|
||||
(point) ;; move to current cursor's position
|
||||
(concat prefix (substring candidate 0 1))
|
||||
(substring candidate 1 (length candidate))
|
||||
|
@ -305,14 +305,14 @@
|
|||
;; no previous candidate or candidate is zero length,
|
||||
;; probably we have reached the end of suggested word,
|
||||
;; so let's hide the overlay.
|
||||
(corfu-hide-candidate-overlay))))))
|
||||
(corfu-candidate-overlay--hide))))))
|
||||
;; preserve the current position, show and update the overlay.
|
||||
;; the corfu-show-candidate-overlay CAN be interrupted, that's why
|
||||
;; the corfu-candidate-overlay--show CAN be interrupted, that's why
|
||||
;; we did the shuffling above.
|
||||
(setq corfu--candidate-last-point (point))
|
||||
(corfu-show-candidate-overlay)))
|
||||
(setq corfu-candidate-overlay--last-point (point))
|
||||
(corfu-candidate-overlay--show)))
|
||||
;; or hide the overlay if the conditions to show the overlay where not met.
|
||||
(corfu-hide-candidate-overlay)))))
|
||||
(corfu-candidate-overlay--hide)))))
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode corfu-candidate-overlay-mode
|
||||
|
@ -322,14 +322,14 @@
|
|||
(if corfu-candidate-overlay-mode
|
||||
(cond
|
||||
((not corfu-auto)
|
||||
(add-hook 'post-command-hook #'corfu--candidate-overlay-post-command)
|
||||
(add-hook 'pre-command-hook #'corfu--candidate-overlay-pre-command)
|
||||
(add-hook 'post-command-hook #'corfu-candidate-overlay--post-command)
|
||||
(add-hook 'pre-command-hook #'corfu-candidate-overlay--pre-command)
|
||||
(message "Enabled `corfu-candidate-overlay-mode'."))
|
||||
(t
|
||||
(message "`corfu-auto' enabled, `corfu-candidate-overlay-mode' requires `corfu-auto' to be set to `nil'.")))
|
||||
(progn
|
||||
(remove-hook 'post-command-hook #'corfu--candidate-overlay-post-command)
|
||||
(remove-hook 'pre-command-hook #'corfu--candidate-overlay-pre-command)
|
||||
(remove-hook 'post-command-hook #'corfu-candidate-overlay--post-command)
|
||||
(remove-hook 'pre-command-hook #'corfu-candidate-overlay--pre-command)
|
||||
(message "Disabled `corfu-candidate-overlay-mode'."))))
|
||||
|
||||
;;; corfu-candidate-overlay.el ends here
|
||||
|
|
Loading…
Reference in a new issue