idris-hackers / idris-mode

Idris syntax highlighting, compiler-supported editing, interactive REPL and more things for Emacs.
GNU General Public License v3.0
269 stars 71 forks source link

Documentation comment highlighting (w/ possible solution) #463

Closed dkimbel closed 6 years ago

dkimbel commented 7 years ago

It looks like ||| documentation comments only receive syntax highlighting when they start a line or are preceded exclusively by whitespace. So, for instance, the documentation comments in the Type-Driven Development with Idris code blurb below are not fully highlighted.

||| Represents shapes
data Shape = ||| A triangle, with its base length and height
             Triangle Double Double
           | ||| A rectangle, with its length and height
             Rectangle Double Double
           | ||| A circle, with its radius
             Circle Double
bad comment highlighting

By tweaking idris-syntax.el locally, I was able to get highlighting to work for that code.

good comment highlighting

The change I made was to mostly duplicate idris-syntax.el's lines 234-236 in a new apply-partially block on line 237:

(,(apply-partially #'idris-font-lock-literate-search "\\s-*\\(|||\\)\\(.*\\)$" (idris-lidr-p))
         (1 font-lock-comment-delimiter-face)
         (2 'idris-inline-doc-face))

I'm very much an Emacs newbie -- there's most likely a more elegant solution. I wasn't able to find a straightforward update that wouldn't still require the earlier line-start call using the same regex pattern, though.

If you'd like me to open a PR with that update, I can -- also, if you have any pointers on a better solution, I'd be very happy to make changes. In any case, thanks for idris-mode and your work on Idris itself!

abailly commented 6 years ago

@Techowl I am pretty much an emacs newbie too :) Could you please open PR? I will try to see if I can come up with a better solution starting from it or else merge it.

dkimbel commented 6 years ago

@abailly Sure thing! I just opened a pull request at https://github.com/idris-hackers/idris-mode/pull/477.

david-christiansen commented 6 years ago

The Font Lock stuff is pretty hairy, unfortunately, because it tries to support both .lidr files and .idr files. I suspect that what you've written can't be a whole lot simpler without redoing the whole approach.

david-christiansen commented 6 years ago

When writing the mode (and adding the ||| syntax), I hadn't even considered ||| not being at the start of a line! Just goes to show how languages are extra fun :-)

dkimbel commented 6 years ago

Thanks! I'm closing this issue, since the fix at https://github.com/idris-hackers/idris-mode/pull/477 has been merged.