bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#61368: [PATCH] Extend go-ts-mode with support for pre-filling return


From: Eli Zaretskii
Subject: bug#61368: [PATCH] Extend go-ts-mode with support for pre-filling return statements
Date: Wed, 08 Feb 2023 18:30:41 +0200

> Cc: Randy Taylor <dev@rjt.dev>, Theodor Thornhill <theo@thornhill.no>
> From: Evgeni Kolev <evgenysw@gmail.com>
> Date: Wed, 8 Feb 2023 17:27:58 +0200
> 
> This is a patch which adds support to go-ts-mode to insert
> context-aware return statements for the current function. The return
> statements are pre-filled with the Go zero values of the output
> parameters.
> 
> For example, all these return statements are inserted by M-x
> go-ts-mode-insert-return:
> 
> ```
> func f() (x, y, z int) {
>     return 0, 0, 0
> }
> 
> func exotic() (bool, int, myStruct, *int, chan bool, error) {
>     return false, 0, myStruct{}, nil, nil, err
> }
> 
> func closure(numbers []int) {
>     sort.Slice(numbers, func(i, j int) bool {
>         return false
>     })
> }
> ```
> 
> The command go-ts-mode-insert-return is experimentally bound to a key
> C-c C-r ("r" as return statement). It's a user error to run C-c C-r
> outside of a function body.

Instead of a command bound to a special key sequences, would it
perhaps make more sense to add some kind of "electric" behavior to
"normal" keys?  Like perhaps typing RET after inserting "return" would
add the "context-aware return statement"?  Then the user could turn on
the electric behavior with some minor mode, and get this behavior,
while avoiding the need to dedicate a key sequence.

WDYT?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]