-
Notifications
You must be signed in to change notification settings - Fork 12
/
window-setting.el
380 lines (321 loc) · 13.2 KB
/
window-setting.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
;; Setting By: Hua Liang [ Stupid ET ]
;; email: et@everet.org
;; website: http://EverET.org
;; This is about auto setting window style.
;; You can read the diagram.
;; Time-stamp: <2014-01-28 22:58:53 Tuesday by Hua Liang>
(eval-when-compile (require 'cl))
(winner-mode 1)
;;use meta and direction key to go to the window
(windmove-default-keybindings 'meta)
;; 实现全屏效果,快捷键为f11
(global-set-key [(control f11)] 'my-fullscreen)
(defun my-fullscreen ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_FULLSCREEN" 0))
)
;; 最大化
(defun my-maximized ()
(interactive)
(if (fboundp 'x-send-client-message)
(progn
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
))
)
;; 启动emacs时窗口最大化
(when window-system
(my-maximized))
;; ==================== Transposing Two Buffers ====================
(defun transpose-buffers (arg)
"Transpose the buffers shown in two windows."
(interactive "p")
(let ((selector (if (>= arg 0) 'next-window 'previous-window)))
(while (/= arg 0)
(let ((this-win (window-buffer))
(next-win (window-buffer (funcall selector))))
(set-window-buffer (selected-window) next-win)
(set-window-buffer (funcall selector) this-win)
(select-window (funcall selector)))
(setq arg (if (plusp arg) (1- arg) (1+ arg))))))
;; -------------------- Transposing Two Buffers --------------------
;;==================== window ====================
; +----------+-----------+
; | | |
; | | |
; +----------+-----------+
; | | |
; | | |
; +----------+-----------+
(defun split-window-4()
"Splite window into 4 sub-window"
(interactive)
(if (= 1 (length (window-list)))
(progn (split-window-vertically)
(split-window-horizontally)
(other-window 2)
(split-window-horizontally)
)
)
)
(global-set-key (kbd "C-x 4 4") 'split-window-4)
; +----------------+
; | |
; +----------------+
; | |
; +----------------+
(defun split-window-up-down()
"Splite window into 2 up and down window"
(interactive)
(if (= 1 (length (window-list)))
(progn (split-window-vertically -10)
(other-window 1)
(eshell)
)
))
(global-set-key (kbd "C-x 4 2") 'split-window-up-down)
; +----------+-----------+
; | | |
; | | |
; + +-----------+
; | | |
; | | |
; +----------+-----------+
(defun split-window-3()
"Splite window into 3 sub-window"
(interactive)
(if (= 1 (length (window-list)))
(progn (split-window-horizontally) ;split to left and right
(enlarge-window-horizontally 15) ;make the main window bigger
(other-window 1) ;go to the right window
(split-window-vertically) ;split the right window to two window
(eshell) ;open shell at left top window
(other-window 2) ;go back to origin window
)
)
)
(global-set-key (kbd "C-x 4 3") 'split-window-3)
; +----------------------+ +------------+-----------+
; | | \ | | |
; | | +-------+\ | | |
; +----------+-----------+ +-------+/ | +-----------+
; | | | / | | |
; | | | | | |
; +----------+-----------+ +------------+-----------+
(defun split-v-3 ()
"Change 3 window style from horizontal to vertical"
(interactive)
(select-window (get-largest-window))
(if (= 3 (length (window-list)))
(let ((winList (window-list)))
(let ((1stBuf (window-buffer (car winList)))
(2ndBuf (window-buffer (car (cdr winList))))
(3rdBuf (window-buffer (car (cdr (cdr winList))))))
(message "%s %s %s" 1stBuf 2ndBuf 3rdBuf)
(delete-other-windows)
(split-window-horizontally)
(set-window-buffer nil 1stBuf)
(other-window 1)
(set-window-buffer nil 2ndBuf)
(split-window-vertically)
(set-window-buffer (next-window) 3rdBuf)
(select-window (get-largest-window))
))))
; +------------+-----------+ +----------------------+
; | | | \ | |
; | | | +-------+\ | |
; | +-----------+ +-------+/ +----------+-----------+
; | | | / | | |
; | | | | | |
; +------------+-----------+ +----------+-----------+
(defun split-h-3 ()
"Change 3 window style from vertical to horizontal"
(interactive)
(select-window (get-largest-window))
(if (= 3 (length (window-list)))
(let ((winList (window-list)))
(let ((1stBuf (window-buffer (car winList)))
(2ndBuf (window-buffer (car (cdr winList))))
(3rdBuf (window-buffer (car (cdr (cdr winList))))))
(message "%s %s %s" 1stBuf 2ndBuf 3rdBuf)
(delete-other-windows)
(split-window-vertically)
(set-window-buffer nil 1stBuf)
(other-window 1)
(set-window-buffer nil 2ndBuf)
(split-window-horizontally)
(set-window-buffer (next-window) 3rdBuf)
(select-window (get-largest-window))
))))
; +------------+-----------+ +------------+-----------+
; | | | \ | | |
; | | | +-------+\ | | |
; +------------+-----------+ +-------+/ +------------+ |
; | | / | | |
; | | | | |
; +------------+-----------+ +------------+-----------+
; +------------+-----------+ +------------+-----------+
; | | | \ | | |
; | | | +-------+\ | | |
; | +-----------+ +-------+/ +------------+-----------+
; | | | / | |
; | | | | |
; +------------+-----------+ +------------+-----------+
(defun change-split-type-3 (&optional arg)
"Change 3 window style from horizontal to vertical and vice-versa"
(interactive)
(select-window (get-largest-window))
(if (= 3 (length (window-list)))
(let ((winList (window-list)))
(let ((1stBuf (window-buffer (car winList)))
(2ndBuf (window-buffer (car (cdr winList))))
(3rdBuf (window-buffer (car (cdr (cdr winList)))))
(split-3
(lambda(1stBuf 2ndBuf 3rdBuf split-1 split-2)
"change 3 window from horizontal to vertical and vice-versa"
(message "%s %s %s" 1stBuf 2ndBuf 3rdBuf)
(delete-other-windows)
(funcall split-1)
(set-window-buffer nil 2ndBuf)
(funcall split-2)
(set-window-buffer (next-window) 3rdBuf)
(other-window 2)
(set-window-buffer nil 1stBuf)))
(split-type-1 nil)
(split-type-2 nil)
)
(if (= (window-width) (frame-width))
(setq split-type-1 'split-window-horizontally
split-type-2 'split-window-vertically)
(setq split-type-1 'split-window-vertically
split-type-2 'split-window-horizontally))
(funcall split-3 1stBuf 2ndBuf 3rdBuf split-type-1 split-type-2)
))))
;; (defun change-split-type-2 ()
;; "change between horizonal and vertical"
;; (interactive)
;; (if (= 2 (length (window-list)))
;; (let ((next-buffer (window-buffer (next-window))))
;; (delete-other-windows)
;; (split-window-right)
;; (other-window 0)
;; (set-window-buffer (next-window) next-buffer)
;; (other-window 0)
;; )
;; )
;; )
;; ==================== change-split-type ====================
(defun change-split-type (split-fn &optional arg)
"Change 3 window style from horizontal to vertical and vice-versa"
(let ((bufList (mapcar 'window-buffer (window-list))))
(select-window (get-largest-window))
(funcall split-fn arg)
(mapcar* 'set-window-buffer (window-list) bufList)))
;; -------------------- change-split-type --------------------
; +----------------------+ +---------- +----------+
; | | \ | | |
; | | +-------+\ | | |
; +----------------------+ +-------+/ | | |
; | | / | | |
; | | | | |
; +----------------------+ +---------- +----------+
;
; +--------- +-----------+ +----------------------+
; | | | \ | |
; | | | +-------+\ | |
; | | | +-------+/ +----------------------+
; | | | / | |
; | | | | |
; +--------- +-----------+ +----------------------+
(defun change-split-type-2 (&optional arg)
"Changes splitting from vertical to horizontal and vice-versa"
(interactive "P")
(let ((split-type (lambda (&optional arg)
(delete-other-windows-internal)
(if arg (split-window-vertically)
(split-window-horizontally)))))
(change-split-type split-type arg)))
(defun change-split-type-auto (&optional arg)
"Changes splitting auto"
(interactive "P")
(let ((window-list-length (length (window-list))))
(cond ((= window-list-length 2) (change-split-type-2 arg))
((= window-list-length 3) (change-split-type-3 arg)))
))
;;==================== buffer =====================
; +------------+-----------+ +------------+-----------+
; | | C | \ | | A |
; | | | +-------+\ | | |
; | A |-----------| +-------+/ | B |-----------|
; | | B | / | | C |
; | | | | | |
; +------------+-----------+ +------------+-----------+
;
; +------------------------+ +------------------------+
; | A | \ | B |
; | | +-------+\ | |
; +------------+-----------+ +-------+/ +------------+-----------+
; | B | C | / | C | A |
; | | | | | |
; +------------+-----------+ +------------+-----------+
(defun roll-v-3 (&optional arg)
"Rolling 3 window buffers (anti-)clockwise"
(interactive "P")
(select-window (get-largest-window))
(if (= 3 (length (window-list)))
(let ((winList (window-list)))
(let ((1stWin (car winList))
(2ndWin (car (cdr winList)))
(3rdWin (car (last winList))))
(let ((1stBuf (window-buffer 1stWin))
(2ndBuf (window-buffer 2ndWin))
(3rdBuf (window-buffer 3rdWin)))
(if arg (progn
; anti-clockwise
(set-window-buffer 1stWin 3rdBuf)
(set-window-buffer 2ndWin 1stBuf)
(set-window-buffer 3rdWin 2ndBuf))
(progn ; clockwise
(set-window-buffer 1stWin 2ndBuf)
(set-window-buffer 2ndWin 3rdBuf)
(set-window-buffer 3rdWin 1stBuf))
))))))
(global-set-key (kbd "C-x 4 r") (quote roll-v-3))
;;-------------------- window -------------------
;; ==================== key bindings ====================
(global-set-key (kbd "M-1") 'delete-other-windows)
(global-set-key (kbd "M-2") 'split-window-below)
(global-set-key (kbd "M-3") 'split-window-right)
(global-set-key (kbd "M-0") 'delete-window)
;; (global-unset-key (kbd "C-x 1"))
;; (global-unset-key (kbd "C-x 2"))
;; (global-unset-key (kbd "C-x 3"))
;; (global-unset-key (kbd "C-x 0"))
(global-set-key (kbd "M-4") 'winner-undo)
(global-set-key (kbd "M-5") 'winner-redo)
(global-set-key (kbd "M-6") 'change-split-type-auto) ; 左旋或者右旋
(global-set-key (kbd "M-9") 'transpose-buffers)
(global-set-key (kbd "C-S-j") 'windmove-down)
(global-set-key (kbd "C-S-k") 'windmove-up)
(global-set-key (kbd "C-S-h") 'windmove-left)
(global-set-key (kbd "C-S-l") 'windmove-right)
(global-set-key (kbd "C-M-^") '(lambda ()
(interactive)
(enlarge-window 10)))
(global-set-key (kbd "C-M-&") '(lambda ()
(interactive)
(enlarge-window -10)))
(global-set-key (kbd "C-M-{") '(lambda ()
(interactive)
(enlarge-window-horizontally -20)))
(global-set-key (kbd "C-M-}") '(lambda ()
(interactive)
(enlarge-window-horizontally 20)))
;; -------------------- key bindings --------------------
;; (provide 'window-setting)