-
Notifications
You must be signed in to change notification settings - Fork 1
/
window.el
88 lines (74 loc) · 2.77 KB
/
window.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
; winner!
(winner-mode)
;; window movement
(global-set-key (kbd "C-S-k") (lambda () (interactive) (other-window 1)))
(global-set-key (kbd "C-S-j") (lambda () (interactive) (other-window -1)))
;; frame movement
(global-set-key "\C-zo" 'other-frame)
;; protect/unprotect the window from modification
(global-set-key "\C-z\C-w"
(lambda ()
(interactive)
(set-window-dedicated-p (selected-window)
(not (window-dedicated-p (selected-window))))
(if (window-dedicated-p (selected-window))
(message "Window protected")
(message "Window unprotected"))))
;; writing mode
(global-set-key "\C-z]"
(lambda ()
(interactive)
(visual-line-mode 1)
(let* ((win (selected-window))
(width (window-total-width win))
(margin (max (/ (- width 78) 2) 0)))
(set-window-margins nil margin margin))))
(global-set-key "\C-z["
(lambda ()
(interactive)
(visual-line-mode -1)
(set-window-margins nil nil nil)))
(global-set-key (kbd "<f7>")
(lambda ()
(interactive)
(split-window-below)
(balance-windows)))
(global-set-key (kbd "<f8>")
(lambda ()
(interactive)
(split-window-right)
(balance-windows)))
;; fix for shell column width after splitting frame
;; see http://stackoverflow.com/questions/7987494/emacs-shell-mode-display-is-too-wide-after-splitting-window
(defun comint-fix-window-size ()
"Change process window size."
(when (derived-mode-p 'comint-mode)
;; by default, ls uses tabs ("for efficiency", according to the
;; GNU docs (wtf?)), and expects them to be eight spaces
(set (make-local-variable 'tab-width) 8)
(let ((proc (get-buffer-process (current-buffer))))
(when proc
(set-process-window-size proc
(window-height)
(window-width))))))
(defun my-shell-mode-hook ()
;; add this hook as buffer local, so it runs once per window.
(add-hook 'window-configuration-change-hook 'comint-fix-window-size nil t))
(add-hook 'shell-mode-hook 'my-shell-mode-hook)
;; convenient buffer rename
(global-set-key (kbd "C-z RET") 'rename-buffer)
;; Disable this stupid suspend key
(global-unset-key (kbd "C-x C-z"))
;; The frame closes without warning if using an emacs server, which is
;; annoying.
(global-unset-key (kbd "C-x C-c"))
;; From https://stackoverflow.com/questions/4716855
;; never shrink windows
(defvar allow-window-shrinking nil
"If non-nil, effectively disable shrinking windows by making `shrink-window-if-larger-than-buffer' a no-op.")
(advice-add 'shrink-window-if-larger-than-buffer
:before-while
(lambda (&rest args)
"Do nothing if `allow-window-shrinking' is nil."
allow-window-shrinking))
(setq frame-title-format "𝓗𝓮'𝓼 𝓰𝓸𝓽 𝓼𝓹𝓪𝓬𝓮 𝓭𝓮𝓶𝓮𝓷𝓽𝓲𝓪")