From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>
Received: from mp0.migadu.com ([2001:41d0:403:4876::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by ms1.migadu.com with LMTPS
	id CEmwF3RiUGZ2LwAAqHPOHw:P1
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Fri, 24 May 2024 11:48:36 +0200
Received: from aspmx1.migadu.com ([2001:41d0:403:4876::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by mp0.migadu.com with LMTPS
	id CEmwF3RiUGZ2LwAAqHPOHw
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Fri, 24 May 2024 11:48:36 +0200
X-Envelope-To: larch@yhetil.org
Authentication-Results: aspmx1.migadu.com;
	dkim=pass header.d=posteo.net header.s=2017 header.b=dUEl6fBQ;
	spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org";
	dmarc=pass (policy=none) header.from=posteo.net
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org;
	s=key1; t=1716544116;
	h=from:from:sender:sender:reply-to:subject:subject:date:date:
	 message-id:message-id:to:to:cc:cc:mime-version:mime-version:
	 content-type:content-type:in-reply-to:in-reply-to:
	 references:references:list-id:list-help:list-unsubscribe:
	 list-subscribe:list-post:dkim-signature;
	bh=z2JoXHCkT/hgHd5yT9R2QLl4prqWtXIvV4aqKl5iXrk=;
	b=EZ9Iy05S1CHYyga7jULfLER2+NEmNIjbvslS9qPWwHHWXm+eosfjz8dfkrofw0XyGOB2YB
	7ydtFWUIDaJSw3Gv/Lh6tsgBib6grG9IV9C+1rd5XdFmm791tDoiuDB1Lt452Q06de1Jfo
	6gv5Af5GhP0mpSPZ5nswRpDjU9uoUTP4jGZo00bPwaf39UuCLTUmEYSy2zdrQ2/jvnuv4A
	8gahtCBVDY6jhQt7SRtmQQw6ssnN1JRPbLibteZY5bddpBRxCmUVkUGHVIOMgOmysnYrBn
	+82Hdr7Iexzt6uOixIG2MupJQ29bBr+LjzULkQ39R8KSYyMo3tPAcPDjQVs0aA==
ARC-Authentication-Results: i=1;
	aspmx1.migadu.com;
	dkim=pass header.d=posteo.net header.s=2017 header.b=dUEl6fBQ;
	spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org";
	dmarc=pass (policy=none) header.from=posteo.net
ARC-Seal: i=1; s=key1; d=yhetil.org; t=1716544116; a=rsa-sha256; cv=none;
	b=qCzm+vJAQlRP/oNaFdK+VH5yhDdaxrCy3Z57YbO6ro1HMbfqarnD9XSwXOpJ09YQagq9nM
	dM+NGrhMKZgEBV7HeH49NKx2KI36GG6ICXFH0iA9wze2Tg0FxidUFoX2FjlFk5xDr9+b98
	p6GZsV02XO0BS3XkIaXSEC+d+RQK8gUg1wU6EdPb3IjKruTc4FhnuOr9BdsCSYqW2AboBu
	sX3L9O6kFBgJKVOlZrQaPoPGvqzxwm4BxYyrypulM9SAUcF+PJL1BTX9haV+o1HeTq3SvH
	9gJMWnH4ZXJGoSLi9G/idL4izjlyTkd1FKX+lLoQuAW3iJJlYM3GPuUcx60j3A==
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by aspmx1.migadu.com (Postfix) with ESMTPS id DD57122599
	for <larch@yhetil.org>; Fri, 24 May 2024 11:48:35 +0200 (CEST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-orgmode-bounces@gnu.org>)
	id 1sARWY-0004oj-Dz; Fri, 24 May 2024 05:47:42 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@posteo.net>)
 id 1sARWX-0004kd-At
 for emacs-orgmode@gnu.org; Fri, 24 May 2024 05:47:41 -0400
Received: from mout01.posteo.de ([185.67.36.65])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@posteo.net>)
 id 1sARWT-0002t6-79
 for emacs-orgmode@gnu.org; Fri, 24 May 2024 05:47:39 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout01.posteo.de (Postfix) with ESMTPS id B9CF524002D
 for <emacs-orgmode@gnu.org>; Fri, 24 May 2024 11:47:34 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1716544054; bh=zofE9fD/YwpqZ/yvuQnhSEGV2LukppWBH28maJ4lBR0=;
 h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type:
 From;
 b=dUEl6fBQYIQiCm6dR2BIAzITNMOFbTPexx5OmCs/ynajotPfnvskYHdtGl66OmvhF
 LNoL60CE6iMAPuqg1o6k8AfrZSaOZH8Nk+gnMi9on8dbHaBRkLFB+ZjlD6eyu+299H
 mNQlSaSgFh39ZhFjVb2pqxvypUFznax1cEYjVdRVk6v69gZFMoVspws/r1VBA7ksyw
 qNsVg4J4XrITC/J8ZlbiLq8yxWywfQRZn+vePlBShYeCwPq84imHwbYPlJPukcctcz
 Y176ybjXnrEztm7yTGZL9UhDoNC/eZXKOXOaafXCfO8dQO7jJHVkEnxetkM3DBIeR1
 yRaLKeRGoGzAQ==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4Vm0ZY6szVz6v1H;
 Fri, 24 May 2024 11:47:33 +0200 (CEST)
From: Ihor Radchenko <yantar92@posteo.net>
To: Bruno Barbier <brubar.cs@gmail.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>, Jack Kamm <jackkamm@gmail.com>,
 Matt <matt@excalamus.com>
Subject: Re: Pending contents in org documents (Re: Asynchronous blocks for
 everything (was Re: ...))
In-Reply-To: <664f6f54.050a0220.10342.b002@mx.google.com>
References: <87o7d0mm54.fsf@localhost>
 <18dbe11968a.12c0800a31425096.5114791462107560324@excalamus.com>
 <65df0895.df0a0220.a68c8.0966@mx.google.com> <87edct0x2w.fsf@localhost>
 <65e30609.050a0220.89c06.1798@mx.google.com> <87a5ng7uoq.fsf@localhost>
 <65e9f49b.df0a0220.11103.1c10@mx.google.com> <87ttlhki9e.fsf@localhost>
 <65eb1e60.050a0220.337b2.a0f4@mx.google.com> <87frwuxy1b.fsf@localhost>
 <65f95bf2.050a0220.6d051.c8b1@mx.google.com> <87plvpjj76.fsf@localhost>
 <65fc06c1.5d0a0220.0d53.efdc@mx.google.com> <87frwjlr1a.fsf@localhost>
 <6601b872.050a0220.31a67.5a55@mx.google.com> <87le63c3qy.fsf@localhost>
 <660ed63d.050a0220.36fdd.af23@mx.google.com> <87cyqwyvgw.fsf@localhost>
 <66225435.5d0a0220.f60e4.c590@mx.google.com> <87r0f02vq2.fsf@localhost>
 <664f6f54.050a0220.10342.b002@mx.google.com>
Date: Fri, 24 May 2024 09:49:19 +0000
Message-ID: <87o78vwnds.fsf@localhost>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net;
 helo=mout01.posteo.de
X-Spam_score_int: -43
X-Spam_score: -4.4
X-Spam_bar: ----
X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-orgmode@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=subscribe>
Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
X-Migadu-Country: US
X-Migadu-Flow: FLOW_IN
X-Spam-Score: -8.07
X-Migadu-Queue-Id: DD57122599
X-Migadu-Scanner: mx10.migadu.com
X-Migadu-Spam-Score: -8.07
X-TUID: TnLMqqwSLLtX

--=-=-=
Content-Type: text/plain

Bruno Barbier <brubar.cs@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?


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=org-pending.diff

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:
 

--=-=-=
Content-Type: text/plain


-- 
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>

--=-=-=--