I often want to send Javascript from Emacs to the web browser. It's handy for testing code snippets or working with data on pages that require Javascript or authentication. I could start Google Chrome or Mozilla Firefox with their remote debugging protocols, copy the websocket URLs, and talk to the browser through something like Puppeteer, but it's so much easier to use the Spookfox extension for Mozilla to execute code in the active tab.
spookfox-js-injection-eval-in-active-tab lets you evaluate Javascript and get the results back in Emacs Lisp.
I wanted to be able to execute code even more
easily. This code lets me add a :spookfox t
parameter to Org Babel Javascript blocks so that I
can run the block in my Firefox active tab.
For example, if I have (spookfox-init) set up, Spookfox connected, and https://planet.emacslife.com in my active tab, I can use it with the following code:
I usually edit Javascript files with js2-mode, so I can use my-js-spookfox-minor-mode in addition to that.
I can turn the minor mode on automatically for :spookfox t source blocks. There's no org-babel-edit-prep:js yet, I think, so we need to define it instead of advising it.
Let's try it out by sending the last line repeatedly:
I used to do this kind of interaction with Skewer, which also has some extra stuff for evaluating CSS and HTML. Skewer hasn't been updated in a while, but maybe I should also check that out again to see if I can get it working.
Anyway, now it's just a little bit easier to tinker with Javascript!
Is it the Emacs lifecycle that you tweak your
config for few months and then you live off of fat
of the land for >4 years? My Emacs config is a
Org-tangle spaghetti that I touch only if I want
to set some more sane config variable.
I realized that this isn't quite how I consider
things. I'm lucky in that when it comes to
computer things, I get to choose most of the
things I spend my time on. My consulting clients
have very long wishlists that I pick from based on
interests and priority, and I play with Emacs for
fun.
Because I enjoy tinkering around with Emacs, I
often build a little Emacs hacking into my tasks.
15 or 20 minutes of exploring an idea can make
it even more fun to do the actual task it's
supposed to help with because then I want to test
it out. Then after the task is done, I get to
write about it. It's like making a little task
sandwich with really nice bread. This is also a
little related to sharpening the saw, which is pretty fun in Emacs. (Vim people
do it too!)
These little changes add up over time, making
things even more enjoyable. It's a little like the
way desire paths show where people actually walk
between buildings and give a sense of how much
they are used, or how rivers smooth down the edges
of stones. The easier I make something, the more
likely I am to do it, and the more I'll get to
enjoy the results of my code. It's a little like
the Igors described in this essay.
When I think about something I might tweak about
my Emacs configuration, I usually consider the
following:
I like looking for ways to reduce manual work or looking-up.
I tend to have a hard time with tedious, repetitive tasks.
I also keep an eye out for things I've been meaning to learn.
2. What's the smallest step I can take? What can I fit in 15-30 minutes?
Small steps make it easy to squeeze in things here
and there. I know my brain's going to suggest half
a dozen things along the way, so it helps to start
as small as possible and capture most of the other
things in my inbox for later. That way, I can get
to experience the benefits right away without
feeling lost.
Another advantage of picking really small tasks
and using Org Mode to capture the rest of the
ideas is that I can try to avoid the Ovsiankina
effect.1 I spend most of my
day taking care of our 7-year-old, so I squeeze in
my focused-time tasks early in the morning before
she wakes up. Sometimes I have little
opportunities to work on things throughout the
day, like when she wants to read a book or watch a
video. She might do that for 15-30 minutes before
wanting to connect again. If I pick the
wrong-sized task or I don't dump enough rough
notes into my inbox so that I can get the open
loops out of my head and trust that I can pick
things up again, the unfinished part pulls on my
brain and makes it harder to enjoy time with her.
Then I get tempted to let her binge-watch
Minecraft or Rubik's cube videos2 so that I can
finish a thought, which doesn't quite feel like
good parenting.
Lastly, I don't usually understand enough about my
needs to build something complex from the start.
Trying things out helps me discover more about
what's possible and what I want.
3. What's nearby?
Thanks to Emacs's amazing community, there are
usually relevant functions or packages that I can
borrow code from. I mostly have a sense of things
from the blog posts and forum threads that cross
my radar because of Emacs News, and I should
probably get used to skimming the descriptions in
the "New packages" list because that can help me
find even more things.
When coming up with possible approaches, I also
sometimes think about other related ideas I've had
before. Filing those ideas into the appropriate
subtrees in my Org files sometimes helps me come
across them again. If I can take a small step that
also gets me closer to one of those ideas, that's
handy.
I also like to think about next steps and
possibilities. For example, even if I spend an
hour or two learning more about data visualization
with Org Mode and plotting, that's something I
can use for other things someday. This works
pretty well with keeping things small, too, since
small parts can be combined in surprisingly
interesting ways.
Let me try to trace through a web of related
features so I can give you a sense of how this all
works in teeny tiny steps.
If you view this on my blog with Javascript enabled, the SVG should stick to the top of the browser window and get highlighted as you go through the different sections.
defun: I often wanted to write about a
specific function, so I wrote some code to find
the function definition and copy it into my
export post hidden inside a details tag with
the first line of the docstring as the summary.
2023-01-02
my-include:...?from-regexp=...&to-regexp...:
Sometimes I wanted to write about longer pieces
of code. I wanted to include code without
repeating myself. The regular #+INCLUDE can
handle line numbers or headings, but neither of
them worked for the Elisp files I referred to
since the line numbers kept changing as I edited
the code above it and it wasn't an Org Mode
file. I made my own custom link so I could
specify a start and end regexp. 2023-01-08
my_details: I wanted to put the code in a
details element so that it could be
collapsible. I made an org-special-blocks
template for it. special-blocks
:summary: For Org source blocks, I wanted to
be able to do that kind of collapsible block by
just adding a :summary attribute. 2023-01-27
defun-open: I wanted to sometimes be able to
keep the function definition expanded. 2023-09-12
emacsconf-el: Since I was writing about a lot
of EmacsConf functions in preparation for my
presentation, I wanted a quick way to link to
the files in the web-based repository. 2023-09-12
defvar: Made sense to include variable definitions too.
web links: The emacsconf-el links were so
useful, I wanted to be able to use that type of
link for other projects as well. 2024-01-07
Embark: I
wanted to be able to copy the final URL from a
custom link at point, so I used Embark. 2024-01
QR code: I started livestreaming again, so I
wanted a quick way for viewers to get the URL of
something without waiting for stream notes. 2024-01-10
:comments both: While scanning Reddit to find links for Emacs News, I learned about :comments both and how that includes references to the Babel file that tangled the code. 2024-01-07
context: Now that it was easy to link to the web version of an Emacs Lisp file, I thought it might be fun to be able to automatically include a context link by passing link=1. I also wanted to be able to navigate to the Org source code for a tangled function. 2024-01-11
my-include:...?name=...: I wanted to be able to refer to Org Babel source blocks by name.
In the course of writing this blog post, I learned
how to use URLs in Graphviz, learned how to
include inline HTML for export with
@@html:...@@, used position: sticky, figured
out how to highlight the SVG using JS, used CSS to
make a note that should only show up in RSS feeds,
and submitted a pull request for meme.el that was
merged. And now I want to figure out sidenotes or
at least footnotes that don't assume they're the
only footnotes on the page… This is just how my
brain likes to do things. (Oooh, shiny!)
4. What kinds of notes can I leave for myself or others?
I might take years before revisiting the same
topic, so good notes can pay off a lot. Also, when
I share what I've been working on, sometimes
people e-mail me or comment suggesting other
things that are nearby, which is a lot of fun. The
ideas I come up with are probably too weird to
exactly line up with other people's interests, but
who knows, maybe they're close enough to what
other people work on that they can save people
time or spark more ideas.
Inspired by
Mats Lidell's EmacsConf 2023 talk on writing test
cases, I've been working on writing occasional
tests, too, especially when I'm writing a small,
function to calculate or format something. That's a good way of
sketching out how I want a function to behave so that I can see examples of it when I revisit the code. Tests also mean that if I change things, I don't have to worry too much about breaking important behaviours.
Ideas for next steps
How can I get even better at this?
Popping the stack (untangling interruptions and
ideas): When I let myself get distracted by a
cool sub-idea, I sometimes have a hard time
backing up. I can get back into the habit of
clocking time and practise using my org-capture
template for interrupting task so that I can use
C-u with C-c j (my binding for
org-clock-goto) to jump to a recently-clocked
task.
Braindumps can help me use non-computer time to
flesh out notes for things I'm working on or
ideas for next steps.
If I skim the descriptions of new packages in Emacs News
(maybe even the READMEs instead of just the
one-liners), I'll probably retain a brief sense
of what's out there and what things are called.
Vector search across package descriptions
and function docstrings could be an even more
powerful way to discover things that are close
to something I want to do.
Using elisp-demos to add more examples to
functions can help me look up things I
frequently use but don't remember.
Figuring out more modern IDE features like
refactoring support, on-the-fly error checking,
and code navigation could help me code faster.
So that's how I tinker with Emacs for fun: start
with something that mostly works, keep an eye out
for opportunities to make things better, use
tinkering as a way to make doing things more fun,
look for things that are nearby, and
I used to think this was the Zeigarnik
effect, but it turns out the Zeigarnik effect is
about remembering incomplete tasks versus
completed tasks, while the Ovsiankina effect is
more about intrusive thoughts and wanting to get
back to that incomplete task.
I have a tiny corporation for my consulting. I do
all of my own paperwork. I have lots of notes in
Org Mode for infrequent tasks like the tax-related
paperwork I do once a year. My notes include
checklists, links, and Org Babel blocks for
calculations. I often need to copy standard text
(ex: the name of the company) or parts of the
output of my Org Babel blocks (ex: tax collected)
so that I can fill in web forms on the Canada
Revenue Agency website.
This little snippet makes it easy to copy text for
pasting. It defines a custom Org link that starts
with copy:. When I follow the link by clicking
on it or using C-c C-o (org-open-at-point), it
copies the text to the kill ring (which is what
Emacs calls the clipboard) so that I can paste it
anywhere. For example, [[copy:Hello world]]
becomes a link to copy "Hello world". Copying
means never having to worry about typos or
accidentally selecting only part of the text.
I can use these links as part of my checklist so
that I can quickly fill in things like my business
name and other details. I can put sensitive
information like my social insurance number in a
GPG-encrypted file. (Just set up your GPG keys and
end a filename with .gpg, and Emacs will take
care of transparently encrypting and decrypting
the file.)
I can also export those links as part of my Org
Babel output. For example, the following code
calculates the numbers I need to fill in a T5 form
for the other-than-eligible dividends that I issue
myself according to the T5 instructions from the CRA.
For this livestream, I experimented with scheduling it for
8:00 AM EST instead of just starting it whenever I could
squeeze in the time.1 People dropped by! And
asked questions! And suggested interesting things! Wow. This
could be fun.
I wrote a bunch of blog posts throughout the week and added
lots of little videos to them. It was easy to walk through
my recent posts and demonstrate things without worrying
about (a) accidentally leaking personal information or (b)
flubbing things on camera, since apparently my multitasking
abilities are on the way down.2 It felt good to go
through them and add some more commentary and highlights
while knowing that all the details are there in case people
want to do a deeper dive.
I roughly edited the transcript from Deepgram and I uploaded
it to YouTube, fixing some bugs in my Deepgram VTT
conversion along the way. I think I like having proper
transcripts even for ephemeral stuff like this, since it
costs roughly USD 0.21 for the 43-minute video and I can
probably figure out how to make editing even faster..
New projects are easier to keep working on when they have
immediate personal benefits. It's easy for me to keep doing
Emacs News every week because I have so much fun learning
about the cool things people are doing with Emacs. I think
it'll be easy for me to keep doing Yay Emacs livestreams
because not only do I get to capture some workflows and
ideas in videos, but other people might even tell me about
interesting things that could save me time or open up new
possibilities. Also, it's worth building up things I love.
I'm going to try scheduling another stream for next Sunday
(Jan 21) at 7:30 AM EST. Maybe I can experiment with
sharing my screen with the Surface Book or the W530 and then
using that computer to stream. We'll see what that's like!
Thanks to the unpredictability of life with
a kiddo, scheduling things has been one of my life goals for
a while! <laugh> When I created the event, the kiddo was
still in her winter-break habit of sleeping in until 10 or
11, so I figured that I had a little time before I needed to
call in for her virtual school at 8:45 AM. Of course, that
week she decided to start setting her alarm for 7:59 AM so
that she could wake up early and have watching time, and she
actually started waking up around that time. So for Friday,
I woke up earlier (well, the cat woke got me up even
earlier) and packed a little breakfast she could have in the
living room (since my computer's on a kitchen cabinet)…
and that was the one day she snoozed her alarm clock and
sleep in. I've scheduled the next stream for 7:30 AM… and
she has announced that she wants to set her alarm for
7:30ish. Hmm.
I notice that it can be a little challenging for me
to talk and do things at the same time. This is particularly
obvious when I'm cubing (brain hiccup at the last step,
gotta solve the whole Rubik's cube all over again). It's
also why I prefer to record the audio for my presentations
separately instead of winging it. =) It could be verbal
interference, (very mild, totally expected) age-related
cognitive decline (which is a topic I've been meaning to
write up my notes on), or my squirrel brain could just have
been pretty bad at this all along. Anyway, words or code,
sometimes I just gotta pick one. Never mind my laptop's CPU
not handling ffmpeg well, my brain's CPU gets high
utilization too. That's good, though!
tldr (2167 words): I can make animating presentation maps easier by
writing my own functions for the Emacs text editor. In this post, I
show how I can animate an SVG element by element. I can also add IDs
to the path and use CSS to build up an SVG with temporary highlighting
in a Reveal.js presentation.
Text from the sketch
PNG: Inkscape: trace
Supernote (e-ink)
iPad: Adobe Fresco
Convert PDF to SVG with Inkscape (Cairo option) or pdftocairo)
PNG / Supernote PDF: Combined shapes. Process
Break apart, fracture overlaps
Recombine
Set IDs
Sort paths -> Animation style 1
Adobe Fresco: individual elements in order; landscape feels natural
Animation styles
Animation style 1: Display elements one after another
Animation style 2: Display elements one after another, and also show/hide highlights
Table: slide ID, IDs to add, temporary highlights -> Reveal.js: CSS with transitions
Ideas for next steps:
Explore graphviz & other diagramming tools
Frame-by-frame SVGs
on include
write to files
FFmpeg crossfade
Recording Reveal.js presentations
Use OCR results?
I often have a hard time organizing my thoughts into a linear
sequence. Sketches are nice because they let me jump around and still
show the connections between ideas. For presentations, I'd like to
walk people through these sketches by highlighting different areas.
For example, I might highlight the current topic or show the previous
topics that are connected to the current one. Of course, this is
something Emacs can help with. Before we dive into it, here are quick
previews of the kinds of animation I'm talking about:
Getting the sketches: PDFs are not all the same
Let's start with getting the sketches. I usually export my sketches as
PNGs from my Supernote A5X. But if I know that I'm going to animate a
sketch, I can export it as a PDF. I've recently been experimenting
with Adobe Fresco on the iPad, which can also export to PDF. The PDF I
get from Fresco is easier to animate, but I prefer to draw on the
Supernote because it's an e-ink device (and because the kiddo usually
uses the iPad).
If I start with a PNG, I could use Inkscape to trace the PNG and turn
it into an SVG. I think Inkscape uses autotrace behind the scenes. I
don't usually put my highlights on a separate layer, so autotrace will
make odd shapes.
It's a lot easier if you start off with vector graphics in the first
place. I can export a vector PDF from the SuperNote A5X and either
import it into Inkscape using the Cairo option or use the command-line
pdftocairo tool.
I've been looking into using Adobe Fresco, which is a free app
available for the iPad. Fresco's PDF export can be converted to an SVG
using Inkscape or PDF to Cairo. What I like about the output of this
app is that it gives me individual elements as their own paths and
they're listed in order of drawing. This makes it really easy to
animate by just going through the paths in order.
Animation style 1: displaying paths in order
Here's a sample SVG file that pdfcairo creates from an Adobe Fresco
PDF export:
Adobe Fresco also includes built-in time-lapse, but since I often like
to move things around or tidy things up, it's easier to just work with
the final image, export it as a PDF, and convert it to an SVG.
I can make a very simple animation by setting the opacity of all the
paths to 0, then looping through the elements to set the opacity back
to 1 and write that version of the SVG to a separate file.
From how-can-i-generate-png-frames-that-step-through-the-highlights:
my-animate-svg-paths: Add one path at a time. Save the resulting SVGs to OUTPUT-DIR.
Neither Supernote nor Adobe Fresco give me the original stroke
information. These are filled shapes, so I can't animate something
drawing it. But having different elements appear in sequence is fine
for my purposes. If you happen to know how to get stroke information
out of Supernote .note files or of an iPad app that exports nice
single-line SVGs that have stroke direction, I would love to hear
about it.
Identifying paths from Supernote sketches
When I export a PDF from Supernote and convert it to an SVG, each
color is a combined shape with all the elements. If I want to animate
parts of the image, I have to break it up and recombine selected
elements (Inkscape's Ctrl-k shortcut) so that the holes in shapes are
properly handled. This is a bit of a tedious process and it usually
ends up with elements in a pretty random order. Since I have to
reorder elements by hand, I don't really want to animate the sketch
letter-by-letter. Instead, I combine them into larger chunks like
topics or paragraphs.
The following code takes the PDF, converts it to an SVG, recolours
highlights, and then breaks up paths into elements:
my-sketch-convert-pdf-and-break-up-paths: Convert PDF to SVG and break up paths.
(defunmy-sketch-convert-pdf-and-break-up-paths (pdf-file &optional rotate)
"Convert PDF to SVG and break up paths."
(interactive (list (read-file-name
(format "PDF (%s): "
(my-latest-file "~/Dropbox/Supernote/EXPORT/""pdf"))
"~/Dropbox/Supernote/EXPORT/"
(my-latest-file "~/Dropbox/Supernote/EXPORT/""pdf")
t
nil
(lambda (s) (string-match "pdf" s)))))
(unless (file-exists-p (concat (file-name-sans-extension pdf-file) ".svg"))
(call-process "pdftocairo" nil nil nil "-svg" (expand-file-name pdf-file)
(expand-file-name (concat (file-name-sans-extension pdf-file) ".svg"))))
(let ((dom (xml-parse-file (expand-file-name (concat (file-name-sans-extension pdf-file) ".svg"))))
highlights)
(setq highlights (dom-node 'g'((id . "highlights"))))
(dom-append-child dom highlights)
(dolist (path (dom-by-tag dom 'path))
;; recolor and move
(unless (string-match (regexp-quote "rgb(0%,0%,0%)") (or (dom-attr path 'style) ""))
(dom-remove-node dom path)
(dom-append-child highlights path)
(dom-set-attribute
path 'style
(replace-regexp-in-string
(regexp-quote "rgb(78.822327%,78.822327%,78.822327%)")
"#f6f396"
(or (dom-attr path 'style) ""))))
(let ((parent (dom-parent dom path)))
;; break apart
(when (dom-attr path 'd)
(dolist (part (split-string (dom-attr path 'd) "M " t " +"))
(dom-append-child
parent
(dom-node 'path`((style . ,(dom-attr path 'style))
(d . ,(concat "M " part))))))
(dom-remove-node dom path))))
;; remove the use
(dolist (use (dom-by-tag dom 'use))
(dom-remove-node dom use))
(dolist (use (dom-by-tag dom 'image))
(dom-remove-node dom use))
;; move the first g down
(let ((g (car (dom-by-id dom "surface1"))))
(setf (cddar dom)
(seq-remove (lambda (o)
(and (listp o) (string= (dom-attr o 'id) "surface1")))
(dom-children dom)))
(dom-append-child dom g)
(when rotate
(let* ((old-width (dom-attr dom 'width))
(old-height (dom-attr dom 'height))
(view-box (mapcar 'string-to-number (split-string (dom-attr dom 'viewBox))))
(rotate (format "rotate(90) translate(0 %s)" (- (elt view-box 3)))))
(dom-set-attribute dom 'width old-height)
(dom-set-attribute dom 'height old-width)
(dom-set-attribute dom 'viewBox (format "0 0 %d %d" (elt view-box 3) (elt view-box 2)))
(dom-set-attribute highlights 'transform rotate)
(dom-set-attribute g 'transform rotate))))
(with-temp-file (expand-file-name (concat (file-name-sans-extension pdf-file) "-split.svg"))
(svg-print (car dom)))))
You can see how the spaces inside letters like "o" end up being black.
Selecting and combining those paths fixes that.
If there were shapes that were touching, then I need to draw lines and
fracture the shapes in order to break them apart.
The end result should be an SVG with the different chunks that I might
want to animate, but I need to identify the paths first. You can
assign object IDs in Inkscape, but this is a bit of an annoying
process since I haven't figured out a keyboard-friendly way to set
object IDs. I usually find it easier to just set up an Autokey
shortcut (or AutoHotkey in Windows) to click on the ID text box so
that I can type something in.
Autokey script for clicking
import time
x, y= mouse.get_location()
# Use the coordinates of the ID text field on your screen; xev can help
mouse.click_absolute(3152, 639, 1)
time.sleep(1)
keyboard.send_keys("<ctrl>+a")
mouse.move_cursor(x, y)
Then I can select each element, press the shortcut key, and type an ID
into the textbox. I might use "t-…" to indicate the text for a map
section, "h-…" to indicate a highlight, and arrows by specifying
their start and end.
To simplify things, I wrote a function in Emacs that will go through
the different groups that I've made, show each path in a different
color and with a reasonable guess at a bounding box, and prompt me for
an ID. This way, I can quickly assign IDs to all of the paths. The
completion is mostly there to make sure I don't accidentally reuse an
ID, although it can try to combine paths if I specify the ID. It saves
the paths after each change so that I can start and stop as needed.
Identifying paths in Emacs is usually much nicer than identifying them
in Inkscape.
my-svg-identify-paths: Prompt for IDs for each path in FILENAME.
(defunmy-svg-identify-paths (filename)
"Prompt for IDs for each path in FILENAME."
(interactive (list (read-file-name "SVG: " nil nil
(lambda (f) (string-match "\\.svg$" f)))))
(let* ((dom (car (xml-parse-file filename)))
(paths (dom-by-tag dom 'path))
(vertico-count 3)
(ids (seq-keep (lambda (path)
(unless (string-match "path[0-9]+" (or (dom-attr path 'id) "path0"))
(dom-attr path 'id)))
paths))
(edges (window-inside-pixel-edges (get-buffer-window)))
id)
(my-svg-display "*image*" dom nil t)
(dolist (path paths)
(when (string-match "path[0-9]+" (or (dom-attr path 'id) "path0"))
;; display the image with an outline
(unwind-protect
(progn
(my-svg-display "*image*" dom (dom-attr path 'id) t)
(setq id (completing-read
(format "ID (%s): " (dom-attr path 'id))
ids))
;; already exists, merge with existing element
(if-let ((old (dom-by-id dom id)))
(progn
(dom-set-attribute
old
'd
(concat (dom-attr (dom-by-id dom id) 'd)
" ";; change relative to absolute
(replace-regexp-in-string "^m""M"
(dom-attr path 'd))))
(dom-remove-node dom path)
(setq id nil))
(dom-set-attribute path 'id id)
(add-to-list 'ids id))))
;; save the image just in case we get interrupted halfway through
(with-temp-file filename
(svg-print dom))))))
Then I can animate SVGs by specifying the IDs. I can reorder the paths
in the SVG itself so that I can animate it group by group, like the
way that the Adobe Fresco SVGs were animated element by element.
The way it works is that the my-svg-reorder-paths function removes
and readds elements following the list of IDs specified, so
everything's ready to go for step-by-step animation. Here's the code:
Animation style 2: Building up a map with temporary highlights
I can also use CSS rules to transition between opacity values for more
complex animations. For my EmacsConf 2023 presentation, I wanted to
make a self-paced, narrated presentation so that people could follow
hyperlinks, read the source code, and explore. I wanted to include a
map so that I could try to make sense of everything. For this map, I
wanted to highlight the previous sections that were connected to the
topic for the current section.
I used a custom Org link to include the full contents of the SVG
instead of just including it with an img tag.
#+ATTR_HTML: :class r-stretchmy-include:~/proj/emacsconf-2023-emacsconf/map.svg?wrap=export html
my-include-export: Export PATH to FORMAT using the specified wrap parameter.
I wanted to be able to specify the entire sequence using a table in
the Org Mode source for my presentation. Each row had the slide ID, a
list of highlights in the form prev1,prev2;current, and a
comma-separated list of elements to add to the full-opacity view.
Reveal.js adds a "current" class to the slide, so I can use that as a
trigger for the transition. I have a bit of Emacs Lisp code that
generates some very messy CSS, in which I specify the ID of the slide,
followed by all of the elements that need their opacity set to 1, and
also specifying the highlights that will be shown in an animated way.
my-reveal-svg-progression-css: Make the CSS.
(defunmy-reveal-svg-progression-css (map-progression &optional highlight-duration)
"Make the CSS.map-progression should be a list of lists with the following format:((\"slide-id\" \"prev1,prev2;cur1\" \"id-to-add1,id-to-add2\") ...)."
(setq highlight-duration (or highlight-duration 2))
(let (full)
(format
"<style>%s</style>"
(mapconcat
(lambda (slide)
(setq full (append (split-string (elt slide 2) ",") full))
(format "#slide-%s.present path { opacity: 0.2 }%s { opacity: 1 !important }%s"
(car slide)
(mapconcat (lambda (id) (format "#slide-%s.present #%s" (car slide) id))
full
", ")
(my-reveal-svg-highlight-different-colors slide)))
map-progression
"\n"))))
Since it's automatically generated, I don't have to worry about it
once I've gotten it to work. It's all hidden in a
results drawer. So this CSS highlights specific parts of the SVG with
a transition, and the highlight changes over the course of a second or
two. It highlights the previous names and then the current one. The
topics I'd already discussed would be in black, and the topics that I
had yet to discuss would be in very light gray. This could give people
a sense of the progress through the presentation.
As a result, as I go through my presentation, the image appears to
build up incrementally, which is the effect that I was going for.
I can test this by exporting only my map slides:
Graphviz, mermaid-js, and other diagramming tools can make SVGs. I
should be able to adapt my code to animate those diagrams by adding
other elements in addition to path. Then I'll be able to make
diagrams even more easily.
Since SVGs can contain CSS, I could make an SVG equivalent of the
CSS rules I used for the presentation, maybe calling a function with
a Lisp expression that specifies the operations (ex:
("frame-001.svg" "h-foo" opacity 1)). Then I could write frames to
SVGs.
FFmpeg has a crossfade filter. With a little bit of figuring out, I
should be able to make the same kind of animation in a webm form
that I can include in my regular videos instead of using Reveal.js
and CSS transitions.
I've also been thinking about automating the recording of my
Reveal.js presentations. For my EmacsConf talk, I opened my
presentation, started the recording with the system audio and the
screen, and then let it autoplay the presentation. I checked on it
periodically to avoid the screensaver/energy saving things from
kicking in and so that I could stop the recording when it's
finished. If I want to make this take less work, one option is to
use ffmpeg's "-t" argument to specify the expected duration of the
presentation so that I don't have to manually stop it. I'm also
thinking about using Puppeteer to open the presentation, check when
it's fully loaded, and start the process to record it - maybe even
polling to see whether it's finished. I haven't gotten around to it
yet. Anyhow, those are some ideas to explore next time.
As for animation, I'm still curious about the possibility of
finding a way to access the raw stroke information if it's even
available from my Supernote A5X (difficult because it's a
proprietary data format) or finding an app for the iPad that exports
single line SVGs that use stroke information instead of fill. That
would only be if I wanted to do those even fancier animations that
look like the whole thing is being drawn for you. I was trying to
figure out if I could green screen the Adobe Fresco timelapse videos
so that even if I have a pre-sketch to figure out spacing and remind
me what to draw, I can just export the finished elements. But
there's too much anti-aliasing and I haven't figured out how to do
it cleanly yet. Maybe some other day.
I use Google Cloud Vision's text detection engine to convert my
handwriting to text. It can give me bounding polygons for words or
paragraphs. I might be able to figure out which curves are entirely
within a word's bounding polygon and combine those automatically.
It would be pretty cool if I could combine the words recognized by
Google Cloud Vision with the word-level timestamps from speech
recognition so that I could get word-synced sketchnote animations
with maybe a little manual intervention.
Anyway, those are some workflows for animating sketches with Inkscape
and Emacs. Yay Emacs!
[2024-01-12 Fri]: Added some code to display the QR code on the right side.
John Kitchin includes little QR codes in his videos. I
thought that was a neat touch that makes it easier for
people to jump to a link while they're watching. I'd like to
make it easier to show QR codes too. The following code lets
me show a QR code for the Org link at point. Since many of
my links use custom Org link types that aren't that useful
for people to scan, the code reuses the link resolution code
from https://sachachua.com/dotemacs#web-link so that I can get the regular
https: link.
(defunmy-org-link-qr (url)
"Display a QR code for URL in a buffer."
(let ((buf (save-window-excursion (qrencode--encode-to-buffer (my-org-stored-link-as-url url)))))
(display-buffer-in-side-window buf '((side . right)))))
(use-packageqrencode:config
(with-eval-after-load'embark
(define-key embark-org-link-map (kbd "q") #'my-org-link-qr)))