mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.97k stars 714 forks source link

[Feature request] replace-regex highlighter #2536

Open andreyorst opened 6 years ago

andreyorst commented 6 years ago

Conceal is somewhat arcane feature of Vim, that allows to display text differently from how it actually stored in text document. It is widely used in Vim documentation, and another filetypes, to hide formatting symbols from eyesight. Concealing also can be used by various plugins to display information on a some point of line by dynamically generating conceal rules.

In short, concealing works this way: display "some text" from the file as "some other text" Usage cases:

  1. We can add different ligatures for different filetypes, even if our font doesn't support ligatures.
  2. Plugins such as kak-lsp would be able to display additional info about the code, like Intellij Idea does: image (:Unit is displayed as concealed text)
  3. Filetypes like markdown would be able to display such things like *bold text* as bold text.

I think that conceal should be a regexp highlighter, that acts like show whitespaces but for any regexp matched text:

add-highlighter global/div conceal "/" "÷"
add-highlighter window/arrow conceal "->" "→"

And so on.

While we're in insert mode on the same line with some concealed text, conceal maybe should be disabled, so we could see real contents of the line.

Screwtapello commented 6 years ago

See also #453, in which code folding would be implemented by exactly the same mechanism.

mawww commented 6 years ago

This should be handled by the (existing but limited) replace-ranges highglighter, and the (not existing yet) replace-regex highlighter.

An additional feature we need is a way to specify empty ranges (so that we can introduce the :Unit example), which we cannot now because we want to share the range syntax and the selection syntax (to make it easy to generate ranges from selections), and the selection syntax is necessarily inclusive (as selections are inclusive and oriented). As ranges support the + syntax as well, we could change it to be non-inclusive, so that specifing an empty range would be +0.

andreyorst commented 4 years ago

I've changed the issue name to represent the feature @mawww described in the previous comment.

I'm currently in process of updating my kaktree plugin, and we decided to store path info in the buffer. I have a question: will we be able to use replaced info in its original state for other highlighters?

What I mean is, if we have this buffer:

item [[some additional info]]
other_item [[some other info]]

And we replace ranges with nothing by using replace-regex highlighter. What we actually see now:

item
other_item

Now we want to highlight other_item because it has [[some other info]] that matches our regular regex highlighter \w+\s+(?=\[\[some other info\]\]). Will this work as if no replace-regex were added?

mawww commented 4 years ago

@andreyorst I would expect that use case to work as a regex highlighter will match on the buffer text, independently of what is on screen.