swift-emacs / swift-mode

Emacs support for Apple's Swift programming language.
GNU General Public License v3.0
363 stars 47 forks source link

Support `fill-region` and auto filling #178

Closed taku0 closed 2 years ago

taku0 commented 2 years ago

Support fill-region and auto filling.

We fill only comments and strings.

Removes swift-mode:comment-fill-column in favor of comment-fill-column.


@woolsweater, I have updated swift-mode-fill.el to support fill-region and auto filling. I have a few questions.

Your previous PR essentially do the followings:

A and B is reasonable. No problems here.

For C, why not just setting fill-column locally?

(add-hook 'swift-mode-hook (lambda () (setq-local 'fill-column 80)))

For D, why do you do it with fill-paragraph, rather than just bind swift-mode:comment-fill-function to some key sequence? I have introduced a customization variable swift-mode:fill-paragraph-entire-comment-or-string to reproduce the original behavior of your code.

woolsweater commented 2 years ago

Hello @taku0,

My desired features were:

and I particularly did not want a separate keybinding: I wanted M-q to always "do the right thing" based on the context of point.

That said, it's definitely possible that I did not choose the best way to implement this. 🙂 It was what I ended up with after researching Emacs filling behavior. I do recall that in my testing, comment-fill-column did not seem to have the effect I desired. But I probably missed something.

I have tried out your implementation quickly and it seems to not only have my desired behavior. It also adds a feature I had not achieved yet: preserving indentation for bulleted lists! E.g. when the foo, bar, baz lines are too long here:

/// - parameters:
///   - foo: labore et dolore magna aliqua...
///   - bar: labore et dolore magna aliqua...
///   - quux: labore et dolore magna aliqua...

This seems quite excellent. Thank you for your work on swift-mode!