greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, packages, and more.
https://www.racket-mode.com/
GNU General Public License v3.0
681 stars 93 forks source link

racket-smart-open-bracket: Handle optional and typed argument forms #205

Open andrew-kennedy opened 8 years ago

andrew-kennedy commented 8 years ago

In plai-typed, function arguments in definitions look like this:

(define (my-function [a : number] [b : symbol]) : (listof symbol)
    (list 'a 'b 'c))

smart-open-bracket does not handle inserting brackets in this case, reverting to parens. Just wanted to make the author aware, not sure if there's a good solution to this.

greghendershott commented 8 years ago

Thanks for the report. IIUC this is also relevant to #lang typed/racket and simply optional arguments in plain #lang racket.

greghendershott commented 8 years ago

The DrRacket feature upon which this is modeled doesn't seem to handle this case either. At least when I tried just now with Racket 6.3.

That doesn't mean racket-mode couldn't do better in this regard; just an observation.

andrew-kennedy commented 8 years ago

That's interesting. I just tested in DrRacket 6.4 and it still doesn't function correctly. I'll probably just turn it off then, at least for typed Racket and plai-typed. Maybe something like general-close can provide a good enough solution for this, as opposed to using DrRacket's features.

greghendershott commented 8 years ago

Maybe something like general-close can provide a good enough solution for this, as opposed to using DrRacket's features.

If you'd be happy with just the closing delimiter, racket-mode already does this for }, ], ). For instance C-h k ] says:

] runs the command racket-insert-closing, which is an interactive
compiled Lisp function in `racket-common.el'.

It is bound to }, ], ).

(racket-insert-closing &optional PREFIX)

Insert a matching closing delimiter.

With a prefix, insert the typed character as-is.
greghendershott commented 8 years ago

Of course many people get matching closing delimiters from paredit, smartparens, or (in newer Emacs) electric-pair-mode. The smart open bracket works with all these, and the appeal is just hitting [ and it (hopefully) does the right thing.

Having said that, I don't actually use the smart open bracket feature in racket-mode, myself. I added it on request.