Org-mode Hidden Gems - 02 Tables

Region operations on cells

Excel-like copy-pasting: C-c C-x M-w(copy)/C-w(cut)/C-y(paste).

Create table from region

Bound to C-c |, org-table-create-or-convert-from-region converts semi-formatted texts (esp. those copied from web) into Org table.

This command rely on detecting delimiter TAB or comma in region. If conversion fails, check any minor modes or settings that may turn TAB character into space in the background. In my case, it’s whitespace-cleanup-mode. This can get tricky if enabled along with auto-save-mode, as copied text might be auto-saved and TABs stripped before conversion. A workaround is to disable them temporarily.

Special Marking Characters for Tables

Advanced Features demonstrates how to use special marking characters to enable two desired features: assigning names to rows/columns/fields, and automatic recalculation of fields.

It is easier to follow the examples in Emacs with proper highlighting, than in HTML/Info in B&W, do give it a try. Here I copy the table to show it in action. Key take-aways:

  • Special marking characters shall occupy the first column
  • Name columns/rows in a human-readable way with !, ^, _ (No more counting, no more C-c ? to locate reference)
  • Control automatic recalculation with # and *
  • Define per-table parameters/constants in unused cells with $

I was confused by table references and haven’t used much of calculation features before, but this section is quite enlightening. I think I’ll use it more later.

That concludes Tables chapter.

Behind the Scene: Bulk Video Conversion with Dired

To support pause operation, I migrated all videos from original gif to webm, and was later reminded (by /u/Bombastry, thanks) that Safari can’t handle webm properly. I still wish to support all browsers, and found out mp4 as a better choice. Now I’ve got a bunch of webm in hand, how do I generate corresponding mp4?

First I need an ffmpeg command. It’s one search away:

ffmpeg -i input.webm -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" output.mp4

Works fine, how do I apply to each individual webm though? I don’t want to input one by one to terminal by hand. Neither do I feel like writing bash script (takes time to remember syntax), nor copy file names from dired and use rectangle editing hacks (lots of editing, you will see my attempt at the beginning of video).

Then I notice this line in dired-do-shell-command (bound to !):

If there is no ‘*’, but there is a ‘?’ in COMMAND, surrounded by whitespace, or
a ‘`?`’ this runs COMMAND on each file individually with the file name
substituted for ‘?’ or ‘`?`’.

Almost cryptic, but essentially it allows running a command on individual marked files. Combined with wdired, this turns out to be quite a smooth flow:

  1. Mark files: individually with m, or in one go with dired-mark-extension (bound to * ., you’ll need dired-x)
  2. Run command: ! (or & to run asynchronously), fill in command, using ? and `?` to refer to file name
  3. Fix suffixes: toggle on wdired (C-x C-q) and query-replace (M-%)

Not Org-mode related, just thought it’s a cool pipeline. Recorded as a macro, this could be a one-click bulk conversion tool for videos. Emacs does have some plain text magics!

PS: If you know how to refer to filename without the suffix, please let me know, this would simplify it even further. It should be a common use case (same filename with different suffix in input/output), but I couldn’t find related settings.

Org-mode Hidden Gems series:

comments powered by Disqus