Function: org-babel-comint-async--find-src

org-babel-comint-async--find-src is a byte-compiled function defined in ob-comint.el.gz.

Signature

(org-babel-comint-async--find-src UUID-OR-TMPFILE)

Documentation

Find source block associated with an async comint result.

UUID-OR-TMPFILE is the uuid or tmpfile associated with the result. Returns non-nil if the source block is succesfully found, and moves point there.

This function assumes that UUID-OR-TMPFILE was previously inserted as the source block's result, as a placeholder until the true result becomes ready. It may fail to find the source block if the buffer was modified so that UUID-OR-TMPFILE is no longer the result of the source block, or if it has been copied elsewhere into the buffer (this is a limitation of the current async implementation).

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-comint.el.gz
(defun org-babel-comint-async--find-src (uuid-or-tmpfile)
  "Find source block associated with an async comint result.
UUID-OR-TMPFILE is the uuid or tmpfile associated with the result.
Returns non-nil if the source block is succesfully found, and moves
point there.

This function assumes that UUID-OR-TMPFILE was previously inserted as
the source block's result, as a placeholder until the true result
becomes ready.  It may fail to find the source block if the buffer was
modified so that UUID-OR-TMPFILE is no longer the result of the source
block, or if it has been copied elsewhere into the buffer (this is a
limitation of the current async implementation)."
  (goto-char (point-min))
  (when (search-forward uuid-or-tmpfile nil t)
    (let ((uuid-pos (point)))
      (and (re-search-backward
            ;; find the nearest preceding src or inline-src block
            (rx (or (regexp org-babel-src-block-regexp)
                    (regexp org-element-inline-src-block-regexp)))
            nil t)
           ;; check it's actually a src block and not verbatim text
           (org-element-type-p (org-element-context)
                               '(inline-src-block src-block))
           ;; Check result contains the uuid. There isn't a simple way
           ;; to extract the result value that works in all cases
           ;; (e.g. inline blocks or results drawers), so instead
           ;; check the result region contains the found uuid position
           (let ((result-where (org-babel-where-is-src-block-result)))
             (when result-where
               (save-excursion
                 (goto-char result-where)
                 (and
                  (>= uuid-pos (org-element-property :begin (org-element-context)))
                  (< uuid-pos (org-element-property :end (org-element-context)))))))))))