Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emacsfodder/move-text
move current line or region up or down
https://github.com/emacsfodder/move-text
emacs emacs-lisp text-manipulation
Last synced: 3 months ago
JSON representation
move current line or region up or down
- Host: GitHub
- URL: https://github.com/emacsfodder/move-text
- Owner: emacsfodder
- Created: 2016-02-12T02:46:24.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-04T15:14:19.000Z (12 months ago)
- Last Synced: 2024-02-16T08:34:15.615Z (9 months ago)
- Topics: emacs, emacs-lisp, text-manipulation
- Language: Emacs Lisp
- Homepage:
- Size: 1.28 MB
- Stars: 177
- Watchers: 6
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Move-Text CI Tests](https://github.com/emacsfodder/move-text/actions/workflows/test.yml/badge.svg)](https://github.com/emacsfodder/move-text/actions/workflows/test.yml)
[![MELPA](https://melpa.org/packages/move-text-badge.svg)](https://melpa.org/#/move-text)
[![MELPA Stable](https://stable.melpa.org/packages/move-text-badge.svg)](https://stable.melpa.org/#/move-text)# Move Text
MoveText
allows you to move the current line using M-up / M-down (or any other bindings you choose)
if a region is marked, it will move the region instead.Using the prefix arg (C-u *number* or META *number*) will predetermine how many lines to move.
Install from MELPA (or MELPA stable)
```
M-x package-install move-text
```If you want to use the default bindings, add the following to .emacs
anywhere after `(package-initialize)`:```
(move-text-default-bindings)
```
This sets the keyboard shortcuts:- Meta-up `move-text-up` (line or active region)
- Meta-down `move-text-down` (line or active region)## Demonstration
![](move-text.gif)
### Indent after moving...
[@jbreeden](https://github.com/jbreeden) gave us this useful function advice to have Emacs re-indent the text in-and-around a text move.
```lisp
(defun indent-region-advice (&rest ignored)
(let ((deactivate deactivate-mark))
(if (region-active-p)
(indent-region (region-beginning) (region-end))
(indent-region (line-beginning-position) (line-end-position)))
(setq deactivate-mark deactivate)))(advice-add 'move-text-up :after 'indent-region-advice)
(advice-add 'move-text-down :after 'indent-region-advice)
```