-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiao-func.el
201 lines (170 loc) · 6.12 KB
/
miao-func.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
;;; miao-func.el --- Miao variables -*- lexical-binding: t; -*-
;; This file is not part of GNU Emacs.
;; 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Internal variables and customizable variables.
;;; Code:
(defun miao-append ()
(interactive)
(miao-insert-mode t)
(unless (eolp)
(forward-char)))
(defun miao-insert-begin ()
(interactive)
(beginning-of-line-text)
(miao-insert-mode))
(defun miao-insert-end ()
(interactive)
(end-of-line)
(miao-insert-mode))
(defun miao-leader-quit ()
"miao leader state quit and switch to previous state"
(interactive)
(if miao-leader-mode
(progn
(miao-switch-to-previous-state)
(setq miao--leader-previous-state nil)
(setq miao--leader-keys nil)
(setq overriding-local-map nil))))
(defun miao-mark-word ()
(interactive)
(when-let ((bound (bounds-of-thing-at-point 'word)))
(goto-char (cdr bound))
(set-mark (car bound))))
(defun miao-mark-symbol ()
(interactive)
(when-let ((bound (bounds-of-thing-at-point 'symbol)))
(goto-char (cdr bound))
(set-mark (car bound))))
(defun miao-mark-string ()
(interactive)
(when-let ((bound (bounds-of-thing-at-point 'string)))
(goto-char (cdr bound))
(set-mark (car bound))))
(defun miao-mark-string-inner ()
(interactive)
(when-let ((bound (bounds-of-thing-at-point 'string)))
(goto-char (- (cdr bound) 1))
(set-mark (+ 1 (car bound)))))
(defun miao-mark-list-inner ()
(interactive)
(let ((forward (or (not (region-active-p))
(equal (point) (region-end)))))
(if (region-active-p)
(if forward
(forward-char)
(backward-char)))
(let ((begin
(if (region-active-p)
(condition-case nil
(or (backward-up-list 1 t t) (point))
(error (goto-char (- (region-beginning) (if forward 1 0)))))
(cond ((looking-back "[\])}]") (backward-list))
((looking-at "[\(\[\{]") (point))
(t (or (backward-up-list 1 t t)) (point)))))
(end (scan-sexps (point) 1)))
(if forward
(progn
(goto-char (- end 1))
(set-mark (+ begin 1)))
(goto-char (+ begin 1))
(set-mark (- end 1))))))
(defun miao-mark-list ()
(interactive)
(let ((begin (if (region-active-p)
(or (backward-up-list 1 t t) (point))
(cond ((looking-back "[\])\{]") (backward-list))
((looking-at "[\(\[\{]") (point))
(t (or (backward-up-list 1 t t)) (point)))))
(end (scan-sexps (point) 1)))
(goto-char end)
(set-mark begin)))
(defun miao-toggle-mark-point ()
(interactive)
(if (region-active-p)
(exchange-point-and-mark)))
(defun miao-delete-char ()
(interactive)
(delete-char 1))
(defun miao-quit-window ()
(interactive)
(quit-window))
(defun miao-delete-window ()
(interactive)
(delete-window))
(defun miao-mark-line ()
(interactive)
(if display-line-numbers-mode
(remove-hook 'deactivate-mark-hook (lambda () (display-line-numbers-mode -1)))
(display-line-numbers-mode t)
(add-hook 'deactivate-mark-hook (lambda () (display-line-numbers-mode -1))))
(if (region-active-p)
(if (equal (point) (region-end))
(progn (next-logical-line) (end-of-line))
(progn (previous-logical-line) (beginning-of-line)))
(let ((pos (point))
(begin (pos-bol))
(end (pos-eol)))
(goto-char end)
(set-mark begin))))
(defun miao-cursor-blink ()
(interactive)
(let ((pos (point))
(begin (pos-bol))
(end (pos-eol)))
(goto-char begin)
(set-mark (+ 1 end))
(run-with-idle-timer 0.5
nil
(lambda ()
(if (region-active-p)
(progn
(deactivate-mark)
(goto-char pos)))))))
(defun miao-next-region-item (direction)
(if (region-active-p)
(let ((length (- (region-end) (region-beginning)))
(re (regexp-quote (buffer-substring-no-properties (region-beginning) (region-end)))))
(goto-char (if (> direction 0) (region-end) (region-beginning)))
(setq next (re-search-forward re nil t direction))
(set-mark (+ (point) (* length (- direction)))))))
(defun miao-next-symbol-item (direction)
(if (not (region-active-p))
(when-let* ((bounds (bounds-of-thing-at-point 'symbol))
(begin (car bounds))
(end (cdr bounds)))
(goto-char begin)
(set-mark end)
(miao-next-region-item direction))))
(defun miao-next-item ()
(interactive)
(if (region-active-p)
(miao-next-region-item 1)
(miao-next-symbol-item 1)))
(defun miao-prev-item ()
(interactive)
(if (region-active-p)
(miao-next-region-item -1)
(miao-next-symbol-item -1)))
(defun miao-setup-modeline ()
"Setup indicator appending the return of function
`miao-indicator' to the modeline.
This function should be called after you setup other parts of the mode-line
and will work well for most cases.
If this function is not enough for your requirements,
use `miao-indicator' to get the raw text for indicator
and put it anywhere you want."
(unless (cl-find '(:eval (miao-indicator)) mode-line-format :test 'equal)
(setq-default mode-line-format (append '((:eval (miao-indicator))) mode-line-format))))
(provide 'miao-func)