emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
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: ...))
Date: Fri, 24 May 2024 09:49:19 +0000	[thread overview]
Message-ID: <87o78vwnds.fsf@localhost> (raw)
In-Reply-To: <664f6f54.050a0220.10342.b002@mx.google.com>

[-- Attachment #1: Type: text/plain, Size: 3053 bytes --]

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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-pending.diff --]
[-- Type: text/x-patch, Size: 5019 bytes --]

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:
 

[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


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

  reply	other threads:[~2024-05-24  9:48 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 11:58 [BUG] Unexpected result when evaluating python src block asynchronously [9.7-pre (release_9.6.17-1131-gc9ed03.dirty @ /home/yantar92/.emacs.d/straight/build/org/)] Ihor Radchenko
2024-02-01 14:56 ` Bruno Barbier
2024-02-03  1:30   ` Jack Kamm
2024-02-04 15:07     ` Ihor Radchenko
2024-02-05  1:37       ` Jack Kamm
2024-02-05 14:29         ` Ihor Radchenko
2024-02-06 19:24           ` Bruno Barbier
2024-02-07 16:19             ` Ihor Radchenko
2024-02-07 17:40               ` Bruno Barbier
2024-02-08  3:21             ` Jack Kamm
2024-02-15 20:02             ` Asynchronous blocks for everything (was Re: [BUG] Unexpected result when evaluating python src block asynchronously [9.7-pre (release_9.6.17-1131-gc9ed03.dirty @ /home/yantar92/.emacs.d/straight/build/org/)]) Matt
2024-02-16 17:52               ` Bruno Barbier
2024-02-18 21:14                 ` Matt
2024-02-19  0:31                   ` Jack Kamm
2024-02-20 10:28                   ` Ihor Radchenko
2024-02-20 10:46                     ` tomas
2024-02-20 11:00                       ` Ihor Radchenko
2024-02-20 11:03                         ` tomas
2024-02-21 15:27                   ` Bruno Barbier
     [not found]                   ` <notmuch-sha1-61e086e33bd1faf1a123c1b0353cf2102c71bdac>
2024-02-28 10:18                     ` Pending contents in org documents (Re: Asynchronous blocks for everything (was Re: ...)) Bruno Barbier
2024-03-02 10:03                       ` Ihor Radchenko
2024-03-02 10:57                         ` Bruno Barbier
2024-03-02 11:13                           ` Ihor Radchenko
2024-03-02 18:06                             ` Bruno Barbier
     [not found]                             ` <notmuch-sha1-d2799a191385bf51811d7788856a83b4f5a1fe3b>
2024-03-07 17:08                               ` Bruno Barbier
2024-03-07 18:29                                 ` Ihor Radchenko
2024-03-08 14:19                                   ` Bruno Barbier
2024-03-13  9:48                                     ` Ihor Radchenko
2024-03-19  9:33                                       ` Bruno Barbier
2024-03-20 10:23                                         ` Ihor Radchenko
2024-03-21 10:06                                           ` Bruno Barbier
2024-03-21 12:15                                             ` Ihor Radchenko
2024-03-25 17:46                                               ` Bruno Barbier
2024-03-27 11:29                                                 ` Ihor Radchenko
2024-03-30 22:53                                                   ` Rudolf Adamkovič
2024-04-04 16:35                                                     ` Bruno Barbier
2024-04-04 16:33                                                   ` Bruno Barbier
2024-04-11 11:44                                                     ` Ihor Radchenko
2024-04-19 11:23                                                       ` Bruno Barbier
2024-04-20 10:07                                                         ` Ihor Radchenko
2024-05-12 16:43                                                           ` Bruno Barbier
2024-05-19  9:39                                                             ` Ihor Radchenko
2024-05-23 16:31                                                           ` Bruno Barbier
2024-05-24  9:49                                                             ` Ihor Radchenko [this message]
2024-05-30 19:01                                                               ` Bruno Barbier
2024-05-31  9:48                                                                 ` Ihor Radchenko
2024-06-01  6:28                                                                   ` Pending contents in org documents Bruno Barbier
2024-06-03 11:04                                                                     ` Ihor Radchenko
2024-06-15  7:49                                                                       ` Bruno Barbier
2024-06-16  9:31                                                                         ` Ihor Radchenko
2024-07-07  9:15                                                                           ` Bruno Barbier
2024-07-07 12:13                                                                             ` Ihor Radchenko
2024-07-18  8:05                                                                               ` Bruno Barbier
2024-07-19 14:23                                                                                 ` Ihor Radchenko
2024-07-31  8:47                                                                                   ` Bruno Barbier
2024-08-02 16:48                                                                                     ` Ihor Radchenko
2024-08-12  7:14                                                                                       ` Bruno Barbier
2024-08-13  9:49                                                                                         ` Ihor Radchenko
2024-02-19  0:15                 ` Asynchronous blocks for everything (was Re: [BUG] Unexpected result when evaluating python src block asynchronously [9.7-pre (release_9.6.17-1131-gc9ed03.dirty @ /home/yantar92/.emacs.d/straight/build/org/)]) Jack Kamm
2024-02-21 15:43                   ` Bruno Barbier
2024-02-19  9:06                 ` Ihor Radchenko
2024-02-19 19:47                   ` Matt
2024-02-19 20:10                     ` Ihor Radchenko
2024-02-20  8:32                     ` Ihor Radchenko
2024-02-20 17:04                     ` Jack Kamm
2024-02-21 16:03                   ` Bruno Barbier
2024-02-23 12:11                     ` Ihor Radchenko
2024-02-23 13:24                       ` Bruno Barbier
2024-02-24 11:59                         ` Ihor Radchenko
2024-02-24 16:42                           ` Bruno Barbier
2024-02-24 19:54                             ` Matt
2024-02-28 10:21                               ` Bruno Barbier
2024-02-08  3:26           ` [BUG] Unexpected result when evaluating python src block asynchronously [9.7-pre (release_9.6.17-1131-gc9ed03.dirty @ /home/yantar92/.emacs.d/straight/build/org/)] Jack Kamm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o78vwnds.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=brubar.cs@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jackkamm@gmail.com \
    --cc=matt@excalamus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).