branch: elpa/dirvish commit b8a6ceb8971a57207dbd0104e8835e0a59c9e512 Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
refactor: use plist for timer management --- dirvish.el | 12 +++++++----- extensions/dirvish-narrow.el | 7 ++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dirvish.el b/dirvish.el index e47b35822c..9bd713e404 100644 --- a/dirvish.el +++ b/dirvish.el @@ -333,8 +333,7 @@ opening and customized handling of specific file types." (dirvish-collapse collapse) (dirvish-subtree subtree-state) (dirvish-yank yank))) -(defvar dirvish--delay-timer `(,(timer-create) ,(float-time) nil)) -(defvar dirvish--reset-keywords '(:free-space :content-begin)) +(defvar dirvish--timers `(:default (,(timer-create) ,(float-time) nil))) (defvar dirvish--selected-window nil) (defvar dirvish--sessions (make-hash-table :test #'equal)) (defvar dirvish--available-attrs '()) @@ -358,9 +357,12 @@ Set the PROP with BODY if given." "Run function FUN accroding to ACTION with delay. DEBOUNCE defaults to `dirvish-input-debounce'. THROTTLE defaults to `dirvish-input-throttle'. -RECORD defaults to `dirvish--delay-timer'." +RECORD defaults to `:default' record in `dirvish--timers'." (declare (indent defun)) - (setq record (or record dirvish--delay-timer) fun (or fun #'ignore) + (unless (plist-get dirvish--timers (setq record (or record :default))) + (cl-callf append dirvish--timers + `(,record (,(timer-create) ,(float-time) nil)))) + (setq record (plist-get dirvish--timers record) fun (or fun #'ignore) debounce (or debounce dirvish-input-debounce) throttle (or throttle dirvish-input-throttle)) (pcase action @@ -1281,7 +1283,7 @@ Dirvish sets `revert-buffer-function' to this function." (let ((dv (dirvish-curr))) (dirvish--check-dependencies dv) ; update dirvish setups (dirvish-prop :attrs (dv-attributes dv))) - (dolist (keyword dirvish--reset-keywords) (dirvish-prop keyword nil)) + (dolist (keyword '(:free-space :content-begin)) (dirvish-prop keyword nil)) (dired-revert) (dirvish--hide-dired-header) (when ignore-auto ; meaning it is called interactively from user diff --git a/extensions/dirvish-narrow.el b/extensions/dirvish-narrow.el index b45ae1ee60..e0a438d3b6 100644 --- a/extensions/dirvish-narrow.el +++ b/extensions/dirvish-narrow.el @@ -85,9 +85,6 @@ "Compile `completion-regexp-list' from string S." (if (fboundp 'orderless-compile) (cdr (orderless-compile s)) (split-string s))) -;; use a separate timer here, otherwise it would be overrided by the default one -(defvar dirvish-narrow--delay-timer `(,(timer-create) ,(float-time) nil)) - (defun dirvish-narrow-update-h () "Update the Dirvish buffer based on the input of the minibuffer." (let* ((mc (minibuffer-contents-no-properties)) @@ -107,7 +104,7 @@ igc (cl-loop for re in (ensure-list rel) always (isearch-no-upper-case-p re t))) (dirvish-prop :narrow-info (list async rel igc))) - (dirvish--run-with-delay mc dirvish-narrow--delay-timer + (dirvish--run-with-delay mc :narrow (lambda (action) (with-current-buffer (cdr (dv-index (dirvish-curr))) (when (dirvish-prop :fd-info) (dirvish-fd--start-proc)) @@ -172,7 +169,7 @@ (directory-file-name default-directory)))) (rename-buffer (concat key "🔍" query "🔍" (dv-id (dirvish-curr))))) (dirvish--run-with-delay 'reset) - (dirvish--run-with-delay 'reset dirvish-narrow--delay-timer))))) + (dirvish--run-with-delay 'reset :narrow))))) (provide 'dirvish-narrow) ;;; dirvish-narrow.el ends here