Bruno Barbier <brubar...@gmail.com> writes: > I've pushed the update to my public branch.
Thanks! I am attaching some minor edits I'd like to propose on top of your latest branch. Also, some more questions. > ;; (setq my-rlock > ;; (org-pending (cons (point) (mark)) > ;; (lambda (outcome) > ;; (pcase outcome > ;; (`(:success ,result) (goto-char END) (insert > result)) > ;; (`(:failure ,err) (message "Failed: %s" > err)))))) 1. It is more natural in Elisp to pass regions as two parameters: BEG and END, not a cons cell. 2. Note that (point) may be _after_ (mark). AFAIU, you code assumes that point is always before the mark. You may want to address this. 3. ON-OUTCOME is optional. What happens if none is provided? 4. In the `org-pending' docstring you say "ON-OUTCOME is non-nil, call it with the reglock and the outcome", but the example shows a lambda accepting a single argument. Something is off. I'm afraid that this example will not work if copy-pasted. > ;; (org-pending-send-update my-rlock (list :progress "Not ready > yet.")) > ;; (org-pending-send-update my-rlock (list :progress "Coming soon.")) Should the progress message always be a string? > ;; (org-pending-send-update my-rlock (list :success 1)) What will org-pending do with :success 1? Will it replace region with "1" or will it do something else? > ;; (org-pending-send-update my-rlock (list :failure "Some error!")) I am slightly confused by this calling convention. Why not simply (org-pending-send-update my-rlock :failure "Some error!") > ;; (setf (org-pending-reglock-insert-details-function my-reglock) > ;; (lambda (rl _start _end) > ;; (insert (format "%s" (org-pending-reglock-property rl > :my-prop))))) Are there any standard properties? It would be nice to list them in a table as well. Also, you can show an example of _setting_ :my-prop property. > ;; If the user kills a buffer, or, kills Emacs, some locks may have to > ;; be killed too. The library will ask the user to confirm if an > ;; operation requires to kill some locks. See the field > ;; `before-kill-function' of REGLOCK object, if you need to do > ;; something before a lock is really killed. For example, if you like > ;; to kill a MY-BUFFER before MY-LOCK is killed, you can do: > ;; > ;; (setf (org-pending-reglock-before-kill-function my-reglock) > ;; (lambda (_rl) (kill-buffer my-buffer))) It would be nice to have an example that will also send a signal to process, as it is probably the most commonly used way to utilize org-pending. >From `org-pending' docstring: > If ON-OUTCOME returns > a region (a pair (start position . end position)), use it to report the > success/failure using visual hints on that region. If ON-OUTCOME > returns nothing, don't display outcome marks. What if ON-OUTCOME returns something that is not a cons cell and not nil?
diff --git a/lisp/org-pending.el b/lisp/org-pending.el index 2530a95b3..973b5e17b 100644 --- a/lisp/org-pending.el +++ b/lisp/org-pending.el @@ -26,11 +26,18 @@ ;;; Commentary: ;;;; Overview ;; ;; -;; This library contains an API to lock a region while it is "being +;; This library provides an API to lock a region while it is "being ;; updated"; the content of the region is "pending" and cannot be ;; modified. It will be updated, later, when the new content is ;; available. ;; +;; While region is "pending", the library will mark it for the user, +;; displaying the current update progress. +;; +;; The update may yield success or failure. On success, the region +;; content will be updated, and the update summary will be indicated. +;; On failure, the error log will be displayed. +;; ;; Locking regions is useful when the update is computed ;; asynchronously and/or depends on external events. ;; @@ -38,7 +45,7 @@ ;;;; Overview ;;;; How to use locks in your library ;; -;; To lock a region, you need to do something like this: +;; To lock a region, you need to: ;; ;; 1. Call the function `org-pending' with the region to lock; use ;; the ON-OUTCOME argument to tell Emacs how to update the @@ -47,18 +54,19 @@ ;;;; How to use locks in your library ;; ;; 2. Start "something" that computes the new content. That ;; "something" may be a thread, a timer, a notification, a -;; process, etc. That "something" must eventually send a -;; :success or :failure message (using -;; `org-pending-send-update'): Emacs will update the pending -;; region (using your ON-OUTCOME) and unlock it; at this point -;; the lock is "dead" (see `org-pending-reglock-live-p'). +;; process, etc. That "something" might optionally report +;; :progress, and must eventually send a :success or :failure +;; message (using `org-pending-send-update'): org-pending will +;; update the pending region (using your ON-OUTCOME) and unlock +;; it; at this point the lock is "dead" (see +;; `org-pending-reglock-live-p'). ;; ;; A lock is "live" (blocking its region) from when it's created until -;; it receives its outcome (success or failure). Once the lock +;; it receives its outcome (:success or :failure). Once the lock ;; receives its outcome, it's dead. ;; ;; You may read the current status using `org-pending-reglock-status'. -;; The status is automatically updated when you send updates using +;; The status is updated when you send updates using ;; `org-pending-send-update'. ;; ;; | Status | Type | Region | Live ? | Possible updates | Outcome available | Outcome marks | @@ -99,23 +107,23 @@ ;;;; Interface provided to the Emacs user ;; and/or overlays. It diplays and updates the status while the ;; region is locked: the initial status is :scheduled, then, when ;; receiving progress it becomes :pending (with progress information -;; if any). Emacs allows to diplay a description of the lock in a new -;; buffer, like, for example, `describe-package'. From that +;; if any). org-pending allows to diplay a description of the lock in +;; a new buffer, like, for example, `describe-package'. From that ;; description buffer, the user may request to cancel that lock; see ;; the field `user-cancel-function' of the REGLOCK object if you need -;; to customize what to do on cancel. By default, Emacs will just -;; send the update (list :failure 'org-pending-user-cancel) so that -;; the region is unlocked. +;; to customize what to do on cancel. By default, org-pending will +;; just send the update (list :failure 'org-pending-user-cancel) so +;; that the region is unlocked. ;; -;; When receiving the outcome (success or failure), after unlocking +;; When receiving the outcome (:success or :failure), after unlocking ;; the region, the library may leave information about the outcome ;; (using text properties/overlays); it will leave an outcome mark ;; only if the ON-OUTCOME function returns the outcome region (see -;; `org-pending`). If that outcome information is (still) displayed, +;; `org-pending'). If that outcome information is (still) displayed, ;; Emacs allows to display a description of that lock. From that ;; description, the user may decide to "forget" that lock; "forgetting -;; the lock" removes the outcome visual marks, and, it allows Emacs to -;; discard any information related to this lock. +;; the lock" removes the outcome visual marks, and, it allows +;; org-pending to discard any information related to this lock. ;; Note that the visual marks of an outcome are silently removed if ;; the library needs to (like when creating a new lock, or when @@ -172,7 +180,7 @@ ;;;; Content of this file ;; and block the user. The section "Dev & debug" contains tools that ;; are useful only for development and debugging. ;; -;; This file does *NOT* depend on Org. +;; This file does *NOT* depend on Org mode. ;;; Code:
-- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>