this-month-in-org/2021-05-31-async.org.html

334 lines
20 KiB
HTML
Raw Normal View History

2024-01-09 18:20:48 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>2021-05-31-async.org.html</title>
<style>
body { background: #fafafa; color: #2a2a2a; }
pre {
font-size: 1rem;
max-width: min(100rem, 100%);
width: max-content;
white-space: pre-wrap;
margin: auto; }
.ef-D {
color: #2a2a2a;
background-color: #fafafa;
font-weight: 400; }
.ef-k {
color: #3b6ea8; }
.ef-d {
color: #b6b6b6; }
.ef-t {
color: #9a7500; }
.ef-s {
color: #4f894c; }
.ef-w {
color: #9a7500; }
.ef-b {
color: #29838d; }
.ef-ct {
color: #b1b1b1; }
.ef-c {
color: #97365b; }
.ef-pp {
color: #3b6ea8;
font-weight: 700; }
.ef-nc {
color: #3b6ea8;
font-weight: 700; }
.ef-v {
color: #cb9aad; }
.ef-f {
color: #29838d; }
.ef-cd {
color: #b1b1b1; }
.ef-rc {
color: #3b6ea8;
font-weight: 700; }
.ef-rb {
color: #3b6ea8;
font-weight: 700; }
.ef-ob {
}
.ef-hn {
color: #97365b;
font-weight: 700; }
.ef-hq {
color: #3b6ea8; }
.ef-hs {
color: #9a7500; }
.ef-rdi {
color: #3b6ea8; }
.ef-rdii {
color: #97365b; }
.ef-rdiii {
color: #4f894c; }
.ef-rdiv {
color: #842879; }
.ef-rdv {
color: #29838d; }
.ef-rdvi {
color: #3b6ea8; }
.ef-rdvii {
color: #97365b; }
.ef-rdiix {
color: #4f894c; }
.ef-rdix {
color: #842879; }
</style>
</head>
<body>
<pre>
<span style="color: #9e9e9e;">#+title:</span> <span style="color: #29838d; font-weight: 700;">May 2021
</span><span style="color: #9e9e9e;">#+subtitle:</span> <span style="color: #29838d;">Asynchronous code execution
</span><span style="color: #9e9e9e;">#+author:</span> <span style="color: #29838d;">TEC
</span><span style="color: #9e9e9e;">#+date:</span> <span style="color: #29838d;">2021-05-31
</span>
<span style="color: #3b6ea8; font-weight: 700;">* Async Babel sessions have landed</span>
Jack Kamm has made a fantastic contribution to Org: <span style="color: #4f894c;">=ob-comint.el=</span> now supports
asynchronous output from source blocks <span style="text-decoration: italic;">/with full support for sessions/</span> 🎉.
If you haven't used sessions before, you're in for a treat! By simply assigning
a named session to a source code block, e.g. <span style="color: #4f894c;">=:session foo=</span>, the same process will
be reused for any other code blocks that specify the <span style="color: #4f894c;">=foo=</span> session. To do this for
a certain language across the entire document, you can set the header argument
property, i.e.
<span style="color: #b1b1b1;">#+begin_src org
</span><span class="ef-ob">,#+property: header-args:lang :session foo
</span><span style="color: #b1b1b1;">#+end_src
</span>
Along with the asynchronous process communication in <span style="color: #4f894c;">=ob-comint.el=</span>, we have an
implementation for <span style="font-weight: 700;">*Python*</span>, and we should see support for <span style="font-weight: 700;">*R*</span> and <span style="font-weight: 700;">*Ruby*</span> in the
not-too-distant future 😍.
To use this, just add the <span style="color: #4f894c;">=:async=</span> parameter to a python block. Instead of Emacs
freezing until it completes execution, you'll see a placeholder inserted which is
replaced by the result when it is ready.
<span style="color: #b1b1b1;">#+begin_export html
</span><span class="ef-ob">&lt;</span><span style="color: #29838d;">figure</span><span class="ef-ob">&gt;
&lt;</span><span style="color: #29838d;">video</span> <span style="color: #cb9aad;">width</span><span class="ef-ob">=</span><span style="color: #4f894c;">"100%"</span> <span style="color: #cb9aad;">height</span><span class="ef-ob">=</span><span style="color: #4f894c;">"auto"</span><span class="ef-ob"> autoplay loop muted </span><span style="color: #cb9aad;">class</span><span class="ef-ob">=</span><span style="color: #4f894c;">"doom-one"</span><span class="ef-ob">&gt;
&lt;</span><span style="color: #29838d;">source</span> <span style="color: #cb9aad;">src</span><span class="ef-ob">=</span><span style="color: #4f894c;">"figures/org-async-python-demo.mp4"</span> <span style="color: #cb9aad;">type</span><span class="ef-ob">=</span><span style="color: #4f894c;">"video/mp4"</span><span class="ef-ob"> /&gt;
&lt;/</span><span style="color: #29838d;">video</span><span class="ef-ob">&gt;
&lt;</span><span style="color: #29838d;">figcaption</span><span class="ef-ob">&gt;
&lt;</span><span style="color: #29838d;">span</span> <span style="color: #cb9aad;">class</span><span class="ef-ob">=</span><span style="color: #4f894c;">"figure-number"</span><span class="ef-ob">&gt;Figure 0:&lt;/</span><span style="color: #29838d;">span</span><span class="ef-ob">&gt;
A demonstration of the new asyncronous Python execution capabilities.
&lt;/</span><span style="color: #29838d;">figcaption</span><span class="ef-ob">&gt;
&lt;/</span><span style="color: #29838d;">figure</span><span class="ef-ob">&gt;
</span><span style="color: #b1b1b1;">#+end_export
</span>
<span style="color: #3b6ea8; font-weight: 700;">[[https://github.com/nnicandro/emacs-jupyter][emacs-jupyter]]</span> allowed for asynchronous code execution (with sessions), but it's
great to have a solution that doesn't require Jupyter kernels, and is part of
Org.
<span style="color: #3b6ea8; font-weight: 700;">* Font lock for inline export snippets</span>
Now, this isn't necessarily a significant change, but I don't think many people
know about this feature so I'll take the opportunity to go over it 🙂.
If you want to include a snippet of HTML/LaTeX etc. when exporting to that
format, you can use a <span style="color: #4f894c;">=#+begin_export html=</span> block which simply includes the
enclosed content verbatim. This doesn't really work for small inline snippets
though --- but never fear, Org has <span style="text-decoration: italic;">/inline/</span> export snippets which simply follow the
form <span style="color: #9e9e9e;">src_</span><span style="color: #b6b6b6;">org</span><span style="color: #9e9e9e;">{</span><span style="color: #b1b1b1;">@@</span><span style="color: #b6b6b6; font-weight: 400;">format:</span><span class="ef-ob">content</span><span style="color: #b1b1b1;">@@</span><span style="color: #9e9e9e;">}</span>. For example:
<span style="color: #b1b1b1;">#+begin_src org
</span><span class="ef-ob">I love using Org to export to </span><span style="color: #b1b1b1;">@@</span><span style="color: #b6b6b6; font-weight: 400;">html:</span><span class="ef-ob">&lt;abbr title="Hyper Text Markup Language"&gt;HTML&lt;/abbr&gt;</span><span style="color: #b1b1b1;">@@</span> <span style="color: #b1b1b1;">@@</span><span style="color: #b6b6b6; font-weight: 400;">latex:</span><span class="ef-ob">\LaTeX{}</span><span style="color: #b1b1b1;">@@</span><span class="ef-ob"> documents.
</span><span style="color: #b1b1b1;">#+end_src
</span>which will export to HTML as,
<span style="color: #b1b1b1;">#+begin_src html
</span><span class="ef-ob">I love using Org to export to &lt;</span><span style="color: #29838d;">abbr</span> <span style="color: #cb9aad;">title</span><span class="ef-ob">=</span><span style="color: #4f894c;">"Hyper Text Markup Language"</span><span class="ef-ob">&gt;HTML&lt;/</span><span style="color: #29838d;">abbr</span><span class="ef-ob">&gt; documents.
</span><span style="color: #b1b1b1;">#+end_src
</span>and then in LaTeX will be,
<span style="color: #b1b1b1;">#+begin_src LaTeX
</span><span class="ef-ob">I love using Org to export to </span><span style="color: #3b6ea8;">\LaTeX</span><span class="ef-ob">{} documents.
</span><span style="color: #b1b1b1;">#+end_src
</span>isn't that neat!
Now you'll find the <span style="color: #4f894c;">=@@=</span> parts using the comment face and the <span style="color: #4f894c;">=format:=</span> bit using the
Org tag's face. It's a small change, but it makes it easier to see what's going on.
No mode-specific syntax highlighting yet, but that may come in the future 😉.
<span style="color: #3b6ea8; font-weight: 700;">* </span><span style="color: #4f894c; font-weight: 700;">=#+plot=</span><span style="color: #3b6ea8; font-weight: 700;"> your </span><span style="color: #4f894c; font-weight: 700;">=#+results=</span>
Org-plot has been getting some more love as of late (see <span style="color: #3b6ea8; font-weight: 700;">[[file:2021-04-30-export-plot.org][last month's post]]</span>), and
that hasn't stopped yet. This month there's been a fairly minor change that I'm
quite a fan of. If you have a source block that produces a table of <span style="color: #4f894c;">=#+results=</span>, you
can now put a <span style="color: #4f894c;">=#+plot=</span> statement immediately above to get a visualisation of those
results!
<span style="color: #b1b1b1;">#+begin_src org
</span><span class="ef-ob">,#+begin_src python
</span><span style="color: #b1b1b1;"># pretend this is some profound source of information</span><span class="ef-ob">
return [[i, i^3 - 4*i^2 - 2*i] for i in range(5)]
,#+end_src
,#+plot: ind:1
,#+RESULTS:
</span><span style="color: #842879;">| 0 | 1 |</span>
<span style="color: #842879;">| 1 | -2 |</span>
<span style="color: #842879;">| 2 | 7 |</span>
<span style="color: #842879;">| 3 | 8 |</span>
<span style="color: #842879;">| 4 | 13 |</span>
<span style="color: #b1b1b1;">#+end_src
</span>
As usual, this relies on <span style="color: #4f894c;">=gnuplot=</span> being present. You can read more
about it in the <span style="color: #3b6ea8; font-weight: 700;">[[https://orgmode.org/manual/Org-Plot.html][manual]]</span>.
<span style="color: #3b6ea8; font-weight: 700;">* Fancier LaTeX verses</span>
With the use of <span style="color: #4f894c;">=verse.sty=</span> you can now export fancier verses from Org, as verse
blocks now support four new attributes:
+ <span style="color: #4f894c;">=:lines=</span> for the numbering interval.
+ <span style="color: #4f894c;">=:center=</span> which can be set to <span style="color: #4f894c;">=t=</span> and works as long as,
- <span style="color: #4f894c;">=:versewidth=</span>, the longest line in the verse as a text string is set.
+ You can also easily add arbitrary LaTeX code to be included with <span style="color: #4f894c;">=:latexcode=</span>.
<span style="color: #b1b1b1;">#+begin_src org
</span><span class="ef-ob">,#+latex_header: \usepackage{verse}
,#+latex: \poemtitle{A Dream Within a Dream}
,#+attr_latex: :lines 3 :center t
,#+attr_latex: :versewidth Through my fingers to the deep,
,#+begin_verse
Take this kiss upon the brow!
And, in parting from you now,
Thus much let me avow —
You are not wrong, who deem
That my days have been a dream;
Yet if hope has flown away
In a night, or in a day,
In a vision, or in none,
Is it therefore the less </span><span style="text-decoration: italic;">/gone?/</span>
<span style="text-decoration: italic;">/All/</span><span class="ef-ob"> that we see or seem
Is but a dream within a dream.
I stand amid the roar
Of a surf-tormented shore,
And I hold within my hand
Grains of the golden sand —
How few! yet how they creep
Through my fingers to the deep,
While I weep — while I weep!
O God! Can I not grasp
Them with a tighter clasp?
O God! can I not save
</span><span style="text-decoration: italic;">/One/</span><span class="ef-ob"> from the pitiless wave?
Is </span><span style="text-decoration: italic;">/all/</span><span class="ef-ob"> that we see or seem
But a dream within a dream?
,#+end_verse
</span><span style="color: #b1b1b1;">#+end_src
</span>
<span style="color: #b6b6b6;">#+caption:</span> <span class="ef-ob">A short Poe-em</span>
<span style="color: #b6b6b6;">#+attr_html: :class invertible</span>
<span style="color: #3b6ea8; font-weight: 700;">[[file:figures/org-verses-example-poem-dream-within-dream.png]]</span>
<span style="color: #3b6ea8; font-weight: 700;">* Easy zero-width spaces with Org</span>
Occasionally you may run into annoyances when you wish to have two different Org
elements right next to each other (no space) --- for example, <span style="font-weight: 700;">*emph*</span>asising part of
a word or putting a currency symbol immediately before an inline source block.
The best solution to this in Org is zero-width spaces. As such, I've found it
rather nice adding insertion of a zero-width space to the <span style="color: #ac4426;">~org-mode-map~</span> in my
config. Perhaps some of you might find this solution useful too 🙂.
<span style="color: #b1b1b1;">#+begin_src emacs-lisp
</span><span class="ef-ob">(define-key org-mode-map (kbd </span><span style="color: #4f894c;">"M-SPC M-SPC"</span><span class="ef-ob">)
(</span><span style="color: #3b6ea8;">lambda</span><span class="ef-ob"> () (</span><span style="color: #3b6ea8;">interactive</span><span class="ef-ob">) (insert </span><span style="color: #4f894c;">"\u200b"</span><span class="ef-ob">)))
</span><span style="color: #b1b1b1;">#+end_src
</span>
Should you want to keep zero-width spaces out of exports, that's easy enough to
accomplish with an <span style="color: #3b6ea8; font-weight: 700;">[[https://orgmode.org/manual/Advanced-Export-Configuration.html][export filter]]</span>.
<span style="color: #b1b1b1;">#+begin_src emacs-lisp
</span><span class="ef-ob">(</span><span style="color: #3b6ea8;">defun</span> <span style="color: #29838d;">+org-export-remove-zero-width-space</span><span class="ef-ob"> (text _backend _info)
</span><span style="color: #b6b6b6;">"Remove zero width spaces from TEXT."</span><span class="ef-ob">
(</span><span style="color: #3b6ea8;">unless</span><span class="ef-ob"> (org-export-derived-backend-p 'org)
(replace-regexp-in-string </span><span style="color: #4f894c;">"\u200b"</span> <span style="color: #4f894c;">""</span><span class="ef-ob"> text)))
(add-to-list 'org-export-filter-final-output-functions #'+org-export-remove-zero-width-space t)
</span><span style="color: #b1b1b1;">#+end_src
</span>
<span style="color: #3b6ea8; font-weight: 700;">* Org's repos have moved</span>
+ <span style="color: #4f894c;">=contrib/=</span> is now at <span style="color: #3b6ea8; font-weight: 700;">https://git.sr.ht/~bzg/org-contrib</span> for Org 9.5, and it will
be available on Non-GNU ELPA.
+ Worg is now at <span style="color: #3b6ea8; font-weight: 700;">https://git.sr.ht/~bzg/worg</span>
+ Org itself is moving to Savannah
<span style="color: #3b6ea8; font-weight: 700;">* Other improvements</span>
+ Add support for <span style="color: #4f894c;">=HHhMM=</span> date formats (e.g. <span style="color: #4f894c;">=13h20=</span>) _Gustavo Barros_
+ Make tangling faster <span style="text-decoration: italic;">/and/</span> more robust _Sébastien Miquel_
+ Allow importing tables from files that <span style="text-decoration: italic;">/don't/</span> end in <span style="color: #4f894c;">=.txt=</span>, <span style="color: #4f894c;">=.tsv=</span>, or <span style="color: #4f894c;">=.csv=</span>
_Utkarsh Singh_
+ Add an SVG-specific post-export <span style="color: #4f894c;">=ob-plantuml=</span> step:
<span style="color: #ac4426;">~org-babel-plantuml-svg-text-to-path~</span> for running Inkscape text-to-path
replacement _Nick Daly_
+ Refactor JavaScript in <span style="color: #4f894c;">=ox-html=</span> _Anthony Carrico_
+ Set <span style="color: #ac4426;">~org-html-head-include-scripts~</span> to <span style="color: #ac4426;">~nil~</span> by default (was <span style="color: #ac4426;">~t~</span>) _Bastien Guerry_
+ Remove LaTeX-environment type <span style="color: #4f894c;">=#+results=</span> _TEC_
+ New capture templates parameter, <span style="color: #4f894c;">=:refile-targets=</span> _Richard Garner_
+ Merge <span style="color: #ac4426;">~org-speed-commands-default~</span> and <span style="color: #ac4426;">~org-speed-commands-user~</span> into a new
variable, <span style="color: #ac4426;">~org-speed-commands~</span> _Bastien Guerry_
+ URL recognition regex now handles up to two levels of nested brackets, and is
tested _Ihor Radchenko_
+ Cache parent heading positions for faster movement up buffers. Significantly
improves Org queries involving inheritance (~15-50x improvement) _Ihor Radchenko_
+ New command <span style="color: #ac4426;">~org-refile-reverse~</span> bound to <span style="color: #4f894c;">=C-c C-M-w=</span> _Adam Spiers_
+ Allow inline tasks to be dragged up/down _Bastien Guerry_
+ LaTeX export, allow arbitrary <span style="color: #4f894c;">=:float=</span> values _Thomas S. Dye_
+ Org attach git, new option <span style="color: #ac4426;">~org-attach-git-dir~</span> to use the attachment dir as a
git repository _Juan Manuel Macías_
+ Use a write-back buffer in Org src _Sébastien Miquel_
+ Add the <span style="color: #4f894c;">=:environment=</span> and <span style="color: #4f894c;">=:options=</span> LaTeX attributes to Quote blocks _Juan Manuel Macias_
+ Surround LaTeX <span style="color: #4f894c;">=:options=</span> attribute with curly braces when it contains square
braces _Markus Huber_
+ Recognise the specific contributions of Kyle Meyer, Ihor Radchenko, and TEC in
the manual _Bastien Guerry_
+ Improve test coverage _Ihor Radchenko, Kévin Le Gouguec_
+ A bikeshed of new maintainers
- New maintainer for <span style="color: #4f894c;">=ox-html=</span> --- TEC
- New <span style="color: #4f894c;">=ob-ledger=</span> maintainer --- Eric S Fraga
- New <span style="color: #4f894c;">=ob-awk=</span> maintainer --- Tyler Smith
- New <span style="color: #4f894c;">=ob-calc=</span> maintainer --- Tom Gillespie
- New <span style="color: #4f894c;">=ob-asymptote=</span> and <span style="color: #4f894c;">=ob-coq=</span> maintainer --- Luc Pellissier
+ General code cleanup _Bastien Guerry_
+ Documentation improvements _Bastien Guerry, Eric S Fraga, Samim Pezeshki,
Nicolar Goaziou_
<span style="color: #3b6ea8; font-weight: 700;">* Bugfixes</span>
+ Make <span style="color: #4f894c;">=ob-gnuplot=</span> work on remote systems _Ihor Radchenko_
+ Stop <span style="color: #4f894c;">=M-x org-toggle-link-display=</span> from affecting emphasis markers _Bastien Guerry_
+ Inserting a heading before a headline _Bastien Guerry_
+ Perform <span style="color: #ac4426;">~org-entry-put~</span> in a read-only buffer _Ihor Radchenko_
+ Emacs 24 compatibility for <span style="color: #4f894c;">=ob-C=</span> and <span style="color: #ac4426;">~org-agenda-show-new-time~</span> _Kyle Meyer_
+ Maintain Org's keybindings when <span style="color: #ac4426;">~visual-line-mode~</span> active _Bastien Guerry_
+ Keep track of start of region beginning in <span style="color: #ac4426;">~org-table-wrap-region~</span> _Bastien Guerry_
+ Ensure correct visibility when unfolding subtree _Bastien Guerry_
+ Corner case in <span style="color: #ac4426;">~org--backwards-paragaph-once~</span> _Bastien Guerry_
+ Some byte compiler silencing _Kyle Meyer_
+ Make tags filtering case-sensitive _Bastien Guerry_
+ <span style="color: #4f894c;">=C-c C-c=</span> on a <span style="color: #4f894c;">=#+plot=</span> line can no longer cause an error _Bastien Guerry_
+ Ensure consistent position-translation in <span style="color: #4f894c;">=org-src=</span> by using point for position
instead of column _TEC_
+ Prevent <span style="color: #4f894c;">=ob-sql=</span> from getting stuck on an error _Ivan Sokolov_
+ Make <span style="color: #4f894c;">=org-columns=</span> respect <span style="color: #ac4426;">~global-visual-line-mode~</span>, and simplify tag scanning
_Nick Savage_
+ Don't fontify <span style="color: #4f894c;">=::=</span> in headlines as description item _Ihor Radchenko_
+ Handle a few corner-cases in <span style="color: #4f894c;">=ob-R=</span> _Jeremie Juste_
+ Many fixes to <span style="color: #ac4426;">~org-indent-line~</span> _Bastien Guerry_
+ Make headline numbering consistent with TOC _Mingkai Dong_
+ Allow read-only tangling again, and ensure the correct filename is used _Sébastien Miquel_
+ Fix edge case when converting durations to minutes _Nicolas Goaziou_
+ Make org-refile work in non-file-visiting buffers _Bastien Guerry_
+ Be more rigorous in <span style="color: #ac4426;">~org-sort-remove-invisible~</span> _Nicolas Goaziou_
+ Don't update checkbox stats when heading has <span style="color: #4f894c;">=todo=</span> <span style="color: #4f894c;">=COOKIE_DATA=</span> _Bastien Guerry_
+ Don't recognise a lone <span style="color: #4f894c;">=:END:=</span> to be forming a drawer _Nicolas Goaziou_
+ Allow new footnotes in empty table cells _Nicolas Goaziou_
</pre>
<body>
</html>