Skip to content

Instantly share code, notes, and snippets.

@acowley
Last active May 18, 2023 17:31
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acowley/2c62379f2fc0667f921b to your computer and use it in GitHub Desktop.
Save acowley/2c62379f2fc0667f921b to your computer and use it in GitHub Desktop.
Emacs Haskell Demo Show Notes

Org Editing in haskell-mode

The video opens with a regular Haskell source file in haskell-mode. We start off by adding headings that break the file into meaningful chunks. A section heading is indicated by an asterisk following Haskell single-line comment characters, i.e. -- *. These are top-level headings, sub-headings are indicated by adding more asterisks.

These section markers are given meaning by outshine. With speed commands enabled, we can navigate between headings or edit document structure with single keypresses, such as n and p to move to the "next" or "previous" headings.

A bit of Haskell code writing is also shown to demonstrate that this is still a regular Haskell source file that ghc-mod can work with. A simple demonstration of case splitting an identifier is shown.

The structure editing capabilities of outshine are then shown with the U and D keys to quickly manipulate the source file structure by moving sections "Up" and "Down".

Writing Comments in org-mode

The next main chunk of editing shows how to focus on editing the comments included in the source file. Here, we use outorg to switch to an org-mode view of the original source file by pressing M-# #. Org-mode lets us add LaTeX equations (which we can enter relatively quickly using an org-mode quick template triggered by hitting TAB with the cursor after <eq). After saving the outorg edit buffer (with C-x C-s, as usual), we can preview LaTeX snippets with org-preview-latex-fragment (C-c C-x C-l). Generating these previews takes a moment, but they are cached, so subsequent previews are quicker.

We then include a diagram generated with the diagrams package. The diagram is defined in an org-babel Haskell source block (a template triggered by hitting TAB with the cursor after <s helps with creating these source blocks) so we get natural Haskell syntax highlighting. We will use the diagrams-builder program to execute our diagram definition, but that program needs its input as a file. We save the diagram definition to the file dia.txt by "tangling" this block with org-babel-tangle (C-c C-v t).

We invoke diagrams-builder-rasterific with a bit of shell script, and can then view the generated PNG image directly in the document with org-toggle-inline-images (C-c C-x C-v). Diagram generation takes a few seconds, but these too are cached, so subsequent views of the document are quick.

When done, hitting M-# takes us back to haskell-mode with our changes copied over as comments. A complication is that the original source code is kept in org-babel haskell blocks when viewing the source file with outorg. When going back to haskell-mode, the source blocks become uncommented code, while the plain text of the org document become comments. If we leave our diagram definition as an org-babel haskell block, then it will be included as real source code in our original file. This is not what we want, so we leave that block as an org-babel block in the org language so that it is included in our source file as a comment. If we want syntax highlighting when viewing the file in org-mode again, we can simply change the language back from org to haskell.

Emacs Configuration

The video was made with my .emacs file. It uses versions of outorg and outshine that are under my account on github, but not yet merged upstream.

@RafalBabinicz
Copy link

Looks great. It’s very similar to lentic mode though.

http://www.russet.org.uk/blog/3035
https://github.com/phillord/lentic

@tj64
Copy link

tj64 commented Nov 1, 2015

Lentic mode is very similar to outshine/outorg, since its development started when the former libraries were already fully developed. Maybe the lentic author wasn't aware of them, since he never cites them, but the whole concept and idea looks like a 1:1 copy, only with a different implementation

@ggreif
Copy link

ggreif commented Apr 2, 2016

@tj64 @acowley, for me the font sizes in the outshine buffer differ from the outorg buffer's font sizes. (The colors match, though.)
In the video the fonts also match (e.g. augmented h1 fonts in the outshine buffers). Why can this happen? Am I missing something?

@ggreif
Copy link

ggreif commented Apr 2, 2016

@ggreif
Copy link

ggreif commented Apr 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment