Lentic is a package which implements lenticular text — two Emacs buffers that contain the same content, but are otherwise independent. Unlike indirect-buffers, which must contain absolutely identical strings, lentic buffers can contain different text, with a transformation between the two.

This has several uses. Firstly, it allows a form of multi-modal editing, where each lentic buffer shows the text in a different mode. For example, this can be used to edit literate Haskell code. This should work with indirect-buffers, but in practice does not because the buffers share text-properties. These are a feature of the buffer strings in Emacs, and are used by some modes for their functionality; when two modes work on the same string, each tends to reset the text properties of the other.

It is possible to take this form of multi-modal editing further, where the different buffers contain different syntax. So, for example, one buffer might be in fully valid Emacs-Lisp, while the other might be a fully-valid org-mode buffer. This allows a literate programming technique even without specific support for this form of programming in the language. Taken to the extreme, it is even possible for the buffers to contain completely different strings; I have not found a good practical use for the extreme yet, but lentic now supports a rot-13 transformation which demonstrates its capabilities.

Lentic can also be used to create persistant views of the same text. For example, lentic could be used to maintain a view of the imports of a java file, or the namespace form in clojure, or the preamble of a latex document. Unlike a second window, this view persists even if it is not visible. Alternatively, one view could use very small text, and the other could contain larger text, allowing rapid navigation.

Lentic 0.8 contains a number of new features since the 0.7 [release] (http://www.russet.org.uk/blog/3047). The biggest change is that it is possible to produce any number of lentic buffers, rather than just two as previously. This means that its multi-modal and persistant view capabilities can be used at the same time.

Lentic is now available on MELPA, MELPA stable and github.

Bibliography

5 Comments

  1. DamienCassou says:

    Would it be possible to use Lentic to show some source in a buffer and some compilation result in another? For example, I can imagine having org-mode on the left and the resulting html on the right.

  2. Phillip Lord says:

    Hmmm, well, yes, that would be possible — for instance, the ROT-13 implementation does something similar.

    For org->html, I think coming up with a *bi-directional* transformation would be a lost cause — so you’d only get to edit the org-mode side. I hadn’t thought about this as a use for lentic, but actually, it should support single-direction transformations quite well. The two questions I am not sure about is, a) how would sync the point between the two and b) whether org would be fast enough to export.

  3. DamienCassou says:

    a) by wrapping some movement functions (e.g., C-n and C-p) and by using isearch and b) let’s see :-)

  4. Phillip Lord says:

    a) Using isearch would be an interesting way to sync point, although, pimping up org-mode would be better — after all, org-mode knows which bit of text in the org buffer it is working on when it outputs HTML. So, getting it to transfer a text property or an overlay at this point should be possible. Still, cheap and cheerful first, and worry about performance later. The first version of lentic just copied the whole buffer on every key press.

    b) Sounds great. Are you offering? I am going to add “unidirectional” support (so that changes in A percolate to B, but changes in B do not percolate backward) anyway.

  5. DamienCassou says:

    a) I’m not offering my help to develop this particular feature as my plate is already full. But I’m willing to adapt pillar-mode to get a live HTML view of the edited pillar document. Please keep me informed. Thank you for your work

Leave a Reply