Make package-lint happy

Also bumping version to 1.2
This commit is contained in:
Adam Kruszewski 2023-06-26 11:22:40 +02:00
parent ef8c36c6d8
commit 88e4fce36c

View file

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