-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcool-moves.el
143 lines (117 loc) · 3.39 KB
/
cool-moves.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
;;; cool-moves.el --- This package moves stuff -*- lexical-binding: t; -*-
;; Copyright (C) 2019
;; Author: Davi Ramos <[email protected]>
;; Keywords: lisp
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This is a package to move text around. It uses basic functions to
;; move words, lines, paragraphs, sentences and sexps forward and
;; backward.
;;; Code:
(defun cool-moves/line-backward ()
"Move line up."
(interactive)
(transpose-lines 1)
(forward-line -2))
(defun cool-moves/line-forward ()
"Move line down."
(interactive)
(forward-line 1)
(transpose-lines 1)
(forward-line -1))
(defun cool-moves/paragraph-forward ()
"Move paragraph down."
(interactive)
(transpose-paragraphs 1)
(backward-paragraph)
(forward-line))
(defun cool-moves/paragraph-backward ()
"Move paragraph up."
(interactive)
(transpose-paragraphs -1)
(backward-paragraph)
(forward-line))
(defun cool-moves/word-backwards ()
"Move word backwards."
(interactive)
(backward-to-word 1)
(transpose-words 1)
(backward-word-strictly 2))
(defun cool-moves/word-forward ()
"Move word forward."
(interactive)
(forward-to-word 1)
(transpose-words 1)
(backward-word))
(defun cool-moves/sentence-backward ()
"Move sentence backward."
(interactive)
(transpose-sentences 1)
(backward-sentence 2))
(defun cool-moves/sentence-forward ()
"Move sentence forward."
(interactive)
(forward-sentence 1)
(transpose-sentences 1)
(backward-sentence))
(defun cool-moves/sexp-backward ()
"Move sexp backward."
(interactive)
(transpose-sexps 1)
(backward-sexp 2))
(defun cool-moves/sexp-forward ()
"Move sexp forward."
(interactive)
(forward-sexp 1)
(transpose-sexps 1)
(backward-sexp))
(defun cool-moves/character-backward ()
"Move character backward."
(interactive)
(transpose-chars 1)
(backward-char 2))
(defun cool-moves/character-forward ()
"Move character forward."
(interactive)
(forward-char 1)
(transpose-chars 1)
(backward-char))
;; Adapted from: https://www.emacswiki.org/emacs/OpenNextLine"
(defun cool-moves/open-line-above ()
"Go to previous line and then open a new one."
(interactive)
(forward-line -1)
(end-of-line)
(newline 1))
(defun cool-moves/open-line-below (arg)
"Go to next line and then open a new one.
Writing ARG just because I hate seeing the
flycheck error."
(interactive "p")
(end-of-line)
(open-line arg)
(forward-line 1))
(defun cool-moves/move-line-up ()
"Move up the current line."
(interactive)
(transpose-lines 1)
(forward-line -2)
(indent-according-to-mode))
(defun cool-moves/move-line-down ()
"Move down the current line."
(interactive)
(forward-line 1)
(transpose-lines 1)
(forward-line -1)
(indent-according-to-mode))
(provide 'cool-moves)
;;; cool-moves.el ends here