phillord / lentic

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

Support C-like comments (/* ... */) #8

Open ffevotte opened 9 years ago

ffevotte commented 9 years ago

First, let me thank you for lentic: it looks a lot like the LP tool I've been wanting for years!

The first application case I tried (which fits my current needs) is : Maxima code embedded into a LaTeX document. I thought about embedding Maxima fragments into comment environments, and using lentic-(un)commented-block-configuration to define the tex to/from maxima conversion. I however stumbled upon two problems, caused by Maxima's use of C-like comments (/* ... */)

  1. lentic-(un)commented-block-configuration seems to only manage commented lines with a start marker, but can not add/remove line end comment markers
  2. I didn't quite understand the semantic of the :comment slot in lentic-(un)commented-block-configuration: is it a plain string or a regular expression? In the case of C-like comment markers, I would like to use "/* " as a comment marker, but I have encountered difficulties with the star (*) character. Things behave strangely when I don't escape it:

    :comment "/* "

    and don't work at all when I escape it like so:

    :comment "/\\\* "

Would it be hard to adapt the existing block conversion of define a new one for such cases? I might be able to try defining one if you give me the required pointers.

Many thanks in advance.

phillord commented 9 years ago

Unfortunately "block configuration" is not that well named. The blocks refer to "blocks of code" demarked in comments, rather than block comments. At the moment, it really only supports beginning of line comments. This is not to say that it could not support C-style block comments, and it is something that I would like to add. The simple case (where /* and / appear on their own line) would not be hard. Supporting / single line */ comments would be a little harder. I'm not sure when I will support this form of comment yet, though. It may take a little while.

The :comment slot is used as a string (for insertion) and also to construct a regexp, so, yes, by default regexp special characters are going to break things. However, this can be modified with the lentic-blk-line-start-comment method. This should use regexp-quote by default though; I've opened a new issue for this, see #9.

ffevotte commented 9 years ago

The simple case (where /* and */ appear on their own line) would not be hard.

Nice to hear! I'll try implementing it, then. Would you think I should implement a new configuration from scratch, or simply specialize the block configuration? (I should mention that I know nothing of CLOS or EIEIO)

phillord commented 9 years ago

The EIEIO stuff isn't that hard. I think that quite a bit of the code could be shared with the block-configuration, but it makes a few assumptions that may not be true. It assumes, for instance, that all comments are the same (not true!), and that they start at the begining of the line.

You can use functionality from lentic-block even if you don't directly extent the block configuration.

phillord commented 9 years ago

Oh, if you try and have a go, please feel free to ask my about things you do not understand; I am updating the documentation as it stands and would welcome feedback about the parts which are not clear.