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 AJzSLDPjBGCVRwAA0tVLHw (envelope-from ) for ; Mon, 18 Jan 2021 01:24:03 +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 cHCNKDPjBGApYQAAbx9fmQ (envelope-from ) for ; Mon, 18 Jan 2021 01:24:03 +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 348919403AE for ; Mon, 18 Jan 2021 01:24:02 +0000 (UTC) Received: from localhost ([::1]:37682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1JGy-0002Ik-B1 for larch@yhetil.org; Sun, 17 Jan 2021 20:24:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1JFy-0002Ic-2l for emacs-orgmode@gnu.org; Sun, 17 Jan 2021 20:22:59 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:54871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1JFv-0000mY-C2 for emacs-orgmode@gnu.org; Sun, 17 Jan 2021 20:22:57 -0500 Received: by mail-wm1-x32f.google.com with SMTP id i63so12174723wma.4 for ; Sun, 17 Jan 2021 17:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrew-cmu-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bMfi0nDDk/wO5B66W6PyOWxTQUDZQxzJHdfSCbwPu0w=; b=0+yp0etKqlIFh5+oOvudF0c7AInpTsZ1Inek9bEyZdejH7YdCVPu2/OsBEF5ATAAD0 wFOOXO4eaLgDk9YdygAWZCN17gbSiptxySXaEUJdC/i9osNZLsDvszUwRPEOb1uSfFkr FcdzOILgPY55EOgP5HS9pFhVgHw28Y2dNuyRzaOkxpof5XlbmayV5vmFrc6Wcv4bkfqR QOincWGqea3z3MI+HQEZ3AJASYL8DsgczcIK7LDxe/9jkpItCPyI8HjB+x3lLWsXbKDc L8+fMzjrvK6hReJpZHTYnl8K2muHBwzBa8+vgNbEdTTUtuE0vae4lNPlFW10i674f9wy GiuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bMfi0nDDk/wO5B66W6PyOWxTQUDZQxzJHdfSCbwPu0w=; b=e2DxzIMALkBfasCNo04PYF3S469hq3PRHNUJU1JDkkneE2Bu2g6heSGmrlVw407uFP ygmBUHl5Q4CRCp90SN40dnjK1eaL4rJgYTP954rQYdWjWZyhhIdcZANsR28k0rszTF3C 69xAxbozKmIw6UXOGE6hQoXgkhlxaDm5aaG/iEvdrTLpTK2B8JUeHD4lLp8bwNlPMQCR DXz51g4TPtyH01kLwA7h/QWMyXcfUUPH7AUIcuPeF9oCDYd6CzA1BFAJTKPG6QKB9qZg hlV0drDOxJvjEWzQC+Wlycq16rlttu8HZjI8YJ/Pet9Aza9bhU/GRI/m+Gyb55+DMYrw 1Wqw== X-Gm-Message-State: AOAM532hE6mUStj3Fv1oc7MUWxrUXLPGm+YeDjwNXAcCbORK0MmeSuRf stm0DnngbX+TsR6S7viXbGk1rYHEbUDWO4SnPcU= X-Google-Smtp-Source: ABdhPJxbmiJDhC8aTMaEOZ4h3+0+FFMBeHWZzC7zQUba3eCKFDKmyMk6BJ5U+nJybi6BdyK+Ox5ptzG9tpv44T/jpYs= X-Received: by 2002:a1c:a145:: with SMTP id k66mr18397072wme.18.1610932973426; Sun, 17 Jan 2021 17:22:53 -0800 (PST) MIME-Version: 1.0 References: <6cef612f-cb56-90d3-0d44-68ab2be9fa8a@XXXXXXXXX.XXX> In-Reply-To: <6cef612f-cb56-90d3-0d44-68ab2be9fa8a@XXXXXXXXX.XXX> From: John Kitchin Date: Sun, 17 Jan 2021 20:22:42 -0500 Message-ID: Subject: Re: self-referencing babel shell code blocks To: HJ Content-Type: multipart/alternative; boundary="000000000000a3597905b9228f7b" Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=johnrkitchin@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: , Cc: org-mode-email Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.46 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=0+yp0etK; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=andrew.cmu.edu (policy=none); 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-Migadu-Queue-Id: 348919403AE X-Spam-Score: -2.46 X-Migadu-Scanner: scn1.migadu.com X-TUID: NBpYHcwEF2Wy --000000000000a3597905b9228f7b Content-Type: text/plain; charset="UTF-8" see https://stackoverflow.com/questions/3139970/open-a-file-at-line-with-filenameline-syntax there are also ways to make fancier org-links, but I think you will find what you need in that link. John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Sun, Jan 17, 2021 at 7:33 PM HJ wrote: > > Dear Mr Kitchin, > > you are a genius !!!!!! > > A BIG THANK YOU!!! > > Wow. I couldn't imagine someone might be able to do this so quickly > and perfectly. Wow. > > thank you so much > > HJ > > PS: Now I'm off to figure out how to invoke emacs to tell it to open up > the window and show this file at the place where this-block block > appears ... > > > On 1/18/21 1:12 AM, John Kitchin wrote: > > I guess this is what you mean: > > > > > > * heading L1_12 > > ** heading L2_37 > > > > #+name: this-block > > #+header: :var VAR1=(getenv "HOSTNAME") > > #+header: :var VAR2=(message user-login-name) > > #+header: :var VAR3=(buffer-file-name) > > #+header: :var VAR4=(org-element-property :name (org-element-context)) > > #+header: :var VAR5=(org-no-properties (org-display-outline-path nil t)) > > #+header: :var VAR5a=(line-number-at-pos (org-element-property :begin > > (org-element-context))) > > #+header: :var VAR6=(s-trim (shell-command-to-string "git rev-parse > > HEAD")) > > #+header: :var VAR7=(s-trim (shell-command-to-string "git branch > > --show-current")) > > #+BEGIN_SRC sh :results raw > > echo Run by $VAR2 from $VAR3 > > echo In a src-block named $VAR4 in $VAR5 at line $VAR5a > > echo on commit $VAR6 in git branch $VAR7 > > #+END_SRC > > > > #+RESULTS: this-block > > Run by jkitchin from > > /Users/jkitchin/Dropbox/emacs/journal/2021/01/17/2021-01-17.org > > > > In a src-block named this-block in heading L1_12/heading L2_37 at line > 140 > > on commit a07475addc3fdf557fb46a72b1100cf1c9c0805a in git branch master > > > > > > > > John > > > > ----------------------------------- > > Professor John Kitchin > > Doherty Hall A207F > > Department of Chemical Engineering > > Carnegie Mellon University > > Pittsburgh, PA 15213 > > 412-268-7803 > > @johnkitchin > > http://kitchingroup.cheme.cmu.edu > > > > > > > > On Sun, Jan 17, 2021 at 4:42 PM HJ > > wrote: > > > > > > hi, > > > > I'm trying to figure out how to write a block , header, > > PROPERTY or > > whatever is necessary so the output of a command in babel source > > block > > identifies it own position - the line (or block or something) in > > buffer > > (or at least the file) in which it is written. ( Plus the checked out > > git revision / branch. ) > > > > > > I've been experimenting with the following, so far without much > > luck ... > > > > Which of these pieces of information (see the "echo" line below) > > is it > > possible to get? Which is easy? (variables VAR[0345] are most > > critical) > > How would one write a snippet which provides (some of) this > > information? > > > > Is it much harder with command 1 being SSH to a remote machine? > > Would > > ":dir user@remotemachine:/some/dir" work better? Or at all? > > > > Perhaps I would know how to find out VAR6 and VAR7 by running first > > some `git cmd1` and `git cmd2` locally in a " command 0 " - but is > > there > > a way to get that info from magit somehow? > > > > But what I am most desperate for is how to cause orgmode block > > to set > > VAR0, VAR3, VAR4 and VAR5, and - also fairly important - how to > > use the > > combination of VAR[0345] do open / recall the file onto the screen > > > > Thanks a million for helping me out here ... > > > > HJ > > > > > > This is the sample file : > > > > > > * heading L1_12 > > Hello and welcome, this is a file with self-referencing shell > > babel source code blocks > > ... > > ** heading L2_37 > > ... > > #+NAME: block220 > > #+BEGIN_SRC bash :session sess9 > > : command 0 ; cd > > _how-do-I-find-the-dir-of-currently-edited-file_ ; VAR6=`git cmd1` > > ; VAR7=`git cmd2` > > : command 1 ; ssh -o "SetEnv VAR1=machine VAR2=user VAR3=..." > > targetUser@targetMachine > > #+END_SRC > > > > > > ... > > > > #+NAME: block225 > > #+BEGIN_SRC bash :session sess9 > > : command 2 ; : do some computation on targetMachine > > : command 3 ; echo This code has been launched from emacs > > process VAR0:_EMACS_SESSION_ID_ \ > > on computer $VAR1:_SRC_HOSTNAME_ \ > > run by user $VAR2:_USER_ \ > > from file $VAR3:_FILENAME_ \ > > code block named $VAR4:block225 \ > > in this file positioned under headings: $VAR5:heading > > L1_12/heading L2_37/ \ > > which is checked out from $VAR6:_GIT_COMMIT_ID_ \ > > on branch $VAR7:_GIT_BRANCH_ > > : command 3 continues ; echo To display the buffer which > > launched this code on the screen of the running emacs session, run > > the following command : emacs _What_the_heck_do_I_put_here?_ '&' > > #+END_SRC > > > > > > > > > > > > > > > --000000000000a3597905b9228f7b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
see=C2=A0https://stackoverflow.c= om/questions/3139970/open-a-file-at-line-with-filenameline-syntax
<= br>
there are also ways to make fancier org-links, but I think yo= u will find what you need in that link.

John

--------------------------= ---------
Professor John Kitchin=C2=A0
Doherty Hall A207F
Departme= nt of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA = 15213
412-268-7803


On Sun, Jan 17, = 2021 at 7:33 PM HJ <hj-o= rgmode-1@hj.proberto.com> wrote:

Dear Mr Kitchin,

=C2=A0=C2=A0 you are a genius !!!!!!

=C2=A0=C2=A0=C2=A0 A BIG THANK YOU!!!

=C2=A0=C2=A0 Wow. I couldn't imagine someone might be able to do this s= o quickly
and perfectly. Wow.

=C2=A0=C2=A0=C2=A0 thank you so much

=C2=A0=C2=A0=C2=A0=C2=A0 HJ

PS: Now I'm off to figure out how to invoke emacs to tell it to open up=
the window and show this file at the place where this-block block
appears ...


On 1/18/21 1:12 AM, John Kitchin wrote:
> I guess this is what you mean:
>
>
> * heading L1_12
> ** heading L2_37
>
> #+name: this-block
> #+header: :var VAR1=3D(getenv "HOSTNAME")
> #+header: :var VAR2=3D(message user-login-name)
> #+header: :var VAR3=3D(buffer-file-name)
> #+header: :var VAR4=3D(org-element-property :name (org-element-context= ))
> #+header: :var VAR5=3D(org-no-properties (org-display-outline-path nil= t))
> #+header: :var VAR5a=3D(line-number-at-pos (org-element-property :begi= n
> (org-element-context)))
> #+header: :var VAR6=3D(s-trim (shell-command-to-string "git rev-p= arse
> HEAD"))
> #+header: :var VAR7=3D(s-trim (shell-command-to-string "git branc= h
> --show-current"))
> #+BEGIN_SRC sh :results raw
> echo Run by $VAR2 from $VAR3
> echo In a src-block named $VAR4 in $VAR5 at line $VAR5a
> echo on commit $VAR6 in git branch $VAR7
> #+END_SRC
>
> #+RESULTS: this-block
> Run by jkitchin from
> /Users/jkitchin/Dropbox/emacs/journal/2021/01/17/2021-01-17.org
> <http://2021-01-17.org>
> In a src-block named this-block in heading L1_12/heading L2_37 at line= 140
> on commit a07475addc3fdf557fb46a72b1100cf1c9c0805a in git branch maste= r
>
>
>
> John
>
> -----------------------------------
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu <http://kitch= ingroup.cheme.cmu.edu>
>
>
>
> On Sun, Jan 17, 2021 at 4:42 PM HJ <hj-orgmode-1@hj.proberto.com
> <mailto:hj-orgmode-1@hj.proberto.com>> wrote:
>
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0hi,
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0 I'm=C2=A0 trying to figure out how= to write a block , header,
>=C2=A0 =C2=A0 =C2=A0PROPERTY or
>=C2=A0 =C2=A0 =C2=A0whatever is necessary so the output of a command in= babel source
>=C2=A0 =C2=A0 =C2=A0block
>=C2=A0 =C2=A0 =C2=A0identifies it own position - the line (or block or = something) in
>=C2=A0 =C2=A0 =C2=A0buffer
>=C2=A0 =C2=A0 =C2=A0(or at least the file) in which it is written. ( Pl= us the checked out
>=C2=A0 =C2=A0 =C2=A0git revision / branch. )
>
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0I've been experimenting with the fo= llowing, so far without much
>=C2=A0 =C2=A0 =C2=A0luck ...
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0Which of these pieces of information (s= ee the "echo" line below)
>=C2=A0 =C2=A0 =C2=A0is it
>=C2=A0 =C2=A0 =C2=A0possible to get? Which is easy? (variables VAR[0345= ] are most
>=C2=A0 =C2=A0 =C2=A0critical)
>=C2=A0 =C2=A0 =C2=A0How would one write a snippet which provides (some = of) this
>=C2=A0 =C2=A0 =C2=A0information?
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0Is it much harder with command 1 being = SSH to a remote machine?
>=C2=A0 =C2=A0 =C2=A0Would
>=C2=A0 =C2=A0 =C2=A0":dir user@remotemachine:/some/dir" work = better? Or at all?
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0Perhaps I would know how to find out VA= R6 and VAR7 by running first
>=C2=A0 =C2=A0 =C2=A0some `git cmd1` and `git cmd2` locally in a " = command 0 " - but is
>=C2=A0 =C2=A0 =C2=A0there
>=C2=A0 =C2=A0 =C2=A0a way to get that info from magit somehow?
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0But what I am most desperate for is how= to cause orgmode block
>=C2=A0 =C2=A0 =C2=A0to set
>=C2=A0 =C2=A0 =C2=A0VAR0, VAR3, VAR4 and VAR5, and - also fairly import= ant - how to
>=C2=A0 =C2=A0 =C2=A0use the
>=C2=A0 =C2=A0 =C2=A0combination of VAR[0345] do open / recall the file = onto the screen
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0Thanks a million for helping me out her= e ...
>
>=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 HJ
>
>
>=C2=A0 =C2=A0 =C2=A0This is the sample file :
>
>
>=C2=A0 =C2=A0 =C2=A0* heading L1_12
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0Hello and welcome, this is a file with= self-referencing shell
>=C2=A0 =C2=A0 =C2=A0babel source code blocks
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0...
>=C2=A0 =C2=A0 =C2=A0** heading L2_37
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0...
>=C2=A0 =C2=A0 =C2=A0#+NAME: block220
>=C2=A0 =C2=A0 =C2=A0#+BEGIN_SRC=C2=A0 bash=C2=A0 :session sess9
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0: command 0 ;=C2=A0 cd
>=C2=A0 =C2=A0 =C2=A0_how-do-I-find-the-dir-of-currently-edited-file_ ; = VAR6=3D`git cmd1`
>=C2=A0 =C2=A0 =C2=A0; VAR7=3D`git cmd2`
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0: command 1 ;=C2=A0 ssh -o "SetEn= v VAR1=3Dmachine VAR2=3Duser VAR3=3D..."=C2=A0
>=C2=A0 =C2=A0 =C2=A0=C2=A0 targetUser@targetMachine
>=C2=A0 =C2=A0 =C2=A0#+END_SRC
>
>
>=C2=A0 =C2=A0 =C2=A0...
>
>=C2=A0 =C2=A0 =C2=A0#+NAME: block225
>=C2=A0 =C2=A0 =C2=A0#+BEGIN_SRC=C2=A0 bash=C2=A0 :session sess9
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0: command 2 ; : do some computation on= targetMachine
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0: command 3 ; echo This code has been = launched from emacs
>=C2=A0 =C2=A0 =C2=A0process VAR0:_EMACS_SESSION_ID_ \
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 =C2=A0on computer $VAR1:_SRC_HOSTNAME= _ \
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 =C2=A0run by user $VAR2:_USER_ \
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 =C2=A0from file $VAR3:_FILENAME_ \ >=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 =C2=A0code block named $VAR4:block225= \
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 =C2=A0in this file positioned under h= eadings: $VAR5:heading
>=C2=A0 =C2=A0 =C2=A0L1_12/heading L2_37/ \
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 =C2=A0which is checked out from $VAR6= :_GIT_COMMIT_ID_ \
>=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 =C2=A0on branch $VAR7:_GIT_BRANCH_ >=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0: command 3 continues ; echo To displa= y the buffer which
>=C2=A0 =C2=A0 =C2=A0launched this code on the screen of the running ema= cs session, run
>=C2=A0 =C2=A0 =C2=A0the following command :=C2=A0 =C2=A0 emacs _What_th= e_heck_do_I_put_here?_=C2=A0 '&'
>=C2=A0 =C2=A0 =C2=A0#+END_SRC
>
>
>
>
>
>
>
--000000000000a3597905b9228f7b--