mooz / js2-mode

Improved JavaScript editing mode for GNU Emacs
GNU General Public License v3.0
1.33k stars 186 forks source link

Feature request: insert closing delimiter #601

Open kengruven opened 7 months ago

kengruven commented 7 months ago

Hello! I'm a longtime on-again/off-again js2-mode user. Recently, I've been writing a lot of programs in Racket, and racket-mode has a very nifty feature that I've come to enjoy: when you type either ) or ], it will figure out the correct closing delimiter from context (whether ) or ] or } or maybe even others) and insert that, so when I'm are at the end of a line or function I can just hit ] several times until everything is closed.

JS has at least the variety of delimiters as Racket, and so I think a similar feature would be tremendously useful here, too. I've only ever been a user of js2-mode, not a developer, so I have no idea how difficult this would be to implement. Anyway, thanks!

dgutov commented 7 months ago

Hi!

I think this might work better as a feature for electric-pair-mode: this mode already watches that any opening paren (or brace, or bracket) that you type is accompanied by its closing counterpart, and it could use similar knowledge (about which characters are paired) to decide whether to replace one closing parentheses type with another, to keep things paired correctly. As an optional feature, of course.

To file a feature request for it, just use M-x report-emacs-bug.