Skip to content

MaskRay/jagger

 
 

Repository files navigation

jagger.el

Move/swap things (including regions, sexps, lines, words) more convenient in Emacs.

Install

Copy file jagger*.el to directory ~/.emacs.d/site-lisp/jagger/, for example, and add this to your .emacs

(add-to-list 'load-path (expand-file-name "~/.emacs.d/site-lisp/jagger"))
(require 'jagger)

Usage

Swap two regions

  • Select region1
  • jagger-swap-regions-mark-region set mark and highlight it with overlay
  • Select region2
  • jagger-swap-regions apply swap, clean overlay

A more natural way is attach swap function to yank. There is a example for evil:

(defun evil-yank@set-mark (begin end &rest argv)
  (jagger-swap-regions-mark-region-1 begin end))

(advice-add 'evil-yank :before 'evil-yank@set-mark)
(define-key evil-visual-state-map (kbd "M-p") 'jagger-swap-regions)

Then you can use it like this:

  • y yank region1 as usual, there is no highlight
  • Select region2
  • M-p to apply swap

Swap things (sexps/words/lines) surround point

(foo| bar) -> (|bar foo)  ;; jagger-swap-sexps

Swap things (sexps/words/lines) surround region

(foo [(qux "quux")] bar) -> (bar (qux "quux")| foo) ;; jagger-swap-sexps

Move things backward/forward at point

(|foo bar) -> (bar |foo) ;; jagger-move-sexp-forward

Move region backward/forward by sexp

([foo] (qux "quux") bar) -> ((qux "quux") [foo] bar) ;; jagger-move-sexp-forward
([foo (qux "quux")] bar) -> (bar [foo (qux "quux")])

Move line up/down

|foo  =>  bar   ;; jagger-move-line-down
bar       |foo

Move region up/down

[foo      qux   ;; jagger-move-line-down
bar]  =>  [foo
qux       bar]

Sort sexps at point in temp buffer

Original bffer:

(foo (qux "quux") bar)

M-x jagger-sort-sexps-at-point-in-temp-buffer switch to temp buffer in other window:

foo               (qux "quux")   ;; M-j/k to move one line at point \
(qux "quux")  =>  bar            ;; or multiple lines in region \down/down
bar               foo

C-c C-c commit changes to original buffer:

((qux "quux") bar foo)

or C-c C-k discard changes.

About

Move/swap things more convenient in Emacs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 99.0%
  • Shell 1.0%