benknoble / vim-racket

vim bundle for Racket
MIT License
24 stars 4 forks source link

Integrate raco fmt as formatprg #4

Closed benknoble closed 2 years ago

benknoble commented 2 years ago

https://github.com/sorawee/fmt

haoyun commented 1 year ago

I dont't think it's appropriate to set formatprg to be raco fmt. The problem is that formatprg is used by the gq command to format lines. If the selection is not a valid block, then an error will return and will be inserted into the buffer.

Besides, it will prevent the vim internal format, e.g., line wrap (textwidth), for comment blocks.

Moreover, not everyone has fmt installed.

Instead, raco fmt can be called by many other format tools specific to formatting.

Perhaps I am wrong, but I hope at least it can be configured to be opt-in.

benknoble commented 1 year ago

I dont't think it's appropriate to set formatprg to be raco fmt. The problem is that formatprg is used by the gq command to format lines. If the selection is not a valid block, then an error will return and will be inserted into the buffer.

Besides, it will prevent the vim internal format, e.g., line wrap (textwidth), for comment blocks.

You can always use gw instead, which is gq but

Since raco fmt is a formatting program for Racket, it makes a good 'formatprg'.

Moreover, not everyone has fmt installed.

If you're working with Racket, you can run raco pkg install fmt and be done?

Instead, raco fmt can be called by many other format tools specific to formatting.

I don't follow. The 'formatprg'/'formatexpr'/gq operator are "format tools specific to formatting."

Perhaps I am wrong, but I hope at least it can be configured to be opt-in.

This is at least opt-out, as with anything: simply put the following in ~/.vim/after/ftplugin/racket.vim:

setlocal formatprg=
haoyun commented 1 year ago

You can always use gw instead.

That's muscle memeory.

If you're working with Racket, you can run raco pkg install fmt and be done?

Of course I can install it and i do have it installed. However, having it hardcoded into the vimplugin essentially declares that fmt is a dependency of this plugin.

I don't follow. The 'formatprg'/'formatexpr'/gq operator are "format tools specific to formatting."

Yes. However, searching formatexpr in vim/neovim's installation, only 4 results:

ftplugin/awk.vim
36:    setlocal formatprg=gawk\ -f-\ -o/dev/stdout

ftplugin/lprolog.vim
18:setlocal efm=%+A./%f:%l.%c:\ %m formatprg=fmt\ -w75\ -p\\%
21:setlocal formatprg=fmt\ -w75\ -p\\%

ftplugin/modula3.vim
18:setlocal formatprg=m3pp

ftplugin/racket.vim
26:setlocal formatprg=raco\ fmt

I cannot say much about modula-3, however, the other two ftplugin uses standard tools (fmt form GNU coreutils, when editing awk, one highly likely has gawk), only racket, depends on a tool that has to be separatedly installed. All the other ftplugins for 270+ languages, never set formatprg. So, I think it's not a common practice to set formatprg in such a ftplugin.

benknoble commented 1 year ago

I don't have gawk. That's an external package. Same for m3pp. I expect fmt is relatively standard, but it isn't POSIX.

My point is, there's nothing that makes this a dependency of the plugin (you can choose not to use it, as I've shown), and it's not entirely non-standard (try grepping format\(expr\|prg\) in the runtime files, not to mention other plugins). gq is to format, possibly via programs or expressions. I'm not sure if there's much more to say.

haoyun commented 1 year ago

I am not insisting that I am correct and persude you make the change. But, as I greped, very very few plugins set expr or prg: 4 expr: ftplugin/rmd, ftplugin/st, ftplugin/xml, indent/typescript, and 4 prg. All other apperances are in variaous documentations. If I were writting such a plugin that provides basic ftdetect, syntax, indent, ..., I wouldn't set a format tool in it. What's more importantly, since syntax, indent are already included in vim, I think it would be more helpful to make a PR to vim that changes those ftdetect of *.rkt,*.rktd,*.rktl to racket instead of scheme.

and, simply setlocal formatprg= does not work. Since the formatprg is set in ftplugin, one has to use autocmd to achieve that.

benknoble commented 1 year ago

and, simply setlocal formatprg does not work. Since the formatprg is set in ftplugin, on has to use autocmd to achieve that.

This is my original comment about opting out:

This is at least opt-out, as with anything: simply put the following in ~/.vim/after/ftplugin/racket.vim:

setlocal formatprg=

You missed the = sign and the use of ~/.vim/after/ftplugin/racket.vim, which obviates the need for an autocommand, but you could equally use an autocommand if you want to replicate the functionality that ftplugins already provide (namely, to execute code for filetypes)…


What's more importantly, since syntax, indent are already included in vim, I think it would be more helpful to make a PR to vim that changes those ftdetect of *.rkt,*.rktd,*.rktl to racket instead of scheme.

See #7. This is trickier than you think, because those file extensions aren't all #lang racket and don't all deserve to be treated the same way. In fact the current situation isn't perfect (#5, #6). So I'm not sure I'm ready to submit such a PR, and I'm not sure if Bram &co. are ready to receive it—it represents a major change in the way those extensions are currently detected.