-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcasey.el
591 lines (509 loc) · 20.2 KB
/
casey.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
; This is my super-poopy .emacs file.
; I barely know how to program LISP, and I know
; even less about ELISP. So take everything in
; this file with a grain of salt!
;
; - Casey
; Stop Emacs from losing undo information by
; setting very high limits for undo buffers
(setq undo-limit 20000000)
(setq undo-strong-limit 40000000)
; Determine the underlying operating system
(setq casey-aquamacs (featurep 'aquamacs))
(setq casey-linux (featurep 'x))
(setq casey-win32 (not (or casey-aquamacs casey-linux)))
(setq casey-todo-file "w:/handmade/code/todo.txt")
(setq casey-log-file "w:/handmade/code/log.txt")
(global-hl-line-mode 1)
(set-face-background 'hl-line "midnight blue")
(setq compilation-directory-locked nil)
(scroll-bar-mode -1)
(setq shift-select-mode nil)
(setq enable-local-variables nil)
(setq casey-font "outline-DejaVu Sans Mono")
(when casey-win32
(setq casey-makescript "build.bat")
(setq casey-font "outline-Liberation Mono")
)
(when casey-aquamacs
(cua-mode 0)
(osx-key-mode 0)
(tabbar-mode 0)
(setq mac-command-modifier 'meta)
(setq x-select-enable-clipboard t)
(setq aquamacs-save-options-on-quit 0)
(setq special-display-regexps nil)
(setq special-display-buffer-names nil)
(define-key function-key-map [return] [13])
(setq mac-command-key-is-meta t)
(scroll-bar-mode nil)
(setq mac-pass-command-to-system nil)
(setq casey-makescript "./build.macosx")
)
(when casey-linux
(setq casey-makescript "./build.linux")
(display-battery-mode 1)
)
; Turn off the toolbar
(tool-bar-mode 0)
(load-library "view")
(require 'cc-mode)
(require 'ido)
(require 'compile)
(ido-mode t)
; Setup my find-files
(define-key global-map "\ef" 'find-file)
(define-key global-map "\eF" 'find-file-other-window)
(global-set-key (read-kbd-macro "\eb") 'ido-switch-buffer)
(global-set-key (read-kbd-macro "\eB") 'ido-switch-buffer-other-window)
(defun casey-ediff-setup-windows (buffer-A buffer-B buffer-C control-buffer)
(ediff-setup-windows-plain buffer-A buffer-B buffer-C control-buffer)
)
(setq ediff-window-setup-function 'casey-ediff-setup-windows)
(setq ediff-split-window-function 'split-window-horizontally)
; Turn off the bell on Mac OS X
(defun nil-bell ())
(setq ring-bell-function 'nil-bell)
; Setup my compilation mode
(defun casey-big-fun-compilation-hook ()
(make-local-variable 'truncate-lines)
(setq truncate-lines nil)
)
(add-hook 'compilation-mode-hook 'casey-big-fun-compilation-hook)
(defun load-todo ()
(interactive)
(find-file casey-todo-file)
)
(define-key global-map "\et" 'load-todo)
(defun insert-timeofday ()
(interactive "*")
(insert (format-time-string "---------------- %a, %d %b %y: %I:%M%p")))
(defun load-log ()
(interactive)
(find-file casey-log-file)
(if (boundp 'longlines-mode) ()
(longlines-mode 1)
(longlines-show-hard-newlines))
(if (equal longlines-mode t) ()
(longlines-mode 1)
(longlines-show-hard-newlines))
(end-of-buffer)
(newline-and-indent)
(insert-timeofday)
(newline-and-indent)
(newline-and-indent)
(end-of-buffer)
)
(define-key global-map "\eT" 'load-log)
; no screwing with my middle mouse button
(global-unset-key [mouse-2])
; Bright-red TODOs
(setq fixme-modes '(c++-mode c-mode emacs-lisp-mode))
(make-face 'font-lock-fixme-face)
(make-face 'font-lock-note-face)
(mapc (lambda (mode)
(font-lock-add-keywords
mode
'(("\\<\\(TODO\\)" 1 'font-lock-fixme-face t)
("\\<\\(NOTE\\)" 1 'font-lock-note-face t))))
fixme-modes)
(modify-face 'font-lock-fixme-face "Red" nil nil t nil t nil nil)
(modify-face 'font-lock-note-face "Dark Green" nil nil t nil t nil nil)
; Accepted file extensions and their appropriate modes
(setq auto-mode-alist
(append
'(("\\.cpp$" . c++-mode)
("\\.hin$" . c++-mode)
("\\.cin$" . c++-mode)
("\\.inl$" . c++-mode)
("\\.rdc$" . c++-mode)
("\\.h$" . c++-mode)
("\\.c$" . c++-mode)
("\\.cc$" . c++-mode)
("\\.c8$" . c++-mode)
("\\.txt$" . indented-text-mode)
("\\.emacs$" . emacs-lisp-mode)
("\\.gen$" . gen-mode)
("\\.ms$" . fundamental-mode)
("\\.m$" . objc-mode)
("\\.mm$" . objc-mode)
) auto-mode-alist))
; C++ indentation style
(defconst casey-big-fun-c-style
'((c-electric-pound-behavior . nil)
(c-tab-always-indent . t)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist . ((class-open)
(class-close)
(defun-open)
(defun-close)
(inline-open)
(inline-close)
(brace-list-open)
(brace-list-close)
(brace-list-intro)
(brace-list-entry)
(block-open)
(block-close)
(substatement-open)
(statement-case-open)
(class-open)))
(c-hanging-colons-alist . ((inher-intro)
(case-label)
(label)
(access-label)
(access-key)
(member-init-intro)))
(c-cleanup-list . (scope-operator
list-close-comma
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(label . -4)
(access-label . -4)
(substatement-open . 0)
(statement-case-intro . 4)
(statement-block-intro . c-lineup-for)
(case-label . 4)
(block-open . 0)
(inline-open . 0)
(topmost-intro-cont . 0)
(knr-argdecl-intro . -4)
(brace-list-open . 0)
(brace-list-intro . 4)))
(c-echo-syntactic-information-p . t))
"Casey's Big Fun C++ Style")
; CC++ mode handling
(defun casey-big-fun-c-hook ()
; Set my style for the current buffer
(c-add-style "BigFun" casey-big-fun-c-style t)
; 4-space tabs
(setq tab-width 4
indent-tabs-mode nil)
; Additional style stuff
(c-set-offset 'member-init-intro '++)
; No hungry backspace
(c-toggle-auto-hungry-state -1)
; Newline indents, semi-colon doesn't
(define-key c++-mode-map "\C-m" 'newline-and-indent)
(setq c-hanging-semi&comma-criteria '((lambda () 'stop)))
; Handle super-tabbify (TAB completes, shift-TAB actually tabs)
(setq dabbrev-case-replace t)
(setq dabbrev-case-fold-search t)
(setq dabbrev-upcase-means-case-search t)
; Abbrevation expansion
(abbrev-mode 1)
(defun casey-header-format ()
"Format the given file as a header file."
(interactive)
(setq BaseFileName (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
(insert "#if !defined(")
(push-mark)
(insert BaseFileName)
(upcase-region (mark) (point))
(pop-mark)
(insert "_H)\n")
(insert "/* ========================================================================\n")
(insert " $File: $\n")
(insert " $Date: $\n")
(insert " $Revision: $\n")
(insert " $Creator: Casey Muratori $\n")
(insert " $Notice: (C) Copyright 2014 by Molly Rocket, Inc. All Rights Reserved. $\n")
(insert " ======================================================================== */\n")
(insert "\n")
(insert "#define ")
(push-mark)
(insert BaseFileName)
(upcase-region (mark) (point))
(pop-mark)
(insert "_H\n")
(insert "#endif")
)
(defun casey-source-format ()
"Format the given file as a source file."
(interactive)
(setq BaseFileName (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
(insert "/* ========================================================================\n")
(insert " $File: $\n")
(insert " $Date: $\n")
(insert " $Revision: $\n")
(insert " $Creator: Casey Muratori $\n")
(insert " $Notice: (C) Copyright 2014 by Molly Rocket, Inc. All Rights Reserved. $\n")
(insert " ======================================================================== */\n")
)
(cond ((file-exists-p buffer-file-name) t)
((string-match "[.]hin" buffer-file-name) (casey-source-format))
((string-match "[.]cin" buffer-file-name) (casey-source-format))
((string-match "[.]h" buffer-file-name) (casey-header-format))
((string-match "[.]cpp" buffer-file-name) (casey-source-format)))
(defun casey-find-corresponding-file ()
"Find the file that corresponds to this one."
(interactive)
(setq CorrespondingFileName nil)
(setq BaseFileName (file-name-sans-extension buffer-file-name))
(if (string-match "\\.c" buffer-file-name)
(setq CorrespondingFileName (concat BaseFileName ".h")))
(if (string-match "\\.h" buffer-file-name)
(if (file-exists-p (concat BaseFileName ".c")) (setq CorrespondingFileName (concat BaseFileName ".c"))
(setq CorrespondingFileName (concat BaseFileName ".cpp"))))
(if (string-match "\\.hin" buffer-file-name)
(setq CorrespondingFileName (concat BaseFileName ".cin")))
(if (string-match "\\.cin" buffer-file-name)
(setq CorrespondingFileName (concat BaseFileName ".hin")))
(if (string-match "\\.cpp" buffer-file-name)
(setq CorrespondingFileName (concat BaseFileName ".h")))
(if CorrespondingFileName (find-file CorrespondingFileName)
(error "Unable to find a corresponding file")))
(defun casey-find-corresponding-file-other-window ()
"Find the file that corresponds to this one."
(interactive)
(find-file-other-window buffer-file-name)
(casey-find-corresponding-file)
(other-window -1))
(define-key c++-mode-map [f12] 'casey-find-corresponding-file)
(define-key c++-mode-map [M-f12] 'casey-find-corresponding-file-other-window)
; Alternate bindings for F-keyless setups (ie MacOS X terminal)
(define-key c++-mode-map "\ec" 'casey-find-corresponding-file)
(define-key c++-mode-map "\eC" 'casey-find-corresponding-file-other-window)
(define-key c++-mode-map "\es" 'casey-save-buffer)
(define-key c++-mode-map "\t" 'dabbrev-expand)
(define-key c++-mode-map [S-tab] 'indent-for-tab-command)
(define-key c++-mode-map "\C-y" 'indent-for-tab-command)
(define-key c++-mode-map [C-tab] 'indent-region)
(define-key c++-mode-map " " 'indent-region)
(define-key c++-mode-map "\ej" 'imenu)
(define-key c++-mode-map "\e." 'c-fill-paragraph)
(define-key c++-mode-map "\e/" 'c-mark-function)
(define-key c++-mode-map "\e " 'set-mark-command)
(define-key c++-mode-map "\eq" 'append-as-kill)
(define-key c++-mode-map "\ea" 'yank)
(define-key c++-mode-map "\ez" 'kill-region)
; devenv.com error parsing
(add-to-list 'compilation-error-regexp-alist 'casey-devenv)
(add-to-list 'compilation-error-regexp-alist-alist '(casey-devenv
"*\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) : \\(?:see declaration\\|\\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:\\)"
2 3 nil (4)))
)
(defun casey-replace-string (FromString ToString)
"Replace a string without moving point."
(interactive "sReplace: \nsReplace: %s With: ")
(save-excursion
(replace-string FromString ToString)
))
(define-key global-map [f8] 'casey-replace-string)
(add-hook 'c-mode-common-hook 'casey-big-fun-c-hook)
(defun casey-save-buffer ()
"Save the buffer after untabifying it."
(interactive)
(save-excursion
(save-restriction
(widen)
(untabify (point-min) (point-max))))
(save-buffer))
; TXT mode handling
(defun casey-big-fun-text-hook ()
; 4-space tabs
(setq tab-width 4
indent-tabs-mode nil)
; Newline indents, semi-colon doesn't
(define-key text-mode-map "\C-m" 'newline-and-indent)
; Prevent overriding of alt-s
(define-key text-mode-map "\es" 'casey-save-buffer)
)
(add-hook 'text-mode-hook 'casey-big-fun-text-hook)
; Window Commands
(defun w32-restore-frame ()
"Restore a minimized frame"
(interactive)
(w32-send-sys-command 61728))
(defun maximize-frame ()
"Maximize the current frame"
(interactive)
(when casey-aquamacs (aquamacs-toggle-full-frame))
(when casey-win32 (w32-send-sys-command 61488)))
(define-key global-map "\ep" 'maximize-frame)
(define-key global-map "\ew" 'other-window)
; Navigation
(defun previous-blank-line ()
"Moves to the previous line containing nothing but whitespace."
(interactive)
(search-backward-regexp "^[ \t]*\n")
)
(defun next-blank-line ()
"Moves to the next line containing nothing but whitespace."
(interactive)
(forward-line)
(search-forward-regexp "^[ \t]*\n")
(forward-line -1)
)
(define-key global-map [C-right] 'forward-word)
(define-key global-map [C-left] 'backward-word)
(define-key global-map [C-up] 'previous-blank-line)
(define-key global-map [C-down] 'next-blank-line)
(define-key global-map [home] 'beginning-of-line)
(define-key global-map [end] 'end-of-line)
(define-key global-map [pgup] 'forward-page)
(define-key global-map [pgdown] 'backward-page)
(define-key global-map [C-next] 'scroll-other-window)
(define-key global-map [C-prior] 'scroll-other-window-down)
; ALT-alternatives
(defadvice set-mark-command (after no-bloody-t-m-m activate)
"Prevent consecutive marks activating bloody `transient-mark-mode'."
(if transient-mark-mode (setq transient-mark-mode nil)))
(defadvice mouse-set-region-1 (after no-bloody-t-m-m activate)
"Prevent mouse commands activating bloody `transient-mark-mode'."
(if transient-mark-mode (setq transient-mark-mode nil)))
(defun append-as-kill ()
"Performs copy-region-as-kill as an append."
(interactive)
(append-next-kill)
(copy-region-as-kill (mark) (point))
)
(define-key global-map "\e " 'set-mark-command)
(define-key global-map "\eq" 'append-as-kill)
(define-key global-map "\ea" 'yank)
(define-key global-map "\ez" 'kill-region)
(define-key global-map [M-up] 'previous-blank-line)
(define-key global-map [M-down] 'next-blank-line)
(define-key global-map [M-right] 'forward-word)
(define-key global-map [M-left] 'backward-word)
(define-key global-map "\e:" 'View-back-to-mark)
(define-key global-map "\e;" 'exchange-point-and-mark)
(define-key global-map [f9] 'first-error)
(define-key global-map [f10] 'previous-error)
(define-key global-map [f11] 'next-error)
(define-key global-map "\en" 'next-error)
(define-key global-map "\eN" 'previous-error)
(define-key global-map "\eg" 'goto-line)
(define-key global-map "\ej" 'imenu)
; Editting
(define-key global-map "" 'copy-region-as-kill)
(define-key global-map "" 'yank)
(define-key global-map "" 'nil)
(define-key global-map "" 'rotate-yank-pointer)
(define-key global-map "\eu" 'undo)
(define-key global-map "\e6" 'upcase-word)
(define-key global-map "\e^" 'captilize-word)
(define-key global-map "\e." 'fill-paragraph)
(defun casey-replace-in-region (old-word new-word)
"Perform a replace-string in the current region."
(interactive "sReplace: \nsReplace: %s With: ")
(save-excursion (save-restriction
(narrow-to-region (mark) (point))
(beginning-of-buffer)
(replace-string old-word new-word)
))
)
(define-key global-map "\el" 'casey-replace-in-region)
(define-key global-map "\eo" 'query-replace)
(define-key global-map "\eO" 'casey-replace-string)
; \377 is alt-backspace
(define-key global-map "\377" 'backward-kill-word)
(define-key global-map [M-delete] 'kill-word)
(define-key global-map "\e[" 'start-kbd-macro)
(define-key global-map "\e]" 'end-kbd-macro)
(define-key global-map "\e'" 'call-last-kbd-macro)
; Buffers
(define-key global-map "\er" 'revert-buffer)
(define-key global-map "\ek" 'kill-this-buffer)
(define-key global-map "\es" 'save-buffer)
; Compilation
(setq compilation-context-lines 0)
(setq compilation-error-regexp-alist
(cons '("^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) : \\(?:fatal error\\|warnin\\(g\\)\\) C[0-9]+:" 2 3 nil (4))
compilation-error-regexp-alist))
(defun find-project-directory-recursive ()
"Recursively search for a makefile."
(interactive)
(if (file-exists-p casey-makescript) t
(cd "../")
(find-project-directory-recursive)))
(defun lock-compilation-directory ()
"The compilation process should NOT hunt for a makefile"
(interactive)
(setq compilation-directory-locked t)
(message "Compilation directory is locked."))
(defun unlock-compilation-directory ()
"The compilation process SHOULD hunt for a makefile"
(interactive)
(setq compilation-directory-locked nil)
(message "Compilation directory is roaming."))
(defun find-project-directory ()
"Find the project directory."
(interactive)
(setq find-project-from-directory default-directory)
(switch-to-buffer-other-window "*compilation*")
(if compilation-directory-locked (cd last-compilation-directory)
(cd find-project-from-directory)
(find-project-directory-recursive)
(setq last-compilation-directory default-directory)))
(defun make-without-asking ()
"Make the current build."
(interactive)
(if (find-project-directory) (compile casey-makescript))
(other-window 1))
(define-key global-map "\em" 'make-without-asking)
; Commands
(set-variable 'grep-command "grep -irHn ")
(when casey-win32
(set-variable 'grep-command "findstr -s -n -i -l "))
; Smooth scroll
(setq scroll-step 3)
; Clock
(display-time)
; Startup windowing
(setq next-line-add-newlines nil)
(setq-default truncate-lines t)
(setq truncate-partial-width-windows nil)
(split-window-horizontally)
(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.
'(auto-save-default nil)
'(auto-save-interval 0)
'(auto-save-list-file-prefix nil)
'(auto-save-timeout 0)
'(auto-show-mode t t)
'(delete-auto-save-files nil)
'(delete-old-versions (quote other))
'(imenu-auto-rescan t)
'(imenu-auto-rescan-maxout 500000)
'(kept-new-versions 5)
'(kept-old-versions 5)
'(make-backup-file-name-function (quote ignore))
'(make-backup-files nil)
'(mouse-wheel-follow-mouse nil)
'(mouse-wheel-progressive-speed nil)
'(mouse-wheel-scroll-amount (quote (15)))
'(version-control nil))
(define-key global-map "\t" 'dabbrev-expand)
(define-key global-map [S-tab] 'indent-for-tab-command)
(define-key global-map [backtab] 'indent-for-tab-command)
(define-key global-map "\C-y" 'indent-for-tab-command)
(define-key global-map [C-tab] 'indent-region)
(define-key global-map " " 'indent-region)
(defun casey-never-split-a-window
"Never, ever split a window. Why would anyone EVER want you to do that??"
nil)
(setq split-window-preferred-function 'casey-never-split-a-window)
;;(add-to-list 'default-frame-alist '(font . "Liberation Mono-11.5"))
;;(set-face-attribute 'default t :font "Liberation Mono-11.5")
(set-face-attribute 'font-lock-builtin-face nil :foreground "#DAB98F")
(set-face-attribute 'font-lock-comment-face nil :foreground "gray50")
(set-face-attribute 'font-lock-constant-face nil :foreground "olive drab")
(set-face-attribute 'font-lock-doc-face nil :foreground "gray50")
(set-face-attribute 'font-lock-function-name-face nil :foreground "burlywood3")
(set-face-attribute 'font-lock-keyword-face nil :foreground "DarkGoldenrod3")
(set-face-attribute 'font-lock-string-face nil :foreground "olive drab")
(set-face-attribute 'font-lock-type-face nil :foreground "burlywood3")
(set-face-attribute 'font-lock-variable-name-face nil :foreground "burlywood3")
(defun post-load-stuff ()
(interactive)
(menu-bar-mode -1)
(maximize-frame)
(set-foreground-color "burlywood3")
(set-background-color "#161616")
(set-cursor-color "#40FF40")
)
(add-hook 'window-setup-hook 'post-load-stuff t)