-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathinit-look-and-feel.el
321 lines (253 loc) · 9.4 KB
/
init-look-and-feel.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
;;; init-look-and-feel.el --- Look and feel -*- lexical-binding: t -*-
;;; Commentary:
;;
;; Keyboard preferences: remaps existing functions to new keys
;;
;; ----------------- ---------------------------------------------------------
;; Key Definition
;; ----------------- ---------------------------------------------------------
;; ESC Quit (= Ctrl-G)
;; M-g Goto line
;; C-z Undo
;; C-` Kill current buffer (= C-x k)
;;
;; RETURN Return or Return + indent, depending on init-prefs
;; S-RETURN The opposite
;;
;; M-C-l Switch to last buffer
;; C-x C-b Buffer menu with `ibuffer', replacing `list-buffers'
;; C- +/- Zoom
;; C-= Expand region by semantic units
;; M-C-= Contract region by semantic units
;;
;; M-<up> Move selected region up
;; M-<down> Move selected region down
;;
;; F10 Speedbar
;; ----------------- ---------------------------------------------------------
;;; Code:
(eval-when-compile
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))
(exordium-require 'init-prefs)
(require 'cl-lib)
;;; Font
(defun exordium-available-preferred-fonts ()
"Trim the unavailable fonts from the preferred font list."
(cl-remove-if-not (lambda (font-and-size)
(member (car font-and-size) (font-family-list)))
exordium-preferred-fonts))
(defun exordium-font-size ()
"Find the available preferred font size."
(when (exordium-available-preferred-fonts)
(cdar (exordium-available-preferred-fonts))))
(defun exordium-font-name ()
"Find the avaliable preferred font name."
(when (exordium-available-preferred-fonts)
(caar (exordium-available-preferred-fonts))))
(defun exordium-set-font (&optional font size)
"Find the preferred fonts that are available and choose the first one.
Set FONT and SIZE if they are passed as arguments."
(interactive
(list (completing-read (format "Font (default %s): " (exordium-font-name))
(exordium-available-preferred-fonts) nil nil nil nil
(exordium-font-name))
(read-number "Size: " (exordium-font-size))))
(let ((font (or font (exordium-font-name)))
(size (or size (exordium-font-size))))
(when (and font size)
(message "Setting font family: %s, height: %s" font size)
(set-face-attribute 'default nil
:family font
:height size
:weight 'normal)
t))) ;; indicate that the font has been set
(when exordium-preferred-fonts
(exordium-set-font))
(if (daemonp)
(add-hook 'server-after-make-frame-hook #'exordium-set-font))
;;; User interface
;;; Default frame size
(when (and exordium-preferred-frame-width
exordium-preferred-frame-height)
(setq default-frame-alist `((width . ,exordium-preferred-frame-width)
(height . ,exordium-preferred-frame-height))))
;;; Remove the toolbar
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
;;; Only show the menu bar in a graphical window
;;; (we don't want to loose that top line in a tty)
(menu-bar-mode (if (null (window-system)) -1 1))
;;; Remove welcome message
(setq inhibit-startup-message t)
;;; Disable blinking cursor
(when (fboundp 'blink-cursor-mode)
(blink-cursor-mode -1))
;;; Display column number in the modebar
(column-number-mode 1)
;;; Smooth scrolling
(setq scroll-step 1)
(setq scroll-margin 0
scroll-conservatively 100000
scroll-up-aggressively 0.01
scroll-down-aggressively 0.01
scroll-preserve-screen-position t)
;;; Scrollbar
(when (fboundp 'set-scroll-bar-mode)
(if exordium-scroll-bar
(set-scroll-bar-mode `right)
(set-scroll-bar-mode nil)))
;;; Better frame title with buffer name
(setq frame-title-format (concat "%b - emacs@" (system-name)))
;;; Disable beep
;;(setq visual-bell t)
;;; Colorize selection
(transient-mark-mode 'on)
;;; Show matching parentheses
(show-paren-mode t)
;;; Mouse selection
(use-package select
:ensure nil
:custom
(select-enable-clipboard t))
;;; http://www.reddit.com/r/emacs/comments/30g5wo/the_kill_ring_and_the_clipboard/
(setq save-interprogram-paste-before-kill t)
;;; Electric pair: automatically close parenthesis, curly brace etc.
;;; `electric-pair-open-newline-between-pairs'.
(when exordium-enable-electric-pair-mode
(setq electric-pair-open-newline-between-pairs t)
(electric-pair-mode))
;;; Indent with spaces, not tabs
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;;; Autofill at 79 characters
(setq-default fill-column 79)
;;; Wordwrap at word boundadies
;;;(global-visual-line-mode 1)
;; Show only 1 window on startup (useful if you open multiple files)
(add-hook 'emacs-startup-hook #'delete-other-windows t)
;; Remove surrounding quotes for link buttons and stick to the same window
(use-package help
:ensure nil
:defer t
:custom
(help-clean-buttons t)
(help-window-keep-selected t))
;;; Keyboard preferences
;; Use ESC as Control-G
(when exordium-keyboard-escape
(bind-key "ESC" #'keyboard-quit))
;;; Use "y or n" answers instead of full words "yes or no"
(when exordium-enable-y-or-n
(fset 'yes-or-no-p 'y-or-n-p))
;;; Delete selection when typing
(delete-selection-mode t)
;;; Let me scroll the buffer while searching, without exiting the search.
;;; This allows for using C-l during isearch.
(when (boundp 'isearch-allow-scroll)
(setq isearch-allow-scroll t))
;;; Evil-mode
(if exordium-enable-evil-mode
(use-package evil
:commands (evil-mode)
:config
(evil-mode))
;; Evil mode depends in undo-tree, which thinks it should work by default
(when (fboundp 'global-undo-tree-mode)
(global-undo-tree-mode -1)))
(defun insert-gui-primary-selection ()
"If no region is selected, insert current gui selection at point."
(interactive)
(when (not (use-region-p))
(let ((text (gui-get-selection)))
(when text
(push-mark (point))
(insert-for-yank text)))))
(when exordium-enable-insert-gui-primary-selection
(bind-key "M-<insert>" #'insert-gui-primary-selection))
;;; Shortcut keys
(bind-key "M-g" #'goto-line)
(when exordium-keyboard-ctrl-z-undo
(bind-key "C-z" #'undo))
(bind-key "C-`" #'kill-this-buffer)
;;; Meta-Control-L = switch to last buffer
(defun switch-to-other-buffer ()
"Alternates between the two most recent buffers."
(interactive)
(switch-to-buffer (other-buffer)))
(bind-key "M-C-l" #'switch-to-other-buffer)
;;; C-x C-b = ibuffer (better than list-buffers)
(bind-key "C-x C-b" #'ibuffer)
;;; Zoom
(use-package default-text-scale
:bind
("C-+" . #'default-text-scale-increase)
("C--" . #'default-text-scale-decrease)
("C-<mouse-4>" . #'default-text-scale-increase)
("C-<mouse-5>" . #'default-text-scale-decrease))
;;; CUA.
;;; CUA makes C-x, C-c and C-v cut/copy/paste when a region is selected.
;;; Adding shift or doubling the Ctrl-* makes it switch back to Emacs keys.
;;; It also has a nice feature: C-RET for selecting rectangular regions.
;;; If exordium-enable-cua-mode is nil, only the rectangular regions are enabled.
(cond ((eq exordium-enable-cua-mode :region)
(cua-selection-mode t))
(exordium-enable-cua-mode
(cua-mode t)))
;;; Cool extensions
;;; Expand region
(use-package expand-region
:bind
(("C-=" . #'er/expand-region)
("C-M-=" . #'er/contract-region)))
;;; Move regions up and down (from https://www.emacswiki.org/emacs/MoveRegion)
(defun move-region (start end n)
"Move the current region from START to END up or down by N lines."
(interactive "r\np")
(let ((line-text (delete-and-extract-region start end)))
(forward-line n)
(let ((start (point)))
(insert line-text)
(setq deactivate-mark nil)
(set-mark start))))
(defun move-region-up (start end n)
"Move the current region from START to END up by N lines."
(interactive "r\np")
(move-region start end (if (null n) -1 (- n))))
(defun move-region-down (start end n)
"Move the current region from START to END down by N lines."
(interactive "r\np")
(move-region start end (if (null n) 1 n)))
(bind-key "M-<up>" #'move-region-up)
(bind-key "M-<down>" #'move-region-down)
;;; File saving and opening
;; Warn when opening files bigger than 100MB (use nil to disable it entirely)
(setq large-file-warning-threshold 100000000)
;; Propose vlf (Very Large File) as a choice when opening large files
;; (otherwise one can open a file using M-x vlf):
(use-package vlf-setup
:ensure vlf
:defer t)
;; Remove trailing blanks on save
(define-minor-mode delete-trailing-whitespace-mode
"Remove trailing whitespace upon saving a buffer."
:lighter nil
(if delete-trailing-whitespace-mode
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t)
(remove-hook 'before-save-hook #'delete-trailing-whitespace t)))
(define-globalized-minor-mode global-delete-trailing-whitespace-mode
delete-trailing-whitespace-mode
(lambda ()
(delete-trailing-whitespace-mode t))
:group 'exordium)
(when exordium-delete-trailing-whitespace
(global-delete-trailing-whitespace-mode t))
;;; Disable backup files (e.g. file~)
(defun no-backup-files ()
"Disable creation of backup files."
(interactive)
(setq make-backup-files nil))
(unless exordium-backup-files
(no-backup-files))
(provide 'init-look-and-feel)
;;; init-look-and-feel.el ends here