-
Notifications
You must be signed in to change notification settings - Fork 50
/
emacs-startup.el
275 lines (244 loc) · 9.16 KB
/
emacs-startup.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
;;; Emacs initialization file for Raman: -*- lexical-binding: t; -*-
;;{{{ History:
;;; Segre March 22 1991
;;; July 15, 2001 finally cutting over to custom.
;;; August 12, 2007: Cleaned up for Emacs 22
;;; September 2017: Optimized and Cleaned Up
;;; August 2020: Limit code at top-level.
;;}}}
;;{{{ Introduction:
;;; Commentary:
;;; This startup file is set up with the following goals:
;;; 1. Speed up emacs startup
;;; 2. Customize packages via a custom file as far as possible.
;;; 3. Keep the custom settings in a separate file, with a later goal of
;;; turning that into a theme.
;;; 4. After converting to a theme,
;;; Move machine-specific custom settings
;;; into a separate host-specific custom file, thus making the
;;; earlier theme host-independent.
;;; Place host-specific non-customizable bits in default.el.
;;; 4. Define package-specific settings not available via Custom in a
;;; package-specific <package>-prepare.el file.
;;; 5. Install everything from elpa/melpa as far as possible. (vm is an
;;; exception at present) --- I have nearly 200 packages activated.
;;; 6. The startup file is a collection of functions with entry-point tvr-emacs.
;;; 7. The only top-level call is (tvr-emacs).
;;; 8. Function tvr-emacs starts up Emacspeak, and sets up two hooks:
;;; - after-init-hook to do the bulk of the work.
;;; - emacs-startup-hook to set up initial window configuration.
;;; 9. Function tvr-after-init-hook on after-init-hook does the
;;; following:
;;; For efficiency, package-specific setup files are concatenated into
;;; a single file all-prepare.el by make.
;;; - Load package-specific prepare.el files.
;;; - Load the custom settings file.
;;; - Start up things like the emacs server.
;;; - Some of these tasks are done on a separate thread using make-thread.
;;; - The work of loading files etc., is done within macro tvr-time-load
;;; which sets up an efficient environment for loading files and
;;; helps in profiling.
;;}}}
;;{{{ libs, vars:
(require 'cl-lib)
(cl-declaim (optimize (safety 0) (speed 3)))
(require 'dbus)
(defvar tvr-site-lib
(expand-file-name "~/emacs/lisp/site-lisp")
"Site libs.")
(when (file-exists-p tvr-site-lib)
(push tvr-site-lib load-path)
(push (expand-file-name "vm/lisp/" tvr-site-lib) load-path))
(defvar tvr-libs
"all-prepare"
"Libraries that need extra setup.")
;;}}}
;;{{{ Macro: tvr-time-load:
(defmacro tvr-time-load (&rest body)
"Execute body with an environment condusive to fast-loading files.
Produce timing information as the last step."
(declare (indent 1) (debug t))
`(let ((start (current-time))
(file-name-handler-alist nil)
(load-source-file-function nil)
(inhibit-message t)
(gc-cons-threshold 128000000)
(gc-cons-percentage 0.7))
,@body
(message "<%.4f %d gcs %.4f>"
(float-time (time-subtract (current-time) start))
gcs-done gc-elapsed)))
;;}}}
;;{{{ Fixups:
;;; Put psession startup on a separate thread:
(defadvice psession--restore-objects-from-directory (around ems pre act comp)
(make-thread ad-do-it))
(defadvice psession--restore-some-buffers (around ems pre act comp)
(make-thread ad-do-it))
(defadvice system-users (around fix pre act comp)
"Just return user real name."
(ignore ad--addoit-function)
(setq ad-return-value (list user-real-login-name)))
;;; for twittering-mode:
(defalias 'epa--decode-coding-string 'decode-coding-string)
;;}}}
;;{{{ tvr-tabs:
(defsubst tvr-tabs ()
"Set up my tab-bar."
(tab-new)
(tab-rename "Books")
(tab-next)
(tab-rename "Home"))
;;}}}
;;{{{ tvr-shell-bind-keys:
(defsubst tvr-shell-bind-keys ()
"Set up shell mode keys."
(cl-declare (special shell-mode-map))
(cl-loop
for b in
'(
("SPC" comint-magic-space)
("C-c k" comint-clear-buffer))
do
(define-key shell-mode-map (ems-kbd (cl-first b)) (cl-second b))))
;;}}}
;;{{{Functions: emacs-startup-hook, after-init-hook, tvr-customize
(defun tvr-emacs-startup-hook ()
"Emacs startup hook.
Reset gc-cons-threshold to a smaller value and play
startup sound."
(cl-declare (special emacspeak-sounds-directory))
(setq gc-cons-threshold 64000000)
(start-process
"play" nil "aplay"
(expand-file-name "highbells.au" emacspeak-sounds-directory))
(message
"<Emacs started for %s in %.2f seconds with %s gcs (%.2f seconds)>"
user-login-name (read (emacs-init-time)) gcs-done gc-elapsed))
(defun tvr-customize ()
"Customize my emacs.
Use Custom to customize where possible. "
(cl-declare (special custom-file
outline-mode-prefix-map outline-minor-mode-prefix))
(setq outline-minor-mode-prefix "\C-co")
;;; basic look and feel
(setq frame-title-format '(multiple-frames "%b" ("Emacs")))
(mapc
#'(lambda (f) (put f 'disabled nil))
'(list-threads narrow-to-page list-timers upcase-region
downcase-region narrow-to-region eval-expression ))
(prefer-coding-system 'utf-8-emacs)
(cl-loop ;;; global key-bindings
for key in
'(
("<f3>" bury-buffer)
("<f4>" emacspeak-kill-buffer-quietly)
("<f5>" find-file)
("C-c <tab>" hs-toggle-hiding)
("M--" undo-only)
("M-/" dabbrev-expand)
("M-C-c" calendar)
("M-C-j" imenu)
("M-e" emacspeak-wizards-end-of-word)
("M-r" replace-string)
( "M-#" calc-dispatch)
("M-C-v" vm-visit-folder))
do
(global-set-key (ems-kbd (cl-first key)) (cl-second key)))
(cl-loop ;;; shell wizard
for i from 0 to 9 do
(global-set-key (ems-kbd (format "C-c %s" i)) 'emacspeak-wizards-shell-by-key))
;;; Smarten up ctl-x-map
(define-key ctl-x-map "c" 'compile)
(define-key ctl-x-map "u" 'undo-only)
(define-key ctl-x-map (ems-kbd "C-u") 'undo-redo)
(define-key ctl-x-map (ems-kbd "C-d") 'dired-jump)
(define-key ctl-x-map (ems-kbd "C-n") 'forward-page)
(define-key ctl-x-map (ems-kbd "C-p") 'backward-page)
;;; Shell mode bindings:
(with-eval-after-load 'shell (tvr-shell-bind-keys))
;;; Outline Setup:
(with-eval-after-load 'outline
(global-set-key (ems-kbd "C-o") outline-mode-prefix-map) ;;;restore
(define-key outline-mode-prefix-map "o" 'open-line))
(server-start)
(with-eval-after-load 'magit (require 'forge))
(make-thread #'(lambda nil (load "eww")))
(tvr-tabs)
(setq custom-file (expand-file-name "~/.customize-emacs"))
(load-theme 'modus-vivendi t)
(tvr-time-load (when (file-exists-p custom-file) (load custom-file))))
(defun tvr-after-init ()
"Actions to take after Emacs is up and ready."
;;; load library-specific settings, customize, then start things.
(cl-declare (special tvr-libs))
(tvr-time-load
(load tvr-libs)) ;;; load settings not customizable via custom.
(tvr-customize) ;;; customizations
(with-eval-after-load 'yasnippet (yas-reload-all))
(tvr-time-load (load "emacspeak-muggles"))
(when (dbus-list-known-names :session)
(make-thread #'emacspeak-dbus-setup))
(soundscape-toggle)
(emacspeak-wizards-project-shells-initialize))
(defun tvr-text-mode-hook ()
"TVR:text-mode"
(auto-fill-mode)
(abbrev-mode)
(unless (eq major-mode 'org-mode) (orgalist-mode)))
(defun tvr-prog-mode-hook ()
"TVR:prog-mode"
(local-set-key "\C-m" 'newline-and-indent)
(company-mode)
(hs-minor-mode)
(auto-fill-mode)
(cond
((memq major-mode '(emacs-lisp-mode lisp-mode lisp-interaction-mode))
(lispy-mode ))
(t (smartparens-mode)))
(yas-minor-mode)
(abbrev-mode))
;;}}}
;;{{{tvr-emacs:
(defun tvr-emacs ()
"Start up emacs.
This function loads Emacspeak.
Emacs customization and library configuration happens via the after-init-hook. "
(cl-declare (special emacspeak-directory
outloud-default-speech-rate dectalk-default-speech-rate))
(setq outloud-default-speech-rate 125 ; because we load custom at the end
dectalk-default-speech-rate 485)
(unless (featurep 'emacspeak)
(tvr-time-load ;;; load emacspeak:
(load (expand-file-name "~/emacs/lisp/emacspeak/lisp/emacspeak-setup.elc"))))
(cl-pushnew (expand-file-name "tvr/" emacspeak-directory) load-path
:test #'string-equal)
(add-hook 'after-init-hook #'tvr-after-init)
(add-hook 'emacs-startup-hook #'tvr-emacs-startup-hook)) ;end defun tvr-emacs
;;}}}
(tvr-emacs)
;;{{{ Forward Function Declarations:
(declare-function ems-kbd "emacspeak-keymap" (string))
(declare-function yas-reload-all "yasnippet" (&optional no-jit interactive))
(declare-function soundscape-toggle "soundscape" nil)
(declare-function emacspeak-dbus-setup "emacspeak-dbus" nil)
(declare-function emacspeak-wizards-project-shells-initialize "emacspeak-wizards" nil)
;;}}}
(provide 'emacs-startup)
;;{{{ emacs local variables
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(safe-local-variable-values '((folded-file . t))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;;;local variables:
;;;folded-file: t
;;;end:
;;}}}