Bruno Barbier <[email protected]> writes:
> Quick summary for this update:
>
> 1. I've handled all your points, well, I hope so.
> 2. I've merged into a current "main".
> ...
> 4. I added some region helpers to handle regions; regions must now be
> at least 2 characters long.
Thanks!
> As I still don't have started the update of my copyright assignment
> (new employer), I've changed the branch name, just in case:
>
> bba-ngnu-pending-contents
>
> https://framagit.org/brubar/org-mode-mirror/-/commits/bba-ngnu-pending-contents
Noted.
>>> (short-version-of (msg)
>>> "Compute the short version of MSG, to display on the anchor.
>>> Must return a string."
>>> (if msg
>>> (car (split-string (format "%s" msg) "\n" :omit-nulls))
>>> ""))
>>
>> Maybe `truncate-string-to-width'?
>
> I couldn't find the right END-COLUMN to truncate. What really matters
> is that progress messages fit on one line.
Do they have to though?
Take a look at the video in https://github.com/karthink/gptel-agent
That's a similar UI to what we are writing here.
>>> (defun org-pending-locks-in (start end &optional owned)
>>> "Return the list of locks in START..END.
>>
>>> Return the list of REGLOCK(s) that are alive between START and END, in
>>> the current buffer.
>>
>>> When OWNED is non-nil, ignore locks that are not owned by this buffer.
>>
>>> See also `org-pending-locks-in-buffer-p'."
>>> (let ((reglocks)
>>> (here nil)
>>> ovl)
>>> (while (and (< start end)
>>
>> Mind the narrowing.
>
> The function `org-pending-locks-in' takes a region and thus respects
> the current narrowing. The function `org-pending-locks-in-buffer-p'
> ignores the narrowing. Is there something wrong here ?
Just being cautious.
Let's keep it as is.
I also have a few final comments on the org-pending.el
> Note that the display is not always the requested one: Org font-lock
> rules do not comply with `font-lock-face' and may override/delete our
> instructions.")
That's not about Org's font-lock. font-lock-mode manages font-lock-face,
so that setting that face directly is not a valid approach. One needs to
plug into font-lock APIs. E.g. like how it is done by M-x highlight-regexp.
> (cl-flet ((make-read-only (ovl)
> "Make the overly OVL read-only."
> (overlay-put ovl 'modification-hooks read-only)
> (overlay-put ovl 'insert-in-front-hooks read-only)
> (overlay-put ovl 'insert-behind-hooks read-only)))
I am probably missing something from the past discussions, but why not
simply setting 'read-only property?
Also, see a couple of minor edits attached as a diff.
> About the integration with org, I already had 2 existing modes
> "execute" (i.e. synchronous execution) and "schedule"
> (i.e. asynchronous execution); I added a 3rd one called "send"
> (i.e. send and don't care).
I haven't looked into your changes to ob-core.el previously.
Before going there, I think I first need to look through
my-async-tests.org, because the design is not described in the code.
> ** An experimental keyword for org babel: execute-with
> We use an experimental keyword to easily test different execution
> engines with org babel.
>
> With the option ':execute-with ENGINE', org delegates the execution of
> the source code block to the function `ENGINE-execute' (in the
> synchronous case), or to `ENGINE-schedule' (in the asynchronous case).
>
> These functions take the same parameters as `org-babel-execute:LANG'
> and `org-babel-schedule:LANG' except that the language is passed as
> the first argument.
>
> Use "none" to unset the value.
Could you please explain more about the rationale?
Or is it temporary?
> ** Integration with org babel: new keyword ":nasync"
> For asynchronous executions, org now calls `org-babel-schedule:LANG'
> to schedule the execution of the source code blocks (instead of
> `org-babel-execute:LANG').
>
> The function `org-babel-schedule:LANG' must be defined like this:
>
> #+begin_src elisp
> (defun org-babel-schedule:LANG (body params outcome-handler reglock)
> ...
> )
> #+end_src
>
> that is, compared to `org-babel-execute:LANG', it takes two extra
> arguments: a function OUTCOME-HANDLER that must be called once with
> the outcome, and a REGLOCK, that is either nil or a REGLOCK, i.e. the
> lock of the region that waits for the result; when available, it may
> be used to report progress or other information, see the org-pending
> library.
>
> The function `org-babel-schedule:LANG' may schedule the execution
> using any possible technique: processes, threads, timers, etc. It may
> use the REGLOCK to report progress; it must evenutally call
> OUTCOME-HANDLER with the outcome. It must return immediately nothing.
>
> When executing a code block, Org locks the block result, if there is
> one, using `org-pending' to create the lock. Org then calls
> `org-babel-schedule:LANG' with the relevant OUTCOME-HANDLER, and the
> lock (which is `nil' when there is no block result).
What about the :async yes/no that we already use?
Why not using the existing header argument?
> ** Integration with dynamic blocks
>
> The function `org-update-dblock' now handles asynchronous dynamic
> blocks.
>
> If the dynamic block function symbol has a non-nil 'nasync' property,
> org now assumes that this is an asynchronous function and runs it as
> such: it locks the dynamic block region as "pending" and calls the
> function with the REGLOCK as an extra argument. The function must
> return a function that waits for the result and returns it.
What about using a special return value (callback) of the dblock-write
function that will return immediately and flag that we need to wait
further until the execution ends?
> 3. I added an example using the new "futur.el" package.
> 5. I didn't update the example that uses threads (my main Emacs is
> compiled without threading support).
> 6. I didn't update the example that uses the async package.
I did not look into those yet.
diff --git a/lisp/org-pending.el b/lisp/org-pending.el
index 76d5ad18c..d579f836f 100644
--- a/lisp/org-pending.el
+++ b/lisp/org-pending.el
@@ -317,7 +317,6 @@ (defcustom org-pending-anchor-status-scheduled-prefix
(char-displayable-p ?⏱))
"⏱" "S")
"Status prefix for anchors when scheduled."
- :group 'org-pending-anchor-status-scheduled-prefix
:package-version '(Org . "9.7")
:type 'string
:safe #'stringp)
@@ -327,7 +326,6 @@ (defcustom org-pending-anchor-status-pending-prefix
(char-displayable-p ?⏳))
"⏳" "P")
"Status prefix for anchors when pending."
- :group 'org-pending-anchor-status-pending-prefix
:package-version '(Org . "9.7")
:type 'string
:safe #'stringp)
@@ -337,7 +335,6 @@ (defcustom org-pending-anchor-status-failure-prefix
(char-displayable-p ?❌))
"❌" "F")
"Status prefix for anchors when failure."
- :group 'org-pending-anchor-status-failure-prefix
:package-version '(Org . "9.7")
:type 'string
:safe #'stringp)
@@ -347,7 +344,6 @@ (defcustom org-pending-anchor-status-success-prefix
(char-displayable-p ?✔))
"✔" "S")
"Status prefix for anchors when success."
- :group 'org-pending-anchor-status-success-prefix
:package-version '(Org . "9.7")
:type 'string
:safe #'stringp)
@@ -540,7 +536,7 @@ (defun org-pending--replace-region-contents (reg source)
(buffer-substring (elt source 1) (elt source 2)))))
(t
;; Something else: squash it to some text.
- (format "%s" t))))
+ (setq source (format "%s" source)))))
;; Insert in the middle to not mixup front and rear
;; markers, properties, etc..
@@ -1143,8 +1139,7 @@ (defun org-pending-describe-reglock (reglock)
(let* ((ns (% s 60))
(rs (/ s 60))
(nm (% rs 60))
- (nh (/ rs 60))
- (d nil))
+ (nh (/ rs 60)))
(format "%02d:%02d:%02d" nh nm ns))))
(setq-local
header-line-format
@@ -1488,8 +1483,6 @@ (defun org-pending-locks-in-buffer-p (&optional buffer owned-only)
buffer.
See also `org-pending-locks-in'."
- (setq buffer (or (and buffer (get-buffer buffer))
- (current-buffer)))
(with-current-buffer buffer
(save-restriction
(widen)
@@ -1504,7 +1497,7 @@ (defun org-pending-ensure-no-locks (begin end &optional error-info)
(when (org-pending-locks-in begin end)
(signal 'org-pending-error-read-only (cons begin (cons end error-info)))))
-(defun org-pending-no-locks-in-emacs-p ()
+(defun org-pending-has-locks-in-emacs-p ()
"Return non-nil if any buffer contains some pending contents."
(catch 'found-one
(dolist (p (org-pending-list))
@@ -1526,7 +1519,7 @@ ;;;; Internals
(cl-defstruct (org-pending--manager
(:constructor org-pending--create-manager)
(:copier nil))
- ; An name (string) uniquely identifies one REGLOCK.
+ ;; A name (string) uniquely identifies one REGLOCK.
used-names ; obarray of in-use names.
reglocks ; The list of REGLOCKs, past & present.
)
@@ -1566,7 +1559,7 @@ (defun org-pending--mgr-handle-new-reglock (reglock name)
(setf (org-pending-reglock-id reglock) name)
nil))
-(defun org-pending--mgr-handle-reglock-update (reglock update)
+(defun org-pending--mgr-handle-reglock-update (_reglock _update)
"Handle the update UPDATE for this REGLOCK.
Return nothing.")
@@ -1686,7 +1679,7 @@ (defun org-pending--kill-emacs-query ()
"For `kill-emacs-query-functions'.
If there are any lock, offer to abort killing Emacs."
;; TODO: Offer to jump to the list of the locks.
- (if (not (org-pending-no-locks-in-emacs-p))
+ (if (not (org-pending-has-locks-in-emacs-p))
:ok-to-kill
(when (or (not org-pending-confirm-ignore-reglocks-on-exit)
(yes-or-no-p (format "There are pending locks, kill anyway?")))
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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>