forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-windows.el
95 lines (72 loc) · 3.46 KB
/
init-windows.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
;;----------------------------------------------------------------------------
;; Navigate window layouts with "C-c <left>" and "C-c <right>"
;;----------------------------------------------------------------------------
(add-hook 'after-init-hook 'winner-mode)
;; Make "C-x o" prompt for a target window when there are more than 2
(require-package 'switch-window)
(setq-default switch-window-shortcut-style 'alphabet)
(setq-default switch-window-timeout nil)
(global-set-key (kbd "C-x o") 'switch-window)
;;----------------------------------------------------------------------------
;; When splitting window, show (other-buffer) in the new window
;;----------------------------------------------------------------------------
(defun split-window-func-with-other-buffer (split-function)
(lexical-let ((s-f split-function))
(lambda (&optional arg)
"Split this window and switch to the new window unless ARG is provided."
(interactive "P")
(funcall s-f)
(let ((target-window (next-window)))
(set-window-buffer target-window (other-buffer))
(unless arg
(select-window target-window))))))
(global-set-key (kbd "C-x 2") (split-window-func-with-other-buffer 'split-window-vertically))
(global-set-key (kbd "C-x 3") (split-window-func-with-other-buffer 'split-window-horizontally))
(defun sanityinc/toggle-delete-other-windows ()
"Delete other windows in frame if any, or restore previous window config."
(interactive)
(if (and winner-mode
(equal (selected-window) (next-window)))
(winner-undo)
(delete-other-windows)))
(global-set-key (kbd "C-x 1") 'sanityinc/toggle-delete-other-windows)
;;----------------------------------------------------------------------------
;; Rearrange split windows
;;----------------------------------------------------------------------------
(defun split-window-horizontally-instead ()
(interactive)
(save-excursion
(delete-other-windows)
(funcall (split-window-func-with-other-buffer 'split-window-horizontally))))
(defun split-window-vertically-instead ()
(interactive)
(save-excursion
(delete-other-windows)
(funcall (split-window-func-with-other-buffer 'split-window-vertically))))
(global-set-key (kbd "C-x |") 'split-window-horizontally-instead)
(global-set-key (kbd "C-x _") 'split-window-vertically-instead)
;; Borrowed from http://postmomentum.ch/blog/201304/blog-on-emacs
(defun sanityinc/split-window()
"Split the window to see the most recent buffer in the other window.
Call a second time to restore the original window configuration."
(interactive)
(if (eq last-command 'sanityinc/split-window)
(progn
(jump-to-register :sanityinc/split-window)
(setq this-command 'sanityinc/unsplit-window))
(window-configuration-to-register :sanityinc/split-window)
(switch-to-buffer-other-window nil)))
(global-set-key (kbd "<f7>") 'sanityinc/split-window)
(defun sanityinc/toggle-current-window-dedication ()
"Toggle whether the current window is dedicated to its current buffer."
(interactive)
(let* ((window (selected-window))
(was-dedicated (window-dedicated-p window)))
(set-window-dedicated-p window (not was-dedicated))
(message "Window %sdedicated to %s"
(if was-dedicated "no longer " "")
(buffer-name))))
(global-set-key (kbd "C-c <down>") 'sanityinc/toggle-current-window-dedication)
(unless (memq window-system '(nt w32))
(windmove-default-keybindings 'control))
(provide 'init-windows)