emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org babel source blocks ignore buffer-local variables
@ 2021-09-04 12:30 Dominik Schrempf
  2021-09-04 17:14 ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Schrempf @ 2021-09-04 12:30 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I use directory local environments with =envrc= [1], and run into trouble when
using (Bash) Org Babel source code blocks. The buffer local environment seems to
be ignored (see the example at the bottom).

This seems to have been discussed in the course of a GitHub issue of
=inheritenv= [2], which is pulled in by =envrc=. Also, on this mailing list,
there was a short discussion [3].

Do you have any thoughts on this? Is there an easy way to make Org Babel source
blocks honor buffer local setups?

Thank you!
Dominik

#+name: Scratch
#+begin_src sh :exports both :results output verbatim
function path () { echo "$PATH" | tr ':' '\n'; }
path
#+end_src

#+RESULTS: Scratch
#+begin_example
/home/dominik/Evolutionary-Biology/Scripts/nix-flakes
/home/dominik/Evolutionary-Biology/Scripts
/home/dominik/bin/nix-flakes
/home/dominik/bin
/run/wrappers/bin
/home/dominik/.nix-profile/bin
/etc/profiles/per-user/dominik/bin
/nix/var/nix/profiles/default/bin
/run/current-system/sw/bin
/nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2/libexec/emacs/27.2/x86_64-pc-linux-gnu
#+end_example

The Emacs =exec-path= variable has the following value:

#+begin_quote
exec-path is a variable defined in ‘C source code’.
Its value is
("/nix/store/cnxncxyghj3gfpfvng6z4l8k4hfl48wq-ghc-8.10.6-with-packages/bin/" "/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin/" "/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0/bin/" "/nix/store/dlni53myj53kx20pi4yhm7p68lw17b07-gcc-10.3.0/bin/" "/nix/store/6z35qvn00xrjvaznv9kfy8xddbbdz4gl-glibc-2.33-47-bin/bin/" "/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin/" "/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1/bin/" "/nix/store/v8imx1nvyz0hgvx9cbcmh6gp4ngw3ffj-binutils-2.35.1/bin/" "/nix/store/iz7bgfvjmwdz3vgmzryhfkqwbn8zr2jn-ncurses-6.2/bin/" "/nix/store/w07a7k61dw5gnsyxj3kgcq3shr76jax8-bash-interactive-4.4-p23/bin/" "/nix/store/xhxll8hx0x9szhlvvd8h1c35glszlj34-cabal-install-3.4.0.0/bin/" "/nix/store/gbxdjp9z1bjx1zl6icckw093yv0vn21r-haskell-language-server-1.2.0.0/bin/" "/nix/store/mx8v4f0hq8nff5ab7mcgmmbxn5rk6al4-aeson-pretty-0.8.8/bin/" "/nix/store/xygkar338ssrwqjcpmmbv1pkkpqc1yfy-ghc-8.10.6/bin/" "/nix/store/w16zhm17a73sn3sshqgpxjk3r265vb9l-ghcide-1.4.0.3/bin/" "/nix/store/isja3hvzjmmg7278mdsyyn0k4s7k6cf8-constraints-extras-0.3.1.0/bin/" "/nix/store/9kz9pwpgnq4miywf5bk97xpn4qqz1h2c-hie-bios-0.7.5/bin/" "/nix/store/wfpjw96bjc1kwx5spddwgpi8r4jrbc6b-hiedb-0.4.0.0/bin/" "/nix/store/il7l9fjr7r0sq00iy0jr6pcwcb97227p-shake-0.19.5/bin/" "/nix/store/9i7z6c6ydhkw1ch37hvpi6fywbfkyrm0-implicit-hie-0.1.2.6/bin/" "/nix/store/88kdasbl46rhfnz249dxnh5n9amr27pv-retrie-1.0.0.0/bin/" "/nix/store/i7djw6911qk0vkkxv5rsm2zh95arfmjp-brittany-0.13.1.2/bin/" "/nix/store/5mpyw1f5jamnvnhsawj147vyvwpw054s-floskell-0.10.5/bin/" "/nix/store/aj2q5q38wzlsl60vwcxirlc133p3i8hj-fourmolu-0.3.0.0/bin/" "/nix/store/mr0algmndmq73ybhnk3752ylhpnp7918-apply-refact-0.9.3.0/bin/" "/nix/store/k9h1adjqqwmq39iik3253cgxdd5drgz8-hlint-3.2.7/bin/" "/nix/store/rdjb7sx4clhzjfal0xhb41x1k62nchf0-cpphs-1.20.9.1/bin/" "/nix/store/wlh74ffhf19ychrcf65885jsx8xy5f8d-hscolour-1.24.4/bin/" "/nix/store/1lbb1bzjqcblb946av3703g76ng18jx1-ormolu-0.1.4.1-bin/bin/" "/nix/store/jvx2rcmbcrjpsvz4p8z5zll4gchmhl75-stylish-haskell-0.12.2.0/bin/" "/nix/store/h0yyp8i85y3cahd1wyxb0a0izxqz2gxj-stack-2.7.3/bin/" "/nix/store/62m5yxq7f9gz4xn3qlvkvkna237vz92k-hpack-0.34.4/bin/" "/nix/store/ki59g3c2y2ahpjja9hch3wxgl7gki5f3-mustache-2.3.1/bin/" "/nix/store/1wdm2g4mz9is77iihfkbycq3m8c2frrv-open-browser-0.2.1.0/bin/" "/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin/" "/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin/" "/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin/" "/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin/" "/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin/" "/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin/" "/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin/" "/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin/" "/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin/" "/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin/" "/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/" "/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin/" "/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin/" "/home/dominik/Evolutionary-Biology/Scripts/nix-flakes/" "/home/dominik/Evolutionary-Biology/Scripts/" "/home/dominik/bin/nix-flakes/" "/home/dominik/bin/" "/run/wrappers/bin/" "/home/dominik/.nix-profile/bin/" "/etc/profiles/per-user/dominik/bin/" "/nix/var/nix/profiles/default/bin/" "/run/current-system/sw/bin/" "/nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2/libexec/emacs/27.2/x86_64-pc-linux-gnu/")
Original value was 
("/nix/store/cnxncxyghj3gfpfvng6z4l8k4hfl48wq-ghc-8.10.6-with-packages/bin" "/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin" "/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0/bin" "/nix/store/dlni53myj53kx20pi4yhm7p68lw17b07-gcc-10.3.0/bin" "/nix/store/6z35qvn00xrjvaznv9kfy8xddbbdz4gl-glibc-2.33-47-bin/bin" "/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin" "/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1/bin" "/nix/store/v8imx1nvyz0hgvx9cbcmh6gp4ngw3ffj-binutils-2.35.1/bin" "/nix/store/iz7bgfvjmwdz3vgmzryhfkqwbn8zr2jn-ncurses-6.2/bin" "/nix/store/w07a7k61dw5gnsyxj3kgcq3shr76jax8-bash-interactive-4.4-p23/bin" "/nix/store/xhxll8hx0x9szhlvvd8h1c35glszlj34-cabal-install-3.4.0.0/bin" "/nix/store/gbxdjp9z1bjx1zl6icckw093yv0vn21r-haskell-language-server-1.2.0.0/bin" "/nix/store/mx8v4f0hq8nff5ab7mcgmmbxn5rk6al4-aeson-pretty-0.8.8/bin" "/nix/store/xygkar338ssrwqjcpmmbv1pkkpqc1yfy-ghc-8.10.6/bin" "/nix/store/w16zhm17a73sn3sshqgpxjk3r265vb9l-ghcide-1.4.0.3/bin" "/nix/store/isja3hvzjmmg7278mdsyyn0k4s7k6cf8-constraints-extras-0.3.1.0/bin" "/nix/store/9kz9pwpgnq4miywf5bk97xpn4qqz1h2c-hie-bios-0.7.5/bin" "/nix/store/wfpjw96bjc1kwx5spddwgpi8r4jrbc6b-hiedb-0.4.0.0/bin" "/nix/store/il7l9fjr7r0sq00iy0jr6pcwcb97227p-shake-0.19.5/bin" "/nix/store/9i7z6c6ydhkw1ch37hvpi6fywbfkyrm0-implicit-hie-0.1.2.6/bin" "/nix/store/88kdasbl46rhfnz249dxnh5n9amr27pv-retrie-1.0.0.0/bin" "/nix/store/i7djw6911qk0vkkxv5rsm2zh95arfmjp-brittany-0.13.1.2/bin" "/nix/store/5mpyw1f5jamnvnhsawj147vyvwpw054s-floskell-0.10.5/bin" "/nix/store/aj2q5q38wzlsl60vwcxirlc133p3i8hj-fourmolu-0.3.0.0/bin" "/nix/store/mr0algmndmq73ybhnk3752ylhpnp7918-apply-refact-0.9.3.0/bin" "/nix/store/k9h1adjqqwmq39iik3253cgxdd5drgz8-hlint-3.2.7/bin" "/nix/store/rdjb7sx4clhzjfal0xhb41x1k62nchf0-cpphs-1.20.9.1/bin" "/nix/store/wlh74ffhf19ychrcf65885jsx8xy5f8d-hscolour-1.24.4/bin" "/nix/store/1lbb1bzjqcblb946av3703g76ng18jx1-ormolu-0.1.4.1-bin/bin" "/nix/store/jvx2rcmbcrjpsvz4p8z5zll4gchmhl75-stylish-haskell-0.12.2.0/bin" "/nix/store/h0yyp8i85y3cahd1wyxb0a0izxqz2gxj-stack-2.7.3/bin" "/nix/store/62m5yxq7f9gz4xn3qlvkvkna237vz92k-hpack-0.34.4/bin" "/nix/store/ki59g3c2y2ahpjja9hch3wxgl7gki5f3-mustache-2.3.1/bin" "/nix/store/1wdm2g4mz9is77iihfkbycq3m8c2frrv-open-browser-0.2.1.0/bin" "/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin" "/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin" "/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin" "/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin" "/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin" "/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin" "/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin" "/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin" "/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin" "/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin" "/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin" "/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin" "/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin" "/home/dominik/Evolutionary-Biology/Scripts/nix-flakes" "/home/dominik/Evolutionary-Biology/Scripts" "/home/dominik/bin/nix-flakes" "/home/dominik/bin" "/run/wrappers/bin" "/home/dominik/.nix-profile/bin" "/etc/profiles/per-user/dominik/bin" "/nix/var/nix/profiles/default/bin" "/run/current-system/sw/bin" "/nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2/libexec/emacs/27.2/x86_64-pc-linux-gnu" "/nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2/libexec/emacs/27.2/x86_64-pc-linux-gnu")
Local in buffer README.org; global value is 
("/home/dominik/Evolutionary-Biology/Scripts/nix-flakes" "/home/dominik/Evolutionary-Biology/Scripts" "/home/dominik/bin/nix-flakes" "/home/dominik/bin" "/run/wrappers/bin" "/home/dominik/.nix-profile/bin" "/etc/profiles/per-user/dominik/bin" "/nix/var/nix/profiles/default/bin" "/run/current-system/sw/bin" "/nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2/libexec/emacs/27.2/x86_64-pc-linux-gnu")
#+end_quote

[1] https://github.com/purcell/envrc
[2] https://github.com/purcell/inheritenv/issues/4
[3] https://orgmode.org/list/3d3611c4-17a6-4d55-875b-f566c28d297b@www.fastmail.com/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Org babel source blocks ignore buffer-local variables
  2021-09-04 12:30 Org babel source blocks ignore buffer-local variables Dominik Schrempf
@ 2021-09-04 17:14 ` Berry, Charles via General discussions about Org-mode.
  2021-09-06  8:53   ` Dominik Schrempf
  0 siblings, 1 reply; 4+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2021-09-04 17:14 UTC (permalink / raw)
  To: Dominik Schrempf; +Cc: emacs-orgmode



> On Sep 4, 2021, at 5:30 AM, Dominik Schrempf <dominik.schrempf@gmail.com> wrote:
> 
> Hello,
> 
> I use directory local environments with =envrc= [1], and run into trouble when
> using (Bash) Org Babel source code blocks. The buffer local environment seems to
> be ignored (see the example at the bottom).
> 
> This seems to have been discussed in the course of a GitHub issue of
> =inheritenv= [2], which is pulled in by =envrc=. Also, on this mailing list,
> there was a short discussion [3].
> 
> Do you have any thoughts on this? Is there an easy way to make Org Babel source
> blocks honor buffer local setups?
> 
> Thank you!
> Dominik
> 
> #+name: Scratch
> #+begin_src sh :exports both :results output verbatim
> function path () { echo "$PATH" | tr ':' '\n'; }
> path
> #+end_src
> 
> #+RESULTS: Scratch
> #+begin_example
> /home/dominik/Evolutionary-Biology/Scripts/nix-flakes
> /home/dominik/Evolutionary-Biology/Scripts
> /home/dominik/bin/nix-flakes
> /home/dominik/bin
> /run/wrappers/bin
> /home/dominik/.nix-profile/bin
> /etc/profiles/per-user/dominik/bin
> /nix/var/nix/profiles/default/bin
> /run/current-system/sw/bin
> /nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2/libexec/emacs/27.2/x86_64-pc-linux-gnu
> #+end_example
> 
> The Emacs =exec-path= variable has the following value:
> 
> #+begin_quote
> exec-path is a variable defined in ‘C source code’.
> Its value is
> ("/nix/store/cnxncxyghj3gfpfvng6z4l8k4hfl48wq-ghc-8.10.6-with-packages/bin/" "/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin/" 

[snip]

Indeed, ~exec-path~ and ~(getenv "PATH")~ can differ.

If you want to set PATH for a shell src block, you can do something like:

#+begin_src sh :results output verbatim :var PATH=(mapconcat 'identity exec-path ":")
  echo $PATH
#+end_src

HTH,

Chuck

  

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Org babel source blocks ignore buffer-local variables
  2021-09-04 17:14 ` Berry, Charles via General discussions about Org-mode.
@ 2021-09-06  8:53   ` Dominik Schrempf
  2021-09-06 18:32     ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Schrempf @ 2021-09-06  8:53 UTC (permalink / raw)
  To: Berry, Charles; +Cc: emacs-orgmode

Thank you, this solution works. May I ask about the reasons of such a
distinction?

Dominik

"Berry, Charles" <ccberry@health.ucsd.edu> writes:

>> On Sep 4, 2021, at 5:30 AM, Dominik Schrempf <dominik.schrempf@gmail.com> wrote:
>> 
>> Hello,
>> 
>> I use directory local environments with =envrc= [1], and run into trouble when
>> using (Bash) Org Babel source code blocks. The buffer local environment seems to
>> be ignored (see the example at the bottom).
>> 
>> This seems to have been discussed in the course of a GitHub issue of
>> =inheritenv= [2], which is pulled in by =envrc=. Also, on this mailing list,
>> there was a short discussion [3].
>> 
>> Do you have any thoughts on this? Is there an easy way to make Org Babel source
>> blocks honor buffer local setups?
>> 
>> Thank you!
>> Dominik
>> 
>> #+name: Scratch
>> #+begin_src sh :exports both :results output verbatim
>> function path () { echo "$PATH" | tr ':' '\n'; }
>> path
>> #+end_src
>> 
>> #+RESULTS: Scratch
>> #+begin_example
>> /home/dominik/Evolutionary-Biology/Scripts/nix-flakes
>> /home/dominik/Evolutionary-Biology/Scripts
>> /home/dominik/bin/nix-flakes
>> /home/dominik/bin
>> /run/wrappers/bin
>> /home/dominik/.nix-profile/bin
>> /etc/profiles/per-user/dominik/bin
>> /nix/var/nix/profiles/default/bin
>> /run/current-system/sw/bin
>> /nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2/libexec/emacs/27.2/x86_64-pc-linux-gnu
>> #+end_example
>> 
>> The Emacs =exec-path= variable has the following value:
>> 
>> #+begin_quote
>> exec-path is a variable defined in ‘C source code’.
>> Its value is
>> ("/nix/store/cnxncxyghj3gfpfvng6z4l8k4hfl48wq-ghc-8.10.6-with-packages/bin/" "/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin/" 
>
> [snip]
>
> Indeed, ~exec-path~ and ~(getenv "PATH")~ can differ.
>
> If you want to set PATH for a shell src block, you can do something like:
>
> #+begin_src sh :results output verbatim :var PATH=(mapconcat 'identity exec-path ":")
>   echo $PATH
> #+end_src
>
> HTH,
>
> Chuck
>
>   



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Org babel source blocks ignore buffer-local variables
  2021-09-06  8:53   ` Dominik Schrempf
@ 2021-09-06 18:32     ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 0 replies; 4+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2021-09-06 18:32 UTC (permalink / raw)
  To: Dominik Schrempf; +Cc: emacs-orgmode



> On Sep 6, 2021, at 1:53 AM, Dominik Schrempf <dominik.schrempf@gmail.com> wrote:
> 
> Thank you, this solution works. May I ask about the reasons of such a
> distinction?


[i.e. between exec-path and (getenv "PATH")]

Well, this is how `shell' and `shell-command-on-region' both do it, and they seem to be the underlying engines.  So you might ask elsewhere why it is so.

There are probably a lot of circumstances in which the distinction makes sense in babel shell blocks. 

You would not want to use exec-path if your src block was being executed remotely, for example.

I think different shells can sensibly use different PATH defaults, so that might be another circumstance in which the default to exec-path could trip you up.

HTH,
Chuck




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-06 18:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-04 12:30 Org babel source blocks ignore buffer-local variables Dominik Schrempf
2021-09-04 17:14 ` Berry, Charles via General discussions about Org-mode.
2021-09-06  8:53   ` Dominik Schrempf
2021-09-06 18:32     ` Berry, Charles via General discussions about Org-mode.

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).