phillord / lentic

Create views of the same content in two Emacs buffers
183 stars 12 forks source link

Tangling transformation #39

Open lionel- opened 8 years ago

lionel- commented 8 years ago

Would it be possible in principle for Lentic to support a documentation-free tangling transformation?

That is, a transformation where all documentation is omitted in the buffer with code chunks, possibly with chunk numerotation. So instead of:

;; This is the documentation for my code.
;; This is the documentation for my code.

;; #+BEGIN_SRC emacs-lisp
(some-code)
;; #+END_SRC

;; Some more documentation

;; #+BEGIN_SRC emacs-lisp
(other-code)
;; #+END_SRC

we would have:

(some-code)

(other-code)

or:

;; Chunk 1:
(some-code)

;; Chunk2:
(other-code)

The advantage over lentic-free tangling would be that modifying the code in the tangled buffer would also change the literate buffer. I guess the first one would be very difficult but the second one would already make the code buffer a lot more legible and navigable.

phillord commented 8 years ago

To clarify, you want, for example, and org-mode file with literate clojure source?

In that case, I think that there are two independent issues here. One is making a lentic buffer and the other is hiding comments. Combining the functionality of lentic (to produce the clojure mode visualisation) with something like hide-comnt.el (on the clojure mode visualisation) would seem to be the way to go. Lentic will then do it's thing with creating the two visualisations while hide-comnt.el (which uses text properties) will just hide the comments from view (at the point of screen display -- the comments are still there in the buffer, you just can't see them).

I've just tried this with clojure and latex and it (nearly) works.

Newly added comments in the latex appear disembodied in the Clojure mode view (correctly syntax highlighted though). And hide-comnt works on all comments, not just literate ones. So, the interaction could be improved and lentic could do this (because it can perform any transformation at all during the cloning operation). Lentic-dev, for example, adds random font-lock colours to buffers to show what lentic is doing.

lionel- commented 8 years ago

ah, good idea!

This strategy should make it much easier to implement because if I'm not mistaken lentic keeps track of the start/end markers of the chunks. This information can be used to modify (hide/show-comments) so that it operates only outside chunks.

Ideally that could be enabled for any lentic conf with a :hide-literate key. With the option to show chunk number / name (from org's #+NAME field) with an overlay.

Edit: Probably best to write custom code for this, because hide-cmnt doesn't hide the whitespace between comments.

I'll see if I can find some time next month to work on this.

phillord commented 8 years ago

Yeah. hide-comnt uses emacs "forward-comment" which isn't quite right in this case. lentic can provide boundary markers, though, which shows the literate blocks (for the current configuration).

The "lentic-clone" functionality tells you what has changed, which can be over-ridden to do the right thing (hide or otherwise comments), which should solve the problem of new text appearing without invisible markers. You could even mark is smart so not everything is hidden -- for example, the comment with point in it could be made visible.

How much you'd get from hide-comnt in this circumstance I don't know. It might just make sense to implement this lentic-configuration class that could be used as a mixin.

Of you could just not bother and use hide-comnt.el and lentic as is. It's close enough to doing what you want!

lionel- commented 8 years ago

Of you could just not bother and use hide-comnt.el and lentic as is. It's close enough to doing what you want!

I'm hacking a temporary solution along those lines right now, but Emacs should never be just "close enough" ;)

Thanks for your help!