From b5c66e3691d9a49e6d39990914cdc54ead4e4ac1 Mon Sep 17 00:00:00 2001 From: Quentin Aristote Date: Sat, 20 Nov 2021 16:24:19 +0100 Subject: split update-entries into two commands update-region and update-buffer --- local/bibli-paris/bibli-paris.el | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'local') diff --git a/local/bibli-paris/bibli-paris.el b/local/bibli-paris/bibli-paris.el index 2f33e53..6580bba 100644 --- a/local/bibli-paris/bibli-paris.el +++ b/local/bibli-paris/bibli-paris.el @@ -289,24 +289,37 @@ sequentially. Terribly inefficient but works." (deferred:call 'goto-char pom) (deferred:nextc it 'bibli-paris/update-entry)))))) -(defun bibli-paris/update-entries-batch () - "Update all entries' schedules and quotes, by batches so as to prevent -emacs from opening too many files." - (let ((poms (org-map-entries (lambda () - `(,(point) . ,(bibli-paris/get-entry-recnum)))))) +(defun bibli-paris/update-entries-batch (scope) + "Update schedules and quotes, by batches so as to prevent emacs from opening +too many files, for every entry in the SCOPE (see the documentation entry for +org-map-entries)" + (let ((pom-recnum-seq (org-map-entries + (lambda () + ;; (point) is incremented to prevent off-by-one + ;; errors when navigating the buffer + `(,(+ 5 (point)) . ,(bibli-paris/get-entry-recnum))) + nil scope))) + (message "%s" pom-recnum-seq) (deferred:$ (deferred:next (lambda () (message "Update started."))) (deferred:loop - (seq-partition (seq-reverse poms) bibli-paris/max-asynchronous-processes) + (seq-partition (seq-reverse pom-recnum-seq) + bibli-paris/max-asynchronous-processes) 'bibli-paris/async-update-entries-at-points) - (deferred:nextc it 'bibli-paris/sort) + ;; (deferred:nextc it 'bibli-paris/sort) (deferred:nextc it (lambda () (message "Update done.")))))) ;;;###autoload -(defun bibli-paris/update-entries () - "Update all entries' schedules and quotes." +(defun bibli-paris/update-region () + "Update the schedules and quotes of the entries in the current region." (interactive) - (bibli-paris/update-entries-batch)) + (bibli-paris/update-entries-batch 'region)) + +;;;###autoload +(defun bibli-paris/update-buffer () + "Update the schedules and quotes of the entries in the current buffer." + (interactive) + (bibli-paris/update-entries-batch nil)) ;; import entries -- cgit v1.2.3