Replace move-text with drag-stuff

Just like: https://github.com/emacsfodder/move-text

https://github.com/rejeep/drag-stuff.el
also drags one or more (region) lines up or down.

But it also allows for dragging left and right (across end of lines):
- a word: changing place with the next or previous word.
- a region: moving it one character at a time to the left or right.

Added a new key binding: `SPC x .`
that opens the:
```
Drag Stuff Transient State
[k/K] up    [h/H] left   [q] quit
[j/J] down  [l/L] right
```

The `move-text` package isn't removed, even though it isn't used anymore in
Spacemacs.

Because the `evil-unimpaired` elpa directory is generated from the local
Spacemacs `evil-unimpaired.el` file.
https://github.com/syl20bnr/spacemacs/blob/develop/layers/%2Bspacemacs/spacemacs-evil/local/evil-unimpaired/evil-unimpaired.el

Therefore the `evil-unimpaired` key bindings `[e` and `]e` still call the
`move-text` commands.

Until the `evil-unimpaired` elpa directory has been removed and regenerated by
restarting Spacemacs.

Then they will call the new `drag-stuff` commands.

I don't know if/when the `move-text` package can be removed in the future.
This commit is contained in:
duianto 2021-03-02 17:07:57 +01:00 committed by Maximilian Wolff
parent 589c16b73a
commit 94585331ce
4 changed files with 52 additions and 22 deletions

View File

@ -168,6 +168,7 @@
- [[#paste-transient-state][Paste transient state]]
- [[#auto-indent-pasted-text][Auto-indent pasted text]]
- [[#text-manipulation-commands][Text manipulation commands]]
- [[#drag-stuff-transient-state][Drag stuff transient state]]
- [[#text-insertion-commands][Text insertion commands]]
- [[#smartparens-strict-mode][Smartparens Strict mode]]
- [[#zooming][Zooming]]
@ -2970,6 +2971,7 @@ Text related commands (start with ~x~):
| Key binding | Description |
|---------------+---------------------------------------------------------------|
| ~SPC x .~ | enter the drag stuff transient state |
| ~SPC x TAB~ | indent or dedent a region rigidly |
| ~SPC x a &~ | align region at & |
| ~SPC x a (~ | align region at ( |
@ -3012,8 +3014,8 @@ Text related commands (start with ~x~):
| ~SPC x j l~ | set the justification to left |
| ~SPC x j n~ | set the justification to none |
| ~SPC x j r~ | set the justification to right |
| ~SPC x J~ | move down a line of text (enter transient state) |
| ~SPC x K~ | move up a line of text (enter transient state) |
| ~SPC x J~ | drag down a line of text (enter drag stuff transient state) |
| ~SPC x K~ | drag up a line of text (enter drag stuff transient state) |
| ~SPC x l d~ | duplicate line or region |
| ~SPC x l r~ | randomize lines in region |
| ~SPC x l s~ | sort lines |
@ -3034,6 +3036,17 @@ Text related commands (start with ~x~):
| ~SPC x y~ | use avy to copy a link in the frame |
| ~SPC x Y~ | use avy to copy multiple links in the frame |
**** Drag stuff transient state
The drag stuff transient state is opened with ~SPC x .~:
| Key binding | Description |
|-------------------+-----------------------------|
| ~k~, ~K~, ~Up~ | drag up |
| ~j~, ~J~, ~Down~ | drag down |
| ~h~, ~H~, ~Left~ | drag left (word or region) |
| ~l~, ~L~, ~Right~ | drag right (word or region) |
| ~q~ | quit transient state |
*** Text insertion commands
Text insertion commands (start with ~i~):

View File

@ -132,8 +132,8 @@
;; move selection up and down
(when vim-style-visual-line-move-text
(define-key evil-visual-state-map "J" (concat ":m '>+1" (kbd "RET") "gv=gv"))
(define-key evil-visual-state-map "K" (concat ":m '<-2" (kbd "RET") "gv=gv")))
(define-key evil-visual-state-map "J" 'drag-stuff-down)
(define-key evil-visual-state-map "K" 'drag-stuff-up))
(evil-ex-define-cmd "enew" 'spacemacs/new-empty-buffer)

View File

@ -15,6 +15,7 @@
(bracketed-paste :toggle (version<= emacs-version "25.0.92"))
(clean-aindent-mode :toggle dotspacemacs-use-clean-aindent-mode)
dired-quick-sort
drag-stuff
editorconfig
eval-sexp-fu
expand-region
@ -114,6 +115,35 @@
:config
(evil-define-key 'normal dired-mode-map "s" 'hydra-dired-quick-sort/body)))
(defun spacemacs-editing/init-drag-stuff ()
(use-package drag-stuff
:defer t
:init
(drag-stuff-mode t)
(spacemacs|define-transient-state drag-stuff
:title "Drag Stuff Transient State"
:doc "
[_k_/_K_] up [_h_/_H_] left [_q_] quit
[_j_/_J_] down [_l_/_L_] right"
:bindings
("j" drag-stuff-down)
("J" drag-stuff-down)
("<down>" drag-stuff-down)
("k" drag-stuff-up)
("K" drag-stuff-up)
("<up>" drag-stuff-up)
("h" drag-stuff-left)
("H" drag-stuff-left)
("<left>" drag-stuff-left)
("l" drag-stuff-right)
("L" drag-stuff-right)
("<right>" drag-stuff-right)
("q" nil :exit t))
(spacemacs/set-leader-keys
"x." 'spacemacs/drag-stuff-transient-state/body
"xK" 'spacemacs/drag-stuff-transient-state/drag-stuff-up
"xJ" 'spacemacs/drag-stuff-transient-state/drag-stuff-down)))
(defun spacemacs-editing/init-editorconfig ()
(use-package editorconfig
:init
@ -226,18 +256,7 @@
"ilp" 'lorem-ipsum-insert-paragraphs
"ils" 'lorem-ipsum-insert-sentences))))
(defun spacemacs-editing/init-move-text ()
(use-package move-text
:defer t
:init
(spacemacs|define-transient-state move-text
:title "Move Text Transient State"
:bindings
("J" move-text-down "move down")
("K" move-text-up "move up"))
(spacemacs/set-leader-keys
"xJ" 'spacemacs/move-text-transient-state/move-text-down
"xK" 'spacemacs/move-text-transient-state/move-text-up)))
(defun spacemacs-editing/init-move-text ())
(defun spacemacs-editing/init-origami ()
(use-package origami

View File

@ -85,12 +85,10 @@
'evil-unimpaired/insert-space-above)
(define-key evil-normal-state-map (kbd "] SPC")
'evil-unimpaired/insert-space-below)
(define-key evil-normal-state-map (kbd "[ e") 'move-text-up)
(define-key evil-normal-state-map (kbd "] e") 'move-text-down)
(define-key evil-visual-state-map (kbd "[ e") ":move'<--1")
(define-key evil-visual-state-map (kbd "] e") ":move'>+1")
;; (define-key evil-visual-state-map (kbd "[ e") 'move-text-up)
;; (define-key evil-visual-state-map (kbd "] e") 'move-text-down)
(define-key evil-normal-state-map (kbd "[ e") 'drag-stuff-up)
(define-key evil-normal-state-map (kbd "] e") 'drag-stuff-down)
(define-key evil-visual-state-map (kbd "[ e") 'drag-stuff-up)
(define-key evil-visual-state-map (kbd "] e") 'drag-stuff-down)
;; navigation
(define-key evil-motion-state-map (kbd "[ b") 'previous-buffer)
(define-key evil-motion-state-map (kbd "] b") 'next-buffer)