jmacdonald / amp

A complete text editor for your terminal.
https://amp.rs
Other
3.73k stars 105 forks source link

[Feature request] Highlight matching parentheses #135

Open euhmeuh opened 5 years ago

euhmeuh commented 5 years ago

Specification

When the cursor is on (, ), [, ], { or }, highlight the corresponding closing or opening character (if found).

Notes

It's the only feature missing for this editor to be perfect ;)

There's a lot of algorithms lying around on the Internets, so I guess there's plenty of ways to implement this. I wonder what would be the easiest considering Amp's architecture. Looking at other open source projects for examples might be a good idea.

I'm open to any advice, tips, and directions on how to implement this, if no one has the time to do it. I'm pretty busy myself, that's why I didn't directly submitted a PR, but with some starting points, I could try something.

jmacdonald commented 5 years ago

Hi @euhmeuh!

Can you explain a little bit about what problem that feature is solving? Are you dealing with heavily nested parentheses, like this:

nested(functions(are(painful())))

or are you trying to select a series of lines like this:

function() {
  nested_function() {
    really_nested_function() {
      // Lots of content
      // here that makes
      // it difficult to see
      // which nesting level
      // you're targeting.
    }
  }
}

I don't run into the first case very often, but I do run into the second, and I have other ideas for how to solve that. :slightly_smiling_face:

euhmeuh commented 5 years ago

Well I work with Lisp languages :stuck_out_tongue: so I'd say the first case:

(define (harvest crops)
  (cond
    [(wheat? crops) (make-bread water (make-flour crops))]
    [(hop? crops) (make-beer crops)]
    [else (store crops)]))

It's basically the only feature I feel is mandatory for working with Lisp languages: you can just move your cursor from one paren to the other and immediately see the scope of what you're working on. It's useful when working with Racket, Scheme, Common Lisp, Arc, Clojure... to cite a few.

jmacdonald commented 5 years ago

Makes sense! This should sit in the normal mode presenter. That said, those are under a bit of a rewrite for 0.6.0. Once that lands, I can add this to the pipe for a minor release in that series. :slightly_smiling_face: