From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id YOWiNaHj6F4jOAAA0tVLHw (envelope-from ) for ; Tue, 16 Jun 2020 15:22:09 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id iAZoMaHj6F5qBAAAbx9fmQ (envelope-from ) for ; Tue, 16 Jun 2020 15:22:09 +0000 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 7D021940C76 for ; Tue, 16 Jun 2020 15:22:09 +0000 (UTC) Received: from localhost ([::1]:50290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlDPc-0007il-CV for larch@yhetil.org; Tue, 16 Jun 2020 11:22:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlDOj-0007gR-Iv for emacs-orgmode@gnu.org; Tue, 16 Jun 2020 11:21:13 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:46524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jlDOj-0003SH-2D for emacs-orgmode@gnu.org; Tue, 16 Jun 2020 11:21:13 -0400 Received: by mail-qt1-x82b.google.com with SMTP id g18so15727831qtu.13 for ; Tue, 16 Jun 2020 08:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Quf/GQSjPUxKKcgh3+SLdEuEuA5AdoSWjmbASAaD2OM=; b=pWWxWniz2jRx0bGD2k0XlLj0tnlSrOgivN8CKryDHJdo2q1STKLuqt3ULqkayLhQqT ZhG8ec3fcVpNB04xynFaF9OreJU8dVPCqs8T6pkcNHu6tUPEXqXH/8Wq2VGRO3N/5mc7 DxCvaoq0kTRA7USAusoDK4m95UmIDjSLAfUglYfmSASQj2jW8Zwl4h9IF+7SmReH3qAc meX1SbshNeU9ltq50h7h+y447awFWghTI95JZEmrCObEr+i+ifJDjMeAW7MOK17Vv35I HPsezZFi9GX8H5g074alwTCdkl5Cpc9GQ4WjXx6FSW1pHgi+uCsvjB4Hh2BsuEse6ihN vfBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Quf/GQSjPUxKKcgh3+SLdEuEuA5AdoSWjmbASAaD2OM=; b=UG2uM2RDwpGC4mq8I8wLy1ZhDx/rdegfUe/7c+MCghuBdRW6FC8HC+wO7O1ohG0tR6 Lyqwc9Y0z0bilq7e+39L8GkdHEVXdSdwz1598mXy9iI/1TmcPFH3pA6hQCe5OVDT8kYf SuNZWO9I6BhrH/Ne+VJ5qO0Gjsz9xGkJM3lKiiXZyG8RkyLX7uicWnqnsCmS06wUv0ZE k7kEx2R9WcIP1wSoMOpw4QtJ1tjs5I2Qm4eTcCHFJdZtC5aNGOvQDftsCMLaDGMrAVqc lewz1vRETfDJfuJiEht8+casr6Is7xh5UvFWmnBayGSkvjLde2DAa7vXubI7fzsRVlt7 OKaQ== X-Gm-Message-State: AOAM532ekYzzgyF9mKjy4C9TfOD1Is7OxdSIb9jx9Cu5upQQsTXAjxby 3WSmhHB+omm4nGSg4LcdFKANh1xx X-Google-Smtp-Source: ABdhPJx2POdMh2ykShLhvUwkUAUIR7/TgzNHvFaREb4qg0PCuCqAfZZOS4Xb8de9NaZ3tstGOC6CEA== X-Received: by 2002:ac8:969:: with SMTP id z38mr21696190qth.77.1592320871209; Tue, 16 Jun 2020 08:21:11 -0700 (PDT) Received: from DESKTOP-HCCU8CL (c-68-42-123-130.hsd1.mi.comcast.net. [68.42.123.130]) by smtp.gmail.com with ESMTPSA id a5sm14380354qtw.22.2020.06.16.08.21.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jun 2020 08:21:10 -0700 (PDT) Date: Tue, 16 Jun 2020 11:21:10 -0400 From: Salomon Turgman To: emacs-orgmode@gnu.org Subject: Re: Import Reusable org-babel snippet using #+SETUPFILE Message-Id: <20200616112110.5646866fc6589d2b12f3646f@gmail.com> In-Reply-To: References: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=sturgman@gmail.com; helo=mail-qt1-x82b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=pWWxWniz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.21 X-TUID: 5N7u77i/VGoV Thanks for the useful example. I will take a look. Didn't know about org-sbe! -s- On Mon, 15 Jun 2020 15:52:16 -0400 Douglas Perrin wrote: > Hi Salomon Turgman, > I do this a lot and have had success using a combination of #+SETUPFILE to > bring in names and configuration, and org-sbe to do initialization. I mix > emacs vars and org names in my source headers with back quoting. > > The following example has a template file containing user/local > information. This is brought into the example file, on load, through #:eval > calling org-babel-lob-ingest and org-sbe, in addition, parameters are > pulled in with #+SETUPFILE and the same template file name. The end result > for this example is a running docker image with access to local paths and > "remote" execution via tramp. More complex orchestration and actions in the > template are certainly possible using org-sbe calls in the init elisp > source blocks but hopefully, this shows the flavor of what can be done. > > In addition to avoiding code duplication, I have found this to be very > effective when my group is all working from the same org file (via git) but > everyone has their own template file with credentials, local paths, and org > more preferences (ie showstars). > Regards, > Doug > > --------------------------------------------------------------------------------------------------------------------------------- > TemplatingExample.org > --------------------------------------------------------------------------------------------------------------------------------- > #+SETUPFILE: Template-Loader.org > > * Init Code, run when file is opened > #+name: Execute-On-Load > #+begin_src elisp :results output > ;; for this the container and image have the same name > (setq *DockerName* "ContanerName") > #+end_src > > * Run Contaner > #+begin_src bash :results raw drawer :var DockerName=`,*DockerName* > DockerHubUID=`,*DockerHubUID* containerName=`,*DockerContainer* > LocalWorkPath=`,*LocalWorkPath* LocalDataPath=`,*LocalDataPath* > docker run --rm -d \ > -v $LocalWorkPath:/root/Workdir \ > -v $LocalDataPath:/root/Data \ > --name $DockerName $DockerHubUID/$DockerName bash -c "tail -f > /dev/null" > #+end_src > > * run IN contaner > #+begin_src bash :results output :dir (concat "/docker:" `,*DockerName* > ":/root/Workdir/") > ls > #+end_src > > # Local Variables: > # eval: (org-babel-lob-ingest "Template-Loader.org") > # eval: (org-sbe "Init-Template") > # eval: (org-sbe "Execute-On-Load") > # End: > > --------------------------------------------------------------------------------------------------------------------------------- > Template-Loader.org > --------------------------------------------------------------------------------------------------------------------------------- > #+STARTUP: showstars > #+PROPERTY: header-args :mkdirp yes > > #+name: Init-Template > #+begin_src emacs-lisp :results none > ;; This is called expecitly via org-sbe in the buffer that will uses the > templating > (setq *DockerHubUID* "MyUserName") > (setq *LocalWorkPath* "/run/desktop/mnt/host/c/Users/.....") > (setq *LocalDataPath* "/run/desktop/mnt/host/d/devData/") > > ;; ingest + SBE can be used to bring in a hierarchy of templates > (org-babel-lob-ingest "./GroupTools/GeneralORGTools.org") > (org-sbe "GeneralORGTools.org") > > #+end_src -- Salomon Turgman