Restful #02
(&rest rest)
The wonderful Org Show Branches
It's great that we can cycle org trees' visibility with TAB and S-TAB. But there's a useful visibility state that you can't reach with these. Here are steps to reproduce it:
- Open an org file that has subtrees at many levels.
- With point at the root of a big one, press C-l once or twice to
recenter-top-bottomat the top: you want screen space. - Then press C-c C-k to run
org-kill-note-or-show-branches. There's no open note, so no note to kill: branches will be shown. - Conclude the procedure by exclaiming "Whoa!".
Now try this again before the first headline to have it applied to all the trees in the buffer — in which case everything before the first headline disappears. But you don't panic — you've seen this before — you know what to do — so...
"What? I'm not narrowed?"
No, you're not narrowed. Widening won't help.
But that's ok — a S-TAB S-TAB from anywhere is how you make it reappear.
A dozen ways from vector to list
Once in a while I still pause before this simple and common operation: convert a vector to list.
But no more. I came up with a dozen ways to do it:
;; Libraries Characters (--map it [a "b" :c 4]) => '(a "b" :c 4) ; dash 08 + vec+3 (append [a "b" :c 4] nil) => '(a "b" :c 4) ; C src 10 + vec+3 (string-to-list [a "b" :c 4]) => '(a "b" :c 4) ; subr → C src 14 + vec+3 (-map #'identity [a "b" :c 4]) => '(a "b" :c 4) ; dash 15 + vec+3 (mapcar (##and %) [a "b" :c 4]) => '(a "b" :c 4) ; llama 16 + vec+3 (seq-map (##and %) [a "b" :c 4]) => '(a "b" :c 4) ; seq + llama 17 + vec+3 (mapcar #'identity [a "b" :c 4]) => '(a "b" :c 4) ; C src 17 + vec+3 (-map (-cut and <>) [a "b" :c 4]) => '(a "b" :c 4) ; dash 18 + vec+3 (seq-map #'identity [a "b" :c 4]) => '(a "b" :c 4) ; seq 18 + vec+3 (cl-mapcar (##and %) [a "b" :c 4]) => '(a "b" :c 4) ; cl-lib + llama 19 + vec+3 (cl-mapcar #'identity [a "b" :c 4]) => '(a "b" :c 4) ; cl-lib 20 + vec+3 (seq-concatenate 'list [a "b" :c 4]) => '(a "b" :c 4) ; seq 21 + vec+3
A pause to plug packages
(One keypress to (or (and (or 'insert 'update) (or 'align 'nil)) 'remove) a whole block of evaluation arrows when point is anywhere in these lines — a magic trick provided by Exemplify-Eval and Exemplify-Align.)
I almost always go with --map or append.
The third one seems weird here, right? The input isn't a string.
But when it is a string, it looks like this:
(string-to-list "foo") => '(102 111 111) (concat '(102 111 111)) => "foo"
A bit odd to apply it to a non-string, but we can.
That function is in subr.el, as a defsubst:
(defsubst string-to-list (string) "Return a list of characters in STRING." (declare (side-effect-free t)) (append string nil))
So (string-to-list x) is simply (append x nil).
Despite being longer, and despite its (in this case) odd name, it has two advantages:
- native (like
append) - last-threadable (like
--map)
Want to listify a vector?
You can have it short, dashless, and last-threadable — pick two.
Send emoji cat to file cat and cat it
Feline Mangling Warning!
Doing this when "$PWD" is /usr/bin might mangle your cat, bringing you a sorrowful afternoon of reinstalling coreutils — so don't do that.
Pick instead a catless directory — say, a new empty one, or just cd /tmp.
If from Emacs, you can:
- Open an Org scratch buffer
- Change directory: M-x
cdRET/tmpRET - Verify the change: M-x
pwdRET - Wrap each of the two in:
#+begin_src bash :noweb no :results pp #+end_src
Need just one cat?
cat <<^..^>> cat
🐱
^..^
cat cat
>cat
Or need many cats?
>> cat cat <<^..^>> cat $(cat cat cat) 🐱 ^..^ cat cat
Repeat the latter as desired to multiply cats.
📆 2025-12-07