[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 36b8bc7065 2/2: consult--with-preview-1: Extrac
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 36b8bc7065 2/2: consult--with-preview-1: Extract consult--append-local-post-command-hook |
Date: |
Thu, 7 Apr 2022 20:57:22 -0400 (EDT) |
branch: externals/consult
commit 36b8bc7065005778db83f12a594b6929bfd3319c
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
consult--with-preview-1: Extract consult--append-local-post-command-hook
---
consult.el | 43 ++++++++++++++++++++-----------------------
1 file changed, 20 insertions(+), 23 deletions(-)
diff --git a/consult.el b/consult.el
index 3d9bc8d3ea..cb7bc84b39 100644
--- a/consult.el
+++ b/consult.el
@@ -1361,13 +1361,25 @@ FACE is the cursor face."
(funcall fun action cand)
(t (message "consult--read: No preview, the :state function protocol
changed: %S" err))))
+(defun consult--append-local-post-command-hook (fun)
+ "Append FUN to local `post-command-hook' list."
+ ;; Symbol indirection because of bug#46407.
+ (let ((hook (make-symbol "consult--preview-post-command")))
+ (fset hook fun)
+ ;; TODO Emacs 28 has a bug, where the hook--depth-alist is not cleaned up
properly
+ ;; Do not use the broken add-hook here.
+ ;;(add-hook 'post-command-hook sym 'append 'local)
+ (setq-local post-command-hook
+ (append
+ (remove t post-command-hook)
+ (list hook)
+ (and (memq t post-command-hook) '(t))))))
+
(defun consult--with-preview-1 (preview-key state transform candidate fun)
"Add preview support for FUN.
See `consult--with-preview' for the arguments
PREVIEW-KEY, STATE, TRANSFORM and CANDIDATE."
(let ((input "") selected timer last-preview
- ;; symbol indirection because of bug#46407
- (post-command-sym (make-symbol "consult--preview-post-command"))
(minibuffer-exit-sym (make-symbol "consult--preview-minibuffer-exit")))
(consult--minibuffer-with-setup-hook
(if (and state preview-key)
@@ -1415,28 +1427,13 @@ PREVIEW-KEY, STATE, TRANSFORM and CANDIDATE."
;; STEP 4: Notify the preview function of the
minibuffer exit
(consult--protected-state-call state 'exit nil))))
(add-hook 'minibuffer-exit-hook minibuffer-exit-sym nil 'local)
- (fset post-command-sym
- (lambda ()
- (setq input (minibuffer-contents-no-properties))
- (funcall consult--preview-function)))
- ;; TODO Emacs 28 has a bug, where the hook--depth-alist is not
cleaned up properly
- ;; Do not use the broken add-hook here.
- ;;(add-hook 'post-command-hook post-command-sym 'append 'local)
- (setq-local post-command-hook
- (append
- (remove t post-command-hook)
- (list post-command-sym)
- (and (memq t post-command-hook) '(t)))))
+ (consult--append-local-post-command-hook
+ (lambda ()
+ (setq input (minibuffer-contents-no-properties))
+ (funcall consult--preview-function))))
(lambda ()
- (fset post-command-sym (lambda () (setq input
(minibuffer-contents-no-properties))))
- ;; TODO Emacs 28 has a bug, where the hook--depth-alist is not
cleaned up properly
- ;; Do not use the broken add-hook here.
- ;;(add-hook 'post-command-hook post-command-sym 'append 'local)
- (setq-local post-command-hook
- (append
- (remove t post-command-hook)
- (list post-command-sym)
- (and (memq t post-command-hook) '(t))))))
+ (consult--append-local-post-command-hook
+ (lambda () (setq input (minibuffer-contents-no-properties))))))
(unwind-protect
(cons (setq selected (when-let (result (funcall fun))
(funcall transform input result)))