From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id mHvOCRju+GPQagEAbAwnHQ (envelope-from ) for ; Fri, 24 Feb 2023 18:04:24 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id oN7gCRju+GM/OAEA9RJhRA (envelope-from ) for ; Fri, 24 Feb 2023 18:04:24 +0100 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 E2B463DDA4 for ; Fri, 24 Feb 2023 18:04:23 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVbTs-00030E-BZ; Fri, 24 Feb 2023 12:03:36 -0500 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 ) id 1pVbTg-0002po-GS for emacs-orgmode@gnu.org; Fri, 24 Feb 2023 12:03:26 -0500 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVbTe-0007e1-98 for emacs-orgmode@gnu.org; Fri, 24 Feb 2023 12:03:24 -0500 Received: by mail-pj1-x1035.google.com with SMTP id kb15so228103pjb.1 for ; Fri, 24 Feb 2023 09:03:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:subject:to:from:user-agent:from:to:cc :subject:date:message-id:reply-to; bh=R/i/PxgDLA1Jn+xEj7dzFba9lTXhfrZ+Bre2sYWEJOI=; b=Jk5pkUqRzeSb2H3s1SxCA1fhRcuZsn1nqGIcEepHyTFJR+CleOX3zJIWTK2EcGIBp+ x5iFPPbsw4LMiRkCt5C860CRBxNTcXWQUkWV5wMDJ5NuVC6nj+pQUwScuRU61FoQCgyf e6z9YmFCH65yWV+PlLbpTLRCFR14vFxOXe5o7R9yx73EsPWNrk0Dj7uk91BVdUnjQpPR pg0Hq/Ket7BSKQZVSTwqIiiSZyd9aaVz9kRA1VKCdmzY+BQ0w9KZmEjKYM/eFABbZ4yw mCpFPCMwP8uCLoyGnUILPOKd+ky0kJgCockMFHhldRBGl8i5UDIkC8vw2qLayOhhtJh8 H+cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:to:from:user-agent :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R/i/PxgDLA1Jn+xEj7dzFba9lTXhfrZ+Bre2sYWEJOI=; b=3/scNOsOQLb9f80bUDGgTNod6jyr1Whl7thR+rebZQT2MGpEBx7YZr2IpvUdlwwggb Us0FSgq5vr5pwLHsGfx6fEcSkRLseencaw3RSW0Q+pyNWJa9lwoxYHCWD2BJEy8fPh1y UYGkyH0y0yX0Enslf7ZLSHaD7DTqd7QeCjibS5Y+ccTY+4HS8BwQ7Hc+WboqVCUXUqwW 1fhA+rUgxTWPj6AxO27WUDqiO2oS5KyDDv6bsjg5CE89GDx4zGewA/W3vCoUVo0tK8gs FE2iH+YQTaanII+qskKOmupcrgafBpdDha4nC04TajH0iJhV5XLe+rWHIaay4pAYnzqR ywCw== X-Gm-Message-State: AO0yUKWy1IzXEbaIIEyjMIRHESxWK0UPLwN/5wvUE2OzfUbm3BVl2ZAO asCaTS6bkVGV2+2UQPvK7u+ePgdwnkPlR88Ou2I= X-Google-Smtp-Source: AK7set8HyY7GAO1A7J3v3tf8GfZkDH/+WQcMggIUA9066v638Ci0fuI3GTXG5/IcPdRprh35um5qjA== X-Received: by 2002:a05:6a20:8f07:b0:cb:7f0d:e25f with SMTP id b7-20020a056a208f0700b000cb7f0de25fmr16984329pzk.41.1677258199854; Fri, 24 Feb 2023 09:03:19 -0800 (PST) Received: from t480 (97-113-138-203.tukw.qwest.net. [97.113.138.203]) by smtp.gmail.com with ESMTPSA id t16-20020a62ea10000000b005d932d0c029sm4134459pfh.65.2023.02.24.09.03.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 09:03:19 -0800 (PST) User-agent: mu4e 1.8.13; emacs 27.1 From: Ken Mankoff To: Org-mode Subject: [PATCH] lisp/ob-screen.el: Support ~:var~ header args for babel blocks Date: Fri, 24 Feb 2023 09:03:18 -0800 Message-ID: <87pm9z8089.fsf@t480.home> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=mankoff@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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 ARC-Seal: i=1; s=key1; d=yhetil.org; t=1677258263; a=rsa-sha256; cv=none; b=RokefiFmvGwvwtK4LAacmm2f0xRYYCcq74z2Jyah/ayI0VUnwYeynwCLjgFeO9FI2WDbH/ nS/8Do9UbvYVS8ruJeKj/OEuK41VcoLSxaR/tfK1BT/ivr0amq4qEESaVr/6LQwCMH9jCT B+ZtAlsf/x68G1jXjSAPn3k5jU159d9AnZ16IBvQGNhabgy14DOGeuEWBotEHHhxTcfwMC msMyiYKedkbC6H/+qXLozs5i0ahByWGrAV7mpumZxcRYxWCBs7MJWGXqcheNSvQZJNHcjT 8LVG7AdeUCAk93qoThMV4wdE7RBzQUJ5/KEG0wkgEstlfHqjd+ACv0+zsTuS5w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Jk5pkUqR; dmarc=pass (policy=none) header.from=gmail.com; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1677258263; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=R/i/PxgDLA1Jn+xEj7dzFba9lTXhfrZ+Bre2sYWEJOI=; b=bTJxQnWSiuiSkIrXS1/nnS56SBMRA6JI1V/SpJgtO/i6snd5KcLBmBURM53Y/oK/9qBmwk +vnJU0EreD+U8vkzlmXuK7IXPDl8DjZnfwW2kbtjaG2/gdGQxsmcpCXkaQQpxsNz3Y9YGG /aw3qp4qtg+lr755C5ke5eLv+1rqK9UcYXvzDp+/UINjmGjt1LOaIsZv17CYvq6XP8/RZM vfL46An9s/phgDfToQfBjigLmFb5jN4na2the/kqz7WO1bNeFVIEuE5cRT2vH0zVaFtGZN QfyqsZ60+36dcbsPwXTLskNdd9hGVvcMTh2smMJpxkc83Z2nEj1gxsf6h1NU0Q== X-Migadu-Queue-Id: E2B463DDA4 X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Jk5pkUqR; dmarc=pass (policy=none) header.from=gmail.com; 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: -4.90 X-Spam-Score: -4.90 X-TUID: wQzspW3edxzU * ob-screen.el: (org-babel-execute:screen): Parse header params for `:var', then inject into screen session. (org-babel-variable-assignments:screen): Copied from ob-shell.el org-babel-variable-assignments:shell * etc/ORG-NEWS: Document as New Feature This change only supports single-value variables (e.g., ~:var x=42~), not tables or arrays as is currently supported by some other languages. --- etc/ORG-NEWS | 13 +++++++++++++ lisp/ob-screen.el | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 87ecd77cd..d4b454d13 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -106,6 +106,19 @@ selection. TODO state, priority, tags, statistics cookies, and COMMENT keywords are allowed in the tree structure. +*** ob-screen now supports :var header arguments + +The ~:var~ header arg now supports simple single-value variables +(arrays and tables are not supported). + +#+BEGIN_src org +,#+BEGIN_SRC screen :var x=42 +,echo $x +,#+END_SRC +#+END_src + + + * Version 9.6 ** Important announcements and breaking changes diff --git a/lisp/ob-screen.el b/lisp/ob-screen.el index 269538e79..d8f361e50 100644 --- a/lisp/ob-screen.el +++ b/lisp/ob-screen.el @@ -55,11 +55,32 @@ In case you want to use a different screen than one selected by your $PATH") (message "Sending source code block to interactive terminal session...") (save-window-excursion (let* ((session (cdr (assq :session params))) + (var-lines (org-babel-variable-assignments:screen params)) (socket (org-babel-screen-session-socketname session))) (unless socket (org-babel-prep-session:screen session params)) + (mapcar (lambda (var) + (org-babel-screen-session-execute-string session var)) + var-lines) (org-babel-screen-session-execute-string session (org-babel-expand-body:generic body params))))) +(defun org-babel-variable-assignments:screen (params) + "Return list of shell statements assigning the block's variables." + ;; From ob-shell but change function name from ":shell" to ":screen" + (let ((sep (cdr (assq :separator params))) + (hline (when (string= "yes" (cdr (assq :hlines params))) + (or (cdr (assq :hline-string params)) + "hline")))) + (mapcar + (lambda (pair) + (if (string-suffix-p "bash" shell-file-name) + (org-babel--variable-assignments:bash + (car pair) (cdr pair) sep hline) + (org-babel--variable-assignments:sh-generic + (car pair) (cdr pair) sep hline))) + (org-babel--get-vars params)))) + + (defun org-babel-prep-session:screen (_session params) "Prepare SESSION according to the header arguments specified in PARAMS." (let* ((session (cdr (assq :session params)))