-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmy-core.el
244 lines (187 loc) · 6.92 KB
/
my-core.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
;; my-core.el
;;
;; The big, beating heart of my little corner of Emacs.
;; General, mostly-plugin-independent settings go here.
(eval-when-compile (require 'cl-lib))
(defvar my-terminal-emulator "alacritty"
"Terminal emulator to be spawned with my-spawn-terminal-here.")
(defvar my-graphical-font
(cond
((eq system-type 'darwin) "Terminus 10")
((eq system-type 'gnu/linux) "Terminus 16"))
"Font used for graphical editing sessions.")
;; Don't show those horrible buttons
(tool-bar-mode -1)
;; break long lines at word boundaries
(visual-line-mode 1)
;; lockfiles are evil.
(setq create-lockfiles nil)
;; also tabs are evil
(setq-default indent-tabs-mode nil)
;; number columns in the status bar
(column-number-mode)
;; require a trailing newline
(setq require-final-newline t)
;; I never look at right-side fringes. Do you?
(if (fboundp 'set-fringe-style) (set-fringe-style '(8 . 0)))
;; don't put intitial text in scratch buffer
(setq initial-scratch-message nil)
;'Woman' > 'man'.
(defalias 'man 'woman)
;; Disable toolbars and splash screens.
(when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;; from <https://github.com/bling/dotemacs/>
(defmacro after (feature &rest body)
"After FEATURE is loaded, evaluate BODY."
(declare (indent defun))
`(eval-after-load ,feature
'(progn ,@body)))
;; make sure $PATH is set correctly
(use-package exec-path-from-shell
:ensure exec-path-from-shell
:config
(progn
(exec-path-from-shell-copy-env "PATH")
(exec-path-from-shell-copy-env "PYTHONPATH")
))
(ignore-errors ;; windows
(exec-path-from-shell-initialize))
;; Hide startup messages
(setq inhibit-splash-screen t
inhibit-startup-echo-area-message t
inhibit-startup-message t)
;; Line numbers!
;; Disable vertical scrollbars in all frames.
(when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;; Disable menu bar for all (trying this out)
(menu-bar-mode -1)
;; Disable the menu bar in console emacs.
(unless (display-graphic-p) (menu-bar-mode -1))
;; Ediff with horizontal splits.
(setq ediff-split-window-function 'split-window-horizontally)
;; I know what I'm doing; don't litter my fscking tree!
(defvar my-auto-save-folder "~/.emacs.d/.saves/"
"Directory used for Emacs backups.")
(setq backup-directory-alist `(("." . "~/.emacs.d/.saves")))
(setq auto-save-file-name-transforms
`((".*" ,my-auto-save-folder t)))
;; Only scroll one line when near the bottom of the screen, instead
;; of jumping the screen around.
(setq scroll-conservatively 9999
scroll-preserve-screen-position t)
;; Let me write `y` or `n` even for important stuff that would normally require
;; me to fully type `yes` or `no`.
(defalias 'yes-or-no-p 'y-or-n-p)
;; Enable the mouse in terminal mode.
(xterm-mouse-mode 1)
;; UTF-8 everything!
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; This isn't a typewriter (even if it is a terminal); one space after sentences,
;; please.
(setq sentence-end-double-space nil)
;; Flash the frame to represent a bell.
(setq visible-bell t)
;; nevermind that's annoying
(setq ring-bell-function 'ignore)
;; The default of 16 is too low. Give me a 64-object mark ring.
;; Across all files, make it 128.
(setq mark-ring-max 64)
(setq global-mark-ring-max 128)
;; Display the current function name in the modeline.
(which-function-mode 0)
;; Show me the new saved file if the contents change on disk when editing.
(global-auto-revert-mode 1)
;; Thanks
;; http://www.jesshamrick.com/2013/03/31/macs-and-emacs/
;; for the my-system-is-x functions below.
(defun my-system-is-mac ()
(interactive)
(string-equal system-type "darwin"))
(defun my-system-is-linux ()
(interactive)
(string-equal system-type "gnu/linux"))
;; Repurposed from
;; <https://github.com/bling/dotemacs/blob/master/config/init-core.el>
(defun my-find-file-check-large-file ()
"Check the size of files when loading, and don't let me break them."
(when (> (buffer-size) (* 1024 1024 1024))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode)))
(defun my-setup-file-defaults ()
"Set the defaults for a new file opening."
(my-find-file-check-large-file)
(setq show-trailing-whitespace t)
(electric-indent-mode 1))
;; Adapted from
;; <https://github.com/bling/dotemacs/blob/master/config/init-core.el>
(defun my-do-not-kill-scratch-buffer ()
"Don't let the scratch buffer die."
(if (member (buffer-name (current-buffer)) '("*scratch*" "*Messages*"))
(progn
(bury-buffer)
nil)
t))
(add-hook 'kill-buffer-query-functions 'my-do-not-kill-scratch-buffer)
(add-hook 'find-file-hook 'my-setup-file-defaults)
(random t) ;; seed
(plist-put minibuffer-prompt-properties
'point-entered 'minibuffer-avoid-prompt)
;; name the title based on the file
(defun my-update-emacs-title ()
"Update the Emacs title based on the current buffer.
If the current buffer is associated with a filename, that filename will be
used to tile the window. Otherwise, the window will be titled based upon the
name of the buffer."
(if (buffer-file-name (current-buffer))
(setq frame-title-format "Emacs - %f")
(setq frame-title-format "Emacs - %b")))
(cl-dolist (hook '(buffer-list-update-hook
change-major-mode-hook
find-file-hook))
(add-hook hook 'my-update-emacs-title))
(defun my-spawn-terminal-here ()
"Open a terminal in the current buffer's directory"
(interactive)
(start-process my-terminal-emulator nil my-terminal-emulator))
(defun my-set-window-font (font)
"Set the frame font to FONT.
FONT is the name of a xft font, like `Monospace-10'."
(interactive "sFont: ")
;; (set-face-attribute 'default nil :height 125 :family "Fira Mono"))
(set-face-attribute 'default nil :height 120 :font font)
(set-frame-font font nil t))
(defun my-use-default-font (&optional frame)
"Set the frame font to the font name in the variable my-graphical-font.
This command only has an effect on graphical frames."
(interactive)
(if (my-system-is-mac)
(set-face-attribute 'default nil
:family "Monaco" :height 100 :weight 'normal))
(when window-system
(my-set-window-font my-graphical-font)))
(add-hook 'after-make-frame-functions 'my-use-default-font)
(my-use-default-font)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-x C-k") 'kill-this-buffer)
(global-set-key (kbd "C-x g") 'my-google)
(global-set-key (kbd "C-c e") 'my-eval-and-replace)
(defun my-setup-help-mode ()
"Setup help mode the way I like it."
(set-fill-column 80))
(add-hook 'help-mode-hook 'my-setup-help-mode)
(when (my-system-is-mac)
(require 'ls-lisp)
(setq ls-lisp-use-insert-directory-program nil))
;; (global-linum-mode 1)
;; TODO: is this a plugin or can we turn it on here?
(use-package undo-tree
:ensure undo-tree
:config (progn
(global-undo-tree-mode)
(setq undo-tree-auto-save-history nil)))
(global-display-line-numbers-mode)
(provide 'my-core)