Skip to content

davidshepherd7/fill-function-arguments

Repository files navigation

fill-function-arguments

Add/remove line breaks between function arguments and similar constructs

actions MELPA MELPA stable

Usage

Put point inside the brackets and call fill-function-arguments-dwim to convert

frobinate_foos(bar, baz, a_long_argument_just_for_fun, get_value(x, y))

to

frobinate_foos(
    bar,
    baz,
    a_long_argument_just_for_fun,
    get_value(x, y)
)

and back.

Also works with arrays ([x, y, z]) and dictionary literals ({a: b, c: 1}).

If no function call is found fill-function-arguments-dwim will call fill-paragraph, so you can replace an existing fill-paragraph keybinding with it.

Recommended binding:

(add-hook 'prog-mode-hook (lambda () (local-set-key (kbd "M-q") #'fill-function-arguments-dwim)))

(note: some modes, e.g. C-derived modes, bind their own fill paragraph function which will override this so for those modes you'll need to bind the key in that specific mode).

Also works well with html/xml tags with some customisation:

(add-hook 'sgml-mode-hook (lambda ()
                          (setq-local fill-function-arguments-first-argument-same-line t)
                          (setq-local fill-function-arguments-argument-sep " ")
                          (local-set-key (kbd "M-q") #'fill-function-arguments-dwim)))

And for lisps:

(add-hook 'emacs-lisp-mode-hook (lambda ()
                                  (setq-local fill-function-arguments-first-argument-same-line t)
                                  (setq-local fill-function-arguments-second-argument-same-line t)
                                  (setq-local fill-function-arguments-last-argument-same-line t)
                                  (setq-local fill-function-arguments-argument-separator " ")))

By default fill function arguments does not fix the indentation for you (I use aggressive-indent-mode for this). You can enable automatic indentation after converting to the multiline form by setting fill-function-arguments-indent-after-fill to t.

Changelog

Unstable

  • Fix not passing along interactive arguments to fill-paragraph.

Related

This is effectively the emacs version of vim-argwrap, although it was developed completely independently.

About

An emacs package to add/remove line breaks between function arguments and similar constructs

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published