void parse(std::vector<float>& io_vertices, std::vector<unsigned>& io_indices) {}
Oftentimes when we code we need to break lines repeatedly as new expressions and statements enter the picture and our rows veer ever-closer to the column limit. We break function signatures, calls, etc., and line up arguments nicely:
void parse(std::vector<float>& io_vertices,
std::vector<unsigned>& io_indices) {}
When it comes to plain text or comments, fill-paragraph
is a lifesaver. Auto-formatting code, on the other hand, is notoriously difficult but not impossible.
Surely someone must've made the effort in Emacs!
I've been (fruitlessly) trying to find a set of commands or a package that can do this for me, in particular for C and C++ like languages. Either attempts are rare or options so obvious that they elude me. This is the simplest solution to doing what I want:
(defun lazy-break-args ()
(interactive)
(let ((tokens (split-string (thing-at-point 'line t) ", ")))
(unless (= (length tokens) 1)
(let* ((breaks (mapcar (lambda (p) (format "%s,\n" p)) (butlast tokens)))
(lines (append breaks (last tokens))))
(move-beginning-of-line nil)
(kill-line 1)
(mapc (lambda (l) (insert l) (indent-according-to-mode)) lines)))))
Clearly this task depends on whatever language it is you're using, but my question is purposefully open to both language-specific packages (up to full-fledged formatters) and home-brew hacks like mine ("break and indent at commas, what the heck!").
Are there any functions in Emacs already, or any packages, that can do this? I don't expect perfection.