From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8M5BGMXYTmPeawAAbAwnHQ (envelope-from ) for ; Tue, 18 Oct 2022 18:48:05 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id OC5LF8XYTmPpzAAAG6o9tA (envelope-from ) for ; Tue, 18 Oct 2022 18:48:05 +0200 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 BB1938D for ; Tue, 18 Oct 2022 18:48:04 +0200 (CEST) Received: from localhost ([::1]:60382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okpl4-0004Fs-7a for larch@yhetil.org; Tue, 18 Oct 2022 12:48:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okpFy-0003el-Iy for emacs-orgmode@gnu.org; Tue, 18 Oct 2022 12:15:59 -0400 Received: from pie.tf ([5.45.99.52]:36712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1okpFu-0007H9-Q4 for emacs-orgmode@gnu.org; Tue, 18 Oct 2022 12:15:53 -0400 Received: from ip249.174.mip.uni-hannover.de ([130.75.174.249] helo=localhost) by pie.tf with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1okpFl-0000Zv-Rv; Tue, 18 Oct 2022 16:15:41 +0000 From: Ferdinand Pieper To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] Add light argument to org-babel-lob-get-info References: <877d109d3k.fsf@ims.uni-hannover.de> <87bkqaizns.fsf@localhost> Date: Tue, 18 Oct 2022 18:15:31 +0200 In-Reply-To: <87bkqaizns.fsf@localhost> (Ihor Radchenko's message of "Mon, 17 Oct 2022 09:10:15 +0000") Message-ID: <87wn8xds64.fsf@ims.uni-hannover.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=5.45.99.52; envelope-from=fer@pie.tf; helo=pie.tf X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-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." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666111685; 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; bh=+SG4CA8ETzRUB924bYyitY2tFxOmK1hDfysQ3ItSYhY=; b=CZf13blBfiehg1Qp2O6WTI5Dz9o3hTfVPEqfbLAlRl8uiMCBsrh9horUIUAe0TE0pXR3bz YTrVPXTGv27His5+3woOar3iweaseOyB7PPLXxnATHc4E/DMT53eeTQD7k0tBhvc2RKiZn BfpGIiCtllMfL6I+GfQlIXjQHEDxVWOjyMLpM9senVSiQ1CRTbaN2tBmbkmD3MiECnDKil 3YvIYpPFOhWube0xJufW1QCV4+yb7xVzEXpTnYVopaMVFylhkLKHcQffT3CBkkKkVV39DX bnv3Iz2DxDAcWXkgoSkYZDYxcM8oIZPOGbA/ob9a7FhX3c87e1dxNrvxoOJzmQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666111685; a=rsa-sha256; cv=none; b=cFjuGGGumr6KhowlMw5CA530hUdNt4IF/XwuOBzRb5HNmf4AXWeOnepWBD5s9yLYr/nwoB PIBMBdxq9ilwFgE7R2DXLzharMb5/dEo5IHcBIRMkl+hjsAMb7IBvfhRIJkn2zRrBCN3zg /k9Ajjo01njEllSo+Cjx9VG4Z4/fQQArAk9b7hte4YGsJEvpPXpMPGkqp3H0FDvi9+GUNQ LTDIcibT3zNI4NChEZvwpyUga1HmXMyNMmRnA9e6mJ6VUCHyt0wc0MinwjxQGXdTa7hMgI T0Pl/p7vr9mzGQNt5q4kTVIsCpuHObCwMyEJUvzD+pNRztqrRxUpNPDDyH4xnw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; 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" X-Migadu-Spam-Score: -2.62 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; 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" X-Migadu-Queue-Id: BB1938D X-Spam-Score: -2.62 X-Migadu-Scanner: scn1.migadu.com X-TUID: xQb81IEL3W3P --=-=-= Content-Type: text/plain Ihor Radchenko writes: > I'd prefer to change LIGHT to NO-EVAL, including in > org-babel-get-src-block-info. Changing argument name in function does > not affect its caller in any way. Just need to update the function body > and docstring carefully. > > NO-EVAL is already used by org-babel-parse-header-arguments and > org-babel-params-from-properties. I also prefer the NO-EVAL naming. I updated the patch to use no-eval and also added a second patch to rename the light argument of org-babel-get-src-block-info and all its occurrences (I changed the 'light to 'no-eval in all its calls only for consistency and future proofing reasons, altough it is unnecessary right now). Feel free to squash them into one commit. I was not sure wether one or two commits would be preferred. > May I know if you are proposing this for a specific purpose? Thanks for asking. I use it in a function that creates quasi unique names similar to org-babel-temp-file. But instead of random names it uses the source block content and header info to create a unique hash. This makes it very easy to create unique but from call to call consistent filenames in header arguments, when you don't want to worry about the filename, but also don't want to clutter your result directory (especially if its not /tmp) or care about constant filenames, e.g. for linking. Without the no-eval/light argument the hash generation gets stuck in a recursive loop. I attached the functions for reference. If there is wider interest in this, these could be added to org either as a variant of org-babel-temp-file or as an extension. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-babel-lob-get-info-Add-no-eval-argument.patch >From 22edd4f3a9382eb3dca5558b13053cba6fedf7ce Mon Sep 17 00:00:00 2001 From: fpi Date: Tue, 18 Oct 2022 17:27:54 +0200 Subject: [PATCH 1/2] org-babel-lob-get-info: Add no-eval argument * lisp/ob-lob.el (org-babel-lob-get-info): Add no-eval argument to prevent recursive evaluation of lisp values in parameters. --- lisp/ob-exp.el | 2 +- lisp/ob-lob.el | 13 +++++++++---- lisp/ob-ref.el | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index de7e1e3a3..67ed22f84 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -29,7 +29,7 @@ (require 'ob-core) -(declare-function org-babel-lob-get-info "ob-lob" (&optional datum)) +(declare-function org-babel-lob-get-info "ob-lob" (&optional datum no-eval)) (declare-function org-element-at-point "org-element" (&optional pom cached-only)) (declare-function org-element-context "org-element" (&optional element)) (declare-function org-element-property "org-element" (property element)) diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el index c6be8be80..10822accb 100644 --- a/lisp/ob-lob.el +++ b/lisp/ob-lob.el @@ -119,10 +119,15 @@ after REF in the Library of Babel." (cdr (assoc-string ref org-babel-library-of-babel)))))))) ;;;###autoload -(defun org-babel-lob-get-info (&optional datum) +(defun org-babel-lob-get-info (&optional datum no-eval) "Return internal representation for Library of Babel function call. Consider DATUM, when provided, or element at point otherwise. + +When optional argument NO-EVAL is non-nil, Babel does not resolve +remote variable references; a process which could likely result +in the execution of other code blocks, and do not evaluate Lisp +values in parameters. Return nil when not on an appropriate location. Otherwise return a list compatible with `org-babel-get-src-block-info', which @@ -144,16 +149,16 @@ see." org-babel-default-lob-header-args (append (org-with-point-at begin - (org-babel-params-from-properties language)) + (org-babel-params-from-properties language no-eval)) (list (org-babel-parse-header-arguments - (org-element-property :inside-header context)) + (org-element-property :inside-header context) no-eval) (let ((args (org-element-property :arguments context))) (and args (mapcar (lambda (ref) (cons :var ref)) (org-babel-ref-split-args args)))) (org-babel-parse-header-arguments - (org-element-property :end-header context))))) + (org-element-property :end-header context) no-eval)))) nil (org-element-property :name context) begin diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index 2b4a16aea..2bba2071e 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -57,7 +57,7 @@ (require 'org-macs) (require 'cl-lib) -(declare-function org-babel-lob-get-info "ob-lob" (&optional datum)) +(declare-function org-babel-lob-get-info "ob-lob" (&optional datum no-eval)) (declare-function org-element-at-point "org-element" (&optional pom cached-only)) (declare-function org-element-property "org-element" (property element)) (declare-function org-element-type "org-element" (element)) -- 2.20.1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-org-babel-get-src-block-info-Rename-light-argument.patch >From 015ce9ef56c997331ea34957d47fa98efffb54a3 Mon Sep 17 00:00:00 2001 From: fpi Date: Tue, 18 Oct 2022 17:34:18 +0200 Subject: [PATCH 2/2] org-babel-get-src-block-info: Rename light argument * lisp/ob-core.el (org-babel-get-src-block-info): Rename argument light to no-eval. --- lisp/ob-core.el | 20 ++++++++++---------- lisp/ob-lob.el | 2 +- lisp/ob-tangle.el | 6 +++--- lisp/org-pcomplete.el | 4 ++-- lisp/org-src.el | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index f273fa92e..c725a5508 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -339,7 +339,7 @@ then run `org-babel-execute-src-block'." This includes header arguments, language and name, and is largely a window into the `org-babel-get-src-block-info' function." (interactive) - (let ((info (org-babel-get-src-block-info 'light)) + (let ((info (org-babel-get-src-block-info 'no-eval)) (full (lambda (it) (> (length it) 0))) (printf (lambda (fmt &rest args) (princ (apply #'format fmt args))))) (when info @@ -640,10 +640,10 @@ the list of header arguments." (push elem lst))) (reverse lst))) -(defun org-babel-get-src-block-info (&optional light datum) +(defun org-babel-get-src-block-info (&optional no-eval datum) "Extract information from a source block or inline source block. -When optional argument LIGHT is non-nil, Babel does not resolve +When optional argument NO-EVAL is non-nil, Babel does not resolve remote variable references; a process which could likely result in the execution of other code blocks, and do not evaluate Lisp values in parameters. @@ -677,9 +677,9 @@ a list with the following pattern: ;; properties applicable to its location within ;; the document. (org-with-point-at (org-element-property :begin datum) - (org-babel-params-from-properties lang light)) + (org-babel-params-from-properties lang no-eval)) (mapcar (lambda (h) - (org-babel-parse-header-arguments h light)) + (org-babel-parse-header-arguments h no-eval)) (cons (org-element-property :parameters datum) (org-element-property :header datum))))) (or (org-element-property :switches datum) "") @@ -687,7 +687,7 @@ a list with the following pattern: (org-element-property (if inline :begin :post-affiliated) datum) (and (not inline) (org-src-coderef-format datum))))) - (unless light + (unless no-eval (setf (nth 2 info) (org-babel-process-params (nth 2 info)))) (setf (nth 2 info) (org-babel-generate-file-param name (nth 2 info))) info)))) @@ -933,7 +933,7 @@ arguments and pop open the results in a preview buffer." (defun org-babel-insert-header-arg (&optional header-arg value) "Insert a header argument selecting from lists of common args and values." (interactive) - (let* ((info (org-babel-get-src-block-info 'light)) + (let* ((info (org-babel-get-src-block-info 'no-eval)) (lang (car info)) (begin (nth 5 info)) (lang-headers (intern (concat "org-babel-header-args:" lang))) @@ -1130,7 +1130,7 @@ code block, otherwise return nil. With optional prefix argument RE-RUN the source-code block is evaluated even if results already exist." (interactive "P") - (pcase (org-babel-get-src-block-info 'light) + (pcase (org-babel-get-src-block-info 'no-eval) (`(,_ ,_ ,arguments ,_ ,_ ,start ,_) (save-excursion ;; Go to the results, if there aren't any then run the block. @@ -1967,7 +1967,7 @@ split. When called from outside of a code block a new code block is created. In both cases if the region is demarcated and if the region is not active then the point is demarcated." (interactive "P") - (let* ((info (org-babel-get-src-block-info 'light)) + (let* ((info (org-babel-get-src-block-info 'no-eval)) (start (org-babel-where-is-src-block-head)) (block (and start (match-string 0))) (headers (and start (match-string 4))) @@ -2916,7 +2916,7 @@ would set the value of argument \"a\" equal to \"9\". Note that these arguments are not evaluated in the current source-code block but are passed literally to the \"example-block\"." (let* ((parent-buffer (or parent-buffer (current-buffer))) - (info (or info (org-babel-get-src-block-info 'light))) + (info (or info (org-babel-get-src-block-info 'no-eval))) (lang (nth 0 info)) (body (nth 1 info)) (comment (string= "noweb" (cdr (assq :comments (nth 2 info))))) diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el index 10822accb..e4766a7d1 100644 --- a/lisp/ob-lob.el +++ b/lisp/ob-lob.el @@ -54,7 +54,7 @@ should not be inherited from a source block.") (interactive "fFile: ") (let ((lob-ingest-count 0)) (org-babel-map-src-blocks file - (let* ((info (org-babel-get-src-block-info 'light)) + (let* ((info (org-babel-get-src-block-info 'no-eval)) (source-name (nth 4 info))) (when source-name (setf (nth 1 info) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 3240b994e..2da92efaf 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -246,7 +246,7 @@ matching a regular expression." org-babel-default-header-args)) (tangle-file (when (equal arg '(16)) - (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 'light)))) + (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 'no-eval)))) (user-error "Point is not in a source code block")))) path-collector) (mapc ;; map over file-names @@ -461,7 +461,7 @@ code blocks by target file." (setq last-heading-pos current-heading-pos))) (unless (or (org-in-commented-heading-p) (org-in-archived-heading-p)) - (let* ((info (org-babel-get-src-block-info 'light)) + (let* ((info (org-babel-get-src-block-info 'no-eval)) (src-lang (nth 0 info)) (src-tfile (cdr (assq :tangle (nth 2 info))))) (unless (or (string= src-tfile "no") @@ -594,7 +594,7 @@ non-nil, return the full association list to be used by "Return a list of begin and end link comments for the code block at point. INFO, when non nil, is the source block information, as returned by `org-babel-get-src-block-info'." - (let ((link-data (pcase (or info (org-babel-get-src-block-info 'light)) + (let ((link-data (pcase (or info (org-babel-get-src-block-info 'no-eval)) (`(,_ ,_ ,params ,_ ,name ,start ,_) `(("start-line" . ,(org-with-point-at start (number-to-string diff --git a/lisp/org-pcomplete.el b/lisp/org-pcomplete.el index 225cdc093..14bdc55e9 100644 --- a/lisp/org-pcomplete.el +++ b/lisp/org-pcomplete.el @@ -35,7 +35,7 @@ (declare-function org-at-heading-p "org" (&optional ignored)) (declare-function org-babel-combine-header-arg-lists "ob-core" (original &rest others)) -(declare-function org-babel-get-src-block-info "ob-core" (&optional light datum)) +(declare-function org-babel-get-src-block-info "ob-core" (&optional no-eval datum)) (declare-function org-before-first-heading-p "org" ()) (declare-function org-buffer-property-keys "org" (&optional specials defaults columns)) (declare-function org-element-at-point "org-element" (&optional pom cached-only)) @@ -428,7 +428,7 @@ switches." (symbol-plist 'org-babel-load-languages) 'custom-type))))))) - (let* ((info (org-babel-get-src-block-info 'light)) + (let* ((info (org-babel-get-src-block-info 'no-eval)) (lang (car info)) (lang-headers (intern (concat "org-babel-header-args:" lang))) (headers (org-babel-combine-header-arg-lists diff --git a/lisp/org-src.el b/lisp/org-src.el index 2c1dd98ea..8744e98bf 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -1250,7 +1250,7 @@ name of the sub-editing buffer." "example")) (lang-f (and (eq type 'src-block) (org-src-get-lang-mode lang))) (babel-info (and (eq type 'src-block) - (org-babel-get-src-block-info 'light))) + (org-babel-get-src-block-info 'no-eval))) deactivate-mark) (when (and (eq type 'src-block) (not (functionp lang-f))) (error "No such language mode: %s" lang-f)) @@ -1282,7 +1282,7 @@ name of the sub-editing buffer." (user-error "Not on inline source code")) (let* ((lang (org-element-property :language context)) (lang-f (org-src-get-lang-mode lang)) - (babel-info (org-babel-get-src-block-info 'light)) + (babel-info (org-babel-get-src-block-info 'no-eval)) deactivate-mark) (unless (functionp lang-f) (error "No such language mode: %s" lang-f)) (org-src--edit-element -- 2.20.1 --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=org-babel-src-block-temp-file.el Content-Transfer-Encoding: quoted-printable (defun fpi/org-babel-get-src-block-hash (&optional block) "Return a hash based on src block content and header. This function tries to not take any file positions into account and always return the same hash given the same source code and same header arguments. `org-babel-sha1-hash' may provide the same feature, but I discovered that function only after writing this." (save-mark-and-excursion (if block (org-babel-goto-named-src-block block)) (let* ((info (or (org-babel-get-src-block-info t) (org-babel-lob-get-info nil t))) (body (nth 1 info)) (header (nth 2 info)) (hashstring (format "%s%s" body header))) (md5 hashstring)))) (setq fpi/org-babel-outfile-directory "/tmp/babel") (make-directory fpi/org-babel-outfile-directory t) (defun fpi/org-babel-src-block-temp-file (&optional suffix prefix directory= block) "Return a unique filename based on src block content and header. This function is intended as an alternative to `org-babel-temp-file' to provide unique and constant output filenames. Optionally provide SUFFIX or PREFIX of the filename and the file DIRECTORY. If SUFFIX or PREFIX is a list its content will be concatenated. Default directory is `org-babel-temporary-directory'. Optionally provide a source block name BLOCK. " ;; FIXME Way to create really unique names. In case same code can produce= different outputs (e.g. based on time, file context) (let ((hash (fpi/org-babel-get-src-block-hash block)) (directory (or directory fpi/org-babel-outfile-directory)) (suffix (if (listp suffix) (mapconcat (lambda (x) (cond ;; FIXME possible to handle all case= s without cond? ((symbolp x) (symbol-name x)) ((numberp x) (number-to-string x)) (t x) )) suffix "") suffix)) (prefix (if (listp prefix) (mapconcat (lambda (x) (cond ;; FIXME possible to handle all case= s without cond? ((symbolp x) (symbol-name x)) ((numberp x) (number-to-string x)) (t x) )) prefix "") prefix)) (prefix (or prefix "")) ) (expand-file-name (format "%s%s%s" prefix hash suffix) directory) )) --=-=-=--