Skip to content

Commit

Permalink
Use corfu--initial-state instead of corfu--state-vars. (#159)
Browse files Browse the repository at this point in the history
- If `corfu--state-vars` is not bound, use the new
  `corfu--initial-state` instead.
- Bump the required Corfu version from 0.28 to 1.1.  Once the next
  stable version is released, we can bump it again and remove
  references to the old variable.
- Update the changelog.

See:
- Corfu commit 63d1de2696adcb09a4ea01ba668635364e37a9c2
  (minad/corfu@63d1de2)
- This PR #159.
- Prescient issue #158, reporting this change.
  • Loading branch information
zonuexe authored Jan 6, 2024
1 parent 864b352 commit 4b875be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ The format is based on [Keep a Changelog].
* Change how candidates are remembered for Vertico to work with
`vertico-directory-enter` and to remember the minibuffer contents
when exiting the minibuffer.
* Use `corfu--initial-state` if `corfu--state-vars` is not bound
([#158], [#159]).

[#152]: https://github.com/radian-software/prescient.el/issues/152
[#153]: https://github.com/radian-software/prescient.el/pull/153
[#156]: https://github.com/radian-software/prescient.el/pull/156
[#158]: https://github.com/radian-software/prescient.el/pull/158
[#159]: https://github.com/radian-software/prescient.el/pull/159


## 6.2 (released 2023-11-23)
### Features
Expand Down
29 changes: 22 additions & 7 deletions corfu-prescient.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Homepage: https://github.com/radian-software/prescient.el
;; Keywords: extensions
;; Created: 23 Sep 2022
;; Package-Requires: ((emacs "27.1") (prescient "6.1.0") (corfu "0.28"))
;; Package-Requires: ((emacs "27.1") (prescient "6.1.0") (corfu "1.1"))
;; SPDX-License-Identifier: MIT
;; Version: 6.2.0

Expand All @@ -28,6 +28,11 @@
(require 'prescient)
(require 'subr-x)

;; Remove references to `corfu--state-vars' once the next stable
;; version of Corfu is released:
(defvar corfu--state-vars)
(defvar corfu--initial-state)

;;;; Customization

(defgroup corfu-prescient nil
Expand Down Expand Up @@ -193,8 +198,13 @@ This mode will:
;; after the Corfu pop-up closes. For the toggling vars, it
;; is the commands themselves that make the variables buffer
;; local.
(cl-callf cl-union corfu--state-vars prescient--toggle-vars
:test #'eq))
(if (boundp 'corfu--state-vars)
(cl-callf cl-union corfu--state-vars prescient--toggle-vars
:test #'eq)
(cl-callf cl-union corfu--initial-state
(mapcar (lambda (k) (cons k (symbol-value k)))
prescient--toggle-vars)
:test #'eq :key #'car)))

;; While sorting might not be enabled in Corfu, it might
;; still be enabled in another UI, such as Selectrum or Vertico.
Expand All @@ -214,12 +224,17 @@ This mode will:
(when (equal (lookup-key corfu-map (kbd "M-s"))
prescient-toggle-map)
(define-key corfu-map (kbd "M-s")
corfu-prescient--old-toggle-binding))
corfu-prescient--old-toggle-binding))
(remove-hook 'prescient--toggle-refresh-functions
#'corfu-prescient--toggle-refresh)
(cl-callf cl-set-difference corfu--state-vars
prescient--toggle-vars
:test #'eq)
(if (boundp 'corfu--state-vars)
(cl-callf cl-set-difference corfu--state-vars
prescient--toggle-vars
:test #'eq)
(cl-callf cl-set-difference corfu--initial-state
(mapcar (lambda (k) (cons k (symbol-value k)))
prescient--toggle-vars)
:test #'eq :key #'car))

;; Undo filtering settings.
(remove-hook 'corfu-mode-hook
Expand Down
2 changes: 2 additions & 0 deletions stub/corfu.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

(defvar corfu--candidates nil)
(defvar corfu--index nil)
(defvar corfu--initial-state nil)
(defvar corfu--input nil)
;; Removed https://github.com/minad/corfu/commit/63d1de2696adcb09a4ea01ba668635364e37a9c2
(defvar corfu--state-vars nil)
(defvar corfu-map nil)
(defvar corfu-mode nil)
Expand Down

0 comments on commit 4b875be

Please sign in to comment.