-- mode: org; --
#+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD:
[[https://travis-ci.org/IvanMalison/multi-line][file:https://travis-ci.org/IvanMalison/multi-line.svg?branch=master]] [[http://melpa.org/#/multi-line][file:https://melpa.org/packages/multi-line-badge.svg]] [[https://stable.melpa.org/#/multi-line][file:https://stable.melpa.org/packages/multi-line-badge.svg]]
About multi-line aims to provide a flexible framework for automatically multi-lining and single-lining function invocations and definitions, array and map literals and more. It relies on functions that are defined on a per major mode basis wherever it can so that it operates correctly across many different programming languages.
Supported Languages The following languages are officially supported by multi-line
It is likely that multi-line will function pretty well in any language using typical brace/parenthesis/comma syntax, provided that the major mode has properly defined ~forward-sexp~ and ~indent-line~. If you find that multi-line works well without modification in your language of choice please file an issue or submit a pull request to have it added to the list of officially supported languages. * Installation Install from MELPA with ~M-x package-install multi-line~. See the [[https://github.com/milkypostman/melpa][melpa repository]] for details about how to set up MELPA if you have not already done so. * Setup #+BEGIN_SRC emacs-lisp (require ‘multi-line) (global-set-key (kbd “C-c d”) ‘multi-line) #+END_SRC * Usage Execute the ~multi-line~ command (with M-x or a keybinding) inside the body of the expression you wish to multi-line, as show in the demo above. Invoking multi-line multiple times on the same definition will cycle between the different respacing styles that are configured for the current buffer.
When invoked with a prefix argument (~C-u~), multi-line will “single-line” the expression at point, removing all new lines and replacing them with spaces (or the character configured for single lining). * Configuration multi-line can be configured to behave differently depending on the major mode of the current-buffer. The behavior of multi-line is described with a multi-line-strategy object that has three components: a find-strategy, an enter-strategy and a replace-strategy. The ~multi-line-defhook~ macro can be used to set a major mode specific multi-lining strategy. The strategy defined with the defhook will become active in any buffers with the specified mode.
In the following example we set the default multi-lining behavior for the clojure programming language.
#+BEGIN_SRC emacs-lisp (multi-line-defhook clojure (make-instance multi-line-strategy :find (make-instance multi-line-forward-sexp-find-strategy :split-regex “[[:space:]\n]+” :done-regex “[[:space:]]*)]}” :split-advance-fn ‘multi-line-lisp-advance-fn) :respace multi-line-lisp-respacer)) #+END_SRC
This expands to
#+BEGIN_SRC emacs-lisp (eval-and-compile (defvar multi-line-clojure-strategy) (setq multi-line-clojure-strategy (make-instance multi-line-strategy :find (make-instance multi-line-forward-sexp-find-strategy :split-regex “[[:space:]]+” :done-regex “[[:space:]]*)]}” :split-advance-fn ‘multi-line-lisp-advance-fn) :respace multi-line-lisp-respacer)) (defun multi-line-clojure-mode-hook nil (setq-local multi-line-current-strategy multi-line-clojure-strategy)) (add-hook ‘clojure-mode-hook ‘multi-line-clojure-mode-hook t)) #+END_SRC
Users will most often want to configure the respacing portion of the multi-line strategy. If you prefer to always add a newline at every available split point you might set up the default multi-line strategy as follows:
#+BEGIN_SRC emacs-lisp (setq-default multi-line-current-strategy (multi-line-strategy :respace (multi-line-default-respacers (make-instance multi-line-always-newline)))) #+END_SRC ** Built-in Mode Specific Behavior multi-line has some built in mode specific behavior that is enabled by default. The interactive function ~multi-line-disable-mode-hooks~ disables this mode specific behavior.