Have you ever hated having really long chained method calls in heavy OOP languages? or just enjoy avoiding hitting the 80 column margin in any others?
If so, this is the mode for you!
Imagine coming across this mess - who wants to try to mentally parse that out?
$this->setBlub((Factory::get('some-thing', 'with-args'))->inner())->withChained(1, 2, 3);
Hit M-q on the line (after binding it of course for that mode) and it becomes:
$this
->setBlub(
(Factory::get(
'some-thing',
'with-args'))
->inner())
->withChained(
1,
2,
3);
Or maybe you've got a crazy javasript promise chain you're working on?
superagent.get(someUrl).then(response => response.body).catch(reason => console.log(reason))
Again, press M-q on the line and it becomes:
superagent.get(someUrl)
.then(response => response.body)
.catch(reason => console.log(reason))
Clone the repo, then in your Emacs init file:
(add-to-list 'load-path "/path/to/repo")
(require 'prog-fill)
M-x prog-fill ;; to run on current line (ideally, bound to M-q)
After installing, you should bind the function:
(add-hook
'prog-mode-hook
(lambda () (local-set-key (kbd "M-q") #'prog-fill)))
You may find in some modes you want to break right away on a method, while others you do not, for instance in PHP it is common to use:
$this->something
->anotherThing();
Whlie in JS you would usually see:
object
.something
.anotherThing()
The default is nil, meaning it will only break on the second chained call (not the first) - set to t to break on the first.
With this set to t, it will make a parenthesis "float" by itself.
Such as in PHP:
$this->that(
1,
2
);
If set to nil, it will not float, and will appear as:
$this->that(1,
2
);
The default is t, floating parens.
With this set to t, it will make a parenthesis "float" by itself, such as:
$this->that(
1,
2
);
If set to nil, it will not float, and will appear as:
$this->that(
1,
2);
The default is t, floating parens.
This controls the behavior of the auto-indent call - if you disable it (set to nil) this package will not work well, as it will assign the breaks without indenting them.
Controls what is considered a method break - by default it is NOT a
typical list, but a segment of an rx string build '(or "->" ".")
,
which should account for PHP style, JS style, C style and C++ style
(maybe I should add ::
in there, but you can customize if you want
to break on those).
Currently set to '(or ",")
, this determines 'args' - in a non comma
separated language (a lisp) you may want to set this to a space for a
local mode variable, via a setq-local call in that mode's hook list.
- Breaks with matches in comment strings will also break those - need to avoid that! (or you can avoid string literals :) )
GPLv3
Matthew Carter m@ahungry.com