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 --- README.org | 23 ++++++++++++----------- local/bibli-paris/bibli-paris.el | 33 +++++++++++++++++++++++---------- packages.el | 4 +++- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.org b/README.org index aa13f69..20d7e93 100644 --- a/README.org +++ b/README.org @@ -25,17 +25,18 @@ to =Export.csv=. The following commands are available. -| Command | Shortcut | Description | -|---------------------------------+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| =bibli-paris/mode= | =SPC mb= | Enable the shortcuts described in this table. | -| =bibli-paris/import-from-csv= | =SPC mi= | Import entries from the CSV file downloaded on https://bibliotheques.paris.fr/. The first argument is the path to the CSV file, and the second and third (optional) arguments are the tags and state to set the imported entries to. | -| =bibli-paris/sort= | =SPC ms= | Sort the entries by their quotes. | -| =bibli-paris/update-entry= | =SPC mu= | Asynchronously update the availability status and quote of the entry at point. | -| =bibli-paris/update-entries= | =SPC mU= | Asynchronously update all the availabity status and quotes of all entries in parallel. | -| =bibli-paris/archive-all-read= | =SPC mA= | Archive all entries in the =DONE= state. | -| =bibli-paris/number-of-entries= | =SPC m?= | Display the number of entries in the current buffer. | -| =bibli-paris/previous-entry= | =SPC mk= | Move the cursor to and put forward the previous entry. | -| =bibli-paris/next-entry= | =SPC mj= | Move the cursor to and put forward the next entry. | +| Command | Shortcut | Description | +|---------------------------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| =bibli-paris/mode= | =SPC mb= | Enable the shortcuts described in this table. | +| =bibli-paris/import-from-csv= | =SPC mi= | Import entries from the CSV file downloaded on https://bibliotheques.paris.fr/. The first argument is the path to the CSV file, and the second and third (optional) arguments are the tags and state to set the imported entries to. | +| =bibli-paris/sort= | =SPC ms= | Sort the entries by their quotes. | +| =bibli-paris/update-entry= | =SPC mu= | Asynchronously update the availability status and quote of the entry at point. | +| =bibli-paris/update-region= | =SPC mur= | Asynchronously update the availability status and quotes of the entries in the current region. | +| =bibli-paris/update-buffer= | =SPC mub= | Asynchronously update the availability status and quotes of the entries in the current buffer. | +| =bibli-paris/archive-all-read= | =SPC mA= | Archive all entries in the =DONE= state. | +| =bibli-paris/number-of-entries= | =SPC m?= | Display the number of entries in the current buffer. | +| =bibli-paris/previous-entry= | =SPC mk= | Move the cursor to and put forward the previous entry. | +| =bibli-paris/next-entry= | =SPC mj= | Move the cursor to and put forward the next entry. | * Customization 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 diff --git a/packages.el b/packages.el index 1262aac..24968ca 100644 --- a/packages.el +++ b/packages.el @@ -12,7 +12,9 @@ (spacemacs/set-leader-keys-for-minor-mode 'bibli-paris/mode "m?" 'bibli-paris/number-of-entries "ms" 'bibli-paris/sort - "mu" 'bibli-paris/update-entry + "mue" 'bibli-paris/update-entry + "mur" 'bibli-paris/update-region + "mub" 'bibli-paris/update-buffer "mU" 'bibli-paris/update-entries "mA" 'bibli-paris/archive-all-read "mi" 'bibli-paris/import-from-csv -- cgit v1.2.3