#
#
#
#
#
With a bit of Lisp —and a lot of time— we obtain
- a uniform, and practical, syntax for both special blocks and link types
- reusing the Org
src
interface —including arguments for blocks and global header arguments for links
- “write once, generate many”: Write markup in Org and have
it exported to other backends!
See an aesthetically pleasing style online and seek to reproduce it …
Three friends —green:Amin, red:Sacha, and blue:Corwin— were organising a conference
… orange:EmacsConf2020!
Sacha wrote an Org file and wanted some feedback
- top-level remarks visible in the export
… suggest red:replacement text
… this is not possible, green:elegantly, with raw HTML!
- translate in the export
… everyone speaks different languages!
… or suggest a rewrite, without altering the other person’s text
… this is not possible with raw HTML at all!
Sacha …
She gets feedback …
#+latex: {\color{green} \fbox{[Amin:}}
Please change …
#+latex: \fbox{]}
Sacha may write top-level feedback …
Corwin cyan:actually reads an exported result, and is worried at what he sees.
Amin & Sacha agree to read up and make a uniform Org interface that exports to both HTML & PDF
They use Org “special blocks”!
They agree to figure out the necessary magenta:Lisp,
cyan:hooks, blue:advice, and violet:macros needed to form a
special custom block that outputs both HTML and PDF,
green:but
uses Org as interface.
So much work, but it’s worth it!
…!?
Corwin likes to provide blue:terse, right to the point, feedback and thinks blocks are overkill.
The team decides to incorporate an red:Org-link red:type
and —to avoid duplication of code!— they have the link type reuse the core code of the block type.
They have their own interface…!
gray:Need violet:to magenta:learn a red:little blue:about
teal:font, orange:follow cyan:links, purple:export pink:handles.
Eek …!
- doc:defun, for making red:functions to format their blocks!
- doc:advice-add, for advising Emacs utilities to blue:handle their new special blocks
- doc:-let, pattern matching / “destructuring lets”
- extract-arguments, an red:ad-hoc mechanism to cyan:simulate arguments with special blocks
- doc:org-link-set-parameters, to make new link types
green:Of green:course to actually write the formatting function they need doc:loop, doc:s-replace, doc:mapcar, doc:or, doc:s-match, and much more!
Such a pain!
⇒ It’s probably not worth it! |
“Just do enough to make it work!” |
“We’re in a rush!” |
(defblock feedback (who) (color "red")
"Top level (HTML & LaTeX) constructive feedback."
(format (if (equal backend 'html)
"<strong style=\"color: %s;\">⟦%s: %s⟧</strong>"
"{\\color{%s}\\bfseries %s: %s}")
color who contents))
Huh?
There are 3 main parts …
(defblock feedback (who) (color "red") (ref:here1)
"Top level (HTML & LaTeX) constructive feedback."
(format (if (equal backend 'html)
"<strong style=\"color: %s;\">⟦%s: %s⟧</strong>"
"{\\color{%s}\\bfseries %s: %s}")
color who contents))
(defblock feedback (who) (color "red")
"Top level (HTML & LaTeX) constructive feedback." (ref:here2)
(format (if (equal backend 'html)
"<strong style=\"color: %s;\">⟦%s: %s⟧</strong>"
"{\\color{%s}\\bfseries %s: %s}")
color who contents))
(defblock feedback (who) (color "red")
"Top level (HTML & LaTeX) constructive feedback."
(format (if (equal backend 'html) (ref:here3)
"<strong style=\"color: %s;\">⟦%s: %s⟧</strong>"
"{\\color{%s}\\bfseries %s: %s}")
color who contents))
(defblock feedback (who) (color "red")
"Top level (HTML & LaTeX) constructive feedback."
(format (if (equal backend 'html) (ref:anaB)
"<strong style=\"color: %s;\">⟦%s: %s⟧</strong>"
"{\\color{%s}\\bfseries %s: %s}")
color who contents)) (ref:anaC)
Using a few lines of Lisp …
- write text in parallel columns
… to save on vertical whitespace
- hide away technical details for the interested reader only
- enclose text in a pretty box
- Educational material blocks: spolier, solution, and org-demo
Finally, blocks compose: They’re building blocks for new and better ideas!
More details and examples at
https://alhassy.github.io/org-special-block-extras |
Thanks for listening in!
- The olive:org-special-block-extras Library:
https://alhassy.github.io/org-special-block-extras
… has examples, tutorial, and is a literate program! (•̀ᴗ•́)و
- A 5-page PDF covering ELisp fundamentals:
- These slides:
https://alhassy.github.io/org-special-block-extras/emacs-conf-2020