27 June 2014

MailMate supports writing emails in MarkDown and also offers an extension to render tables; these get sent as a multi-part message that is MarkDown and HTML, so other mail readers can render them, too.

Org-Mode has, arguably, the best ASCII table editing environment, and those tables can be written by hand or generated from SQL, R, Python, etc. from within org-mode. Those tables can be rendered by org-mode as HTML, LaTeX, plain text, markdown, and other formats.

Getting the org-mode tables rendered as an appropriate MarkDown table that is suitable for insertion into MailMate is a great time saver for the three people I know who might do that (Paul K. and Matt B., I’m counting myself; if there is a fourth person, contact me, we can be friends).

For example, this table looks pretty nice in HTML on this blog (iidssm).

Name Age
Andy 43
Michelle 43
Don 69
Maddie 7
Megan 39

and what I typed was:

#+ORGTBL: SEND ages orgtbl-to-gfm
  | Name     | Age |
  |----------+-----|
  | Andy     |  43 |
  | Michelle |  43 |
  | Don      |  69 |
  | Maddie   |   7 |
  | Megan    |  39 |

To go from the org table to the MarkDown table, these are the steps:

  1. Paste the contents of this Gist into your .emacs file:
  2. Type or generate your table in org-mode, including the “#ORGTBL: SEND” line.
  3. Create a place for the MarkDown table to go, perhaps into a #+BEGIN/END COMMENT block, using the BEGIN/END RECEIVE... lines.
  4. Switch from Org-mode to text mode: M-x text-mode
  5. Enter the orgtbl minor mode: M-x orgtbl-mode
  6. Move the point (cursor) to the ORGTBL: SEND line and press C-c C-c to generate the markdown table
  7. Switch back to Org-mode: M-x org-mode

That will produce this output

# BEGIN RECEIVE ORGTBL ages
| Name | Age |
|---|--:|
| Andy | 43 |
| Michelle | 43 |
| Don | 69 |
| Maddie | 7 |
| Megan | 39 |
# END RECEIVE ORGTBL ages

Now you can copy the MarkDown table to your MailMate message and it will render as a table.

mailmate-table.png