Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/colonelpanic8/multi-line
multi-line everything from function invocations and definitions to array and map literals in a wide variety of languages
https://github.com/colonelpanic8/multi-line
emacs emacs-lisp whitespace
Last synced: 3 months ago
JSON representation
multi-line everything from function invocations and definitions to array and map literals in a wide variety of languages
- Host: GitHub
- URL: https://github.com/colonelpanic8/multi-line
- Owner: colonelpanic8
- Created: 2015-11-22T05:15:52.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-07-21T18:15:35.000Z (over 1 year ago)
- Last Synced: 2024-04-13T14:07:03.429Z (9 months ago)
- Topics: emacs, emacs-lisp, whitespace
- Language: Emacs Lisp
- Homepage:
- Size: 194 KB
- Stars: 55
- Watchers: 8
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
# -*- mode: org; -*-
#+HTML_HEAD:
#+HTML_HEAD:#+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]]* Demo
[[https://asciinema.org/a/dwft2l94f75x9l46wmdhbm5lh?t=4][https://asciinema.org/a/dwft2l94f75x9l46wmdhbm5lh.png]]* 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
- C/C++
- clojure
- emacs-lisp
- golang
- java
- javascript
- python
- ruby
- rust
- scalaIt 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_SRCThis 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_SRCUsers 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.