tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.75k stars 139 forks source link

Comment re-formatting (e.g., with gq) doesn't respect 'textwidth' #299

Closed bpstahlman closed 6 years ago

bpstahlman commented 7 years ago

I normally use gqgq to re-format comments in source files, but this isn't working for clojure files now that I've installed fireplace. To reformat a comment line that's too long, I have to go to the desired column position and insert a linebreak manually, which is very tedious for long comments. I haven't researched it in depth yet, but I can see that fireplace is setting formatexpr to...

fireplace#format(v:lnum,v:count,v:char)

...and a cursory inspection of fireplace#format suggests it may be sending text off for processing by the lisp client. Is this the case? Is there a way to disable this behavior, or some sort of tweak I could perform to have comments formatted according to 'formatoptions'?

tpope commented 7 years ago

We should definitely abort early in fireplace#format when inside a comment. A PR would be great. In the meantime, you can work around by using gw instead.

bpstahlman commented 7 years ago

Makes sense. Thanks. I'm in the middle of some PR's for another plugin at the moment, but perhaps if this issue is still open when I finish up, I'll have a look...

justone commented 6 years ago

I’ve run into this too. Glad there is a workaround.

I’ve noticed the same thing happens in long docstrings, although those might be harder to detect for short circuiting.

tpope commented 6 years ago

Yeah docstrings will be tricky. You might want to patch up the common case with nmap gqa" gwa" and/or nmap gqi" gwi".

The comment thing is potentially as trivial as adding || getline(a:lnum) =~# '^\s*;' to the first conditional, unless I'm missing something.

justone commented 6 years ago

That did work. PR submitted.

tpope commented 6 years ago

For doc strings probably the best bet will be a regexp checking that code is a single string. Off the top of my head, something like ^\s*"\%(\\.\|[^"]\)*"\s*$