-
Notifications
You must be signed in to change notification settings - Fork 2
/
general.el
519 lines (408 loc) · 15 KB
/
general.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
;; -----
;; Require misc stuff
;; ------
(require 'nxml-mode)
(require 'python)
(require 'ruby-mode)
(require 'epa-file)
(require 'ibuffer)
(epa-file-enable)
;; ------
;; Place backups in ~/.backups/ directory, like a civilized program.
;; ------
(if (file-directory-p "~/.backup")
(setq backup-directory-alist '(("." . "~/.backup")))
(message "Directory does not exist: ~/.backup"))
(setq backup-by-copying t ; Don't delink hardlinks
delete-old-versions t ; Clean up the backups
version-control t ; Use version numbers on backups,
kept-new-versions 3 ; keep some new versions
kept-old-versions 2) ; and some old ones, too
;; ---------
;; ---------
;; Make debian/ubuntu work nicely with cvs emacs
;; ---------
;; (let ((startup-file "/usr/share/emacs/site-lisp/debian-startup.el"))
;; (if (and (or (not (fboundp 'debian-startup))
;; (not (boundp 'debian-emacs-flavor)))
;; (file-readable-p startup-file))
;; (progn
;; (load-file startup-file)
;; (setq debian-emacs-flavor 'emacs22)
;; (debian-startup debian-emacs-flavor)
;; (mapcar '(lambda (f)
;; (and (not (string= (substring f -3) "/.."))
;; (file-directory-p f)
;; (add-to-list 'load-path f)))
;; (directory-files "/usr/share/emacs/site-lisp" t)))))
;; ---------
;; Generic keybindings
;; ---------
; (please move more here soon)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-c fd") 'find-dired)
(global-set-key (kbd "C-c d") 'diff-buffer-with-file)
(global-set-key (kbd "C-c R") 'revert-buffer)
; These should be made more local when I figure out how
;; Life-hack keybindings
(global-set-key (kbd "C-c lc") 'calendar)
(global-set-key (kbd "C-c lp") 'plan)
;; ------
;; General config BS
;; ------
(setq max-specpdl-size 9000)
(when (not window-system)
;;allow you to see the region when in console mode
(setq transient-mark-mode t))
;; Shell stuff
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(setq ispell-alternate-dictionary "/etc/dictionaries-common/words")
(setq diary-file "~/org/diary")
(setq tex-dvi-view-command
(if (eq window-system 'x) "xdvi" "dvi2tty * | cat -s"))
; tab auto-completion cycling is evil.
(setq pcomplete-cycle-completions nil)
;; Make sure that pressing middle mouse button pastes right at point,
;; not where the mouse cursor is.
(setq mouse-yank-at-point t)
;; Don't show my password when I'm entering it, kthx.
(add-hook 'comint-output-filter-functions
'comint-watch-for-password-prompt)
(put 'downcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(setq inhibit-splash-screen t)
(setq column-number-mode 1)
(setq visual-line-fringe-indicators '(t t))
; Don't switch to another frame with iswitchb
(setq iswitchb-default-method 'samewindow)
; Use diff -u
(setq diff-switches "-u")
;; ------
;; Initialize some things
;; ------
; (display-time)
(server-start)
;; Mouse scrolling
(mwheel-install)
;; Shift-arrowkey based movement
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings))
;; ------
;; Terminal / window specific stuff
;; ------
;; Don't minimize my emacs! Honestly wtf
(when window-system
(progn
(global-unset-key (kbd "C-z"))
(setq scroll-bar-mode nil)
(tool-bar-mode nil)
(menu-bar-mode nil)))
;; ---------
;; Custom funcs
;; ---------
(defun other-window-backward (&optional n)
"Select Nth previous window."
(interactive "P")
(other-window (- (prefix-numeric-value n))))
(defun warn-if-symlink ()
(if (file-symlink-p buffer-file-name)
;progn here to execute both as part of else statement together
(message "File is a symlink")))
(add-hook 'find-file-hooks 'warn-if-symlink)
;; creating a scratch buffer command
(defun create-scratch-buffer nil
"create a scratch buffer"
(interactive)
(switch-to-buffer (get-buffer-create "*scratch*"))
(lisp-interaction-mode)
(insert ";; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
"))
;; If the *scratch* buffer is killed, recreate it automatically
;; FROM: Morten Welind
;;http://www.geocrawler.com/archives/3/338/1994/6/0/1877802/
(save-excursion
(set-buffer (get-buffer-create "*scratch*"))
(lisp-interaction-mode)
(make-local-variable 'kill-buffer-query-functions)
(add-hook 'kill-buffer-query-functions 'kill-scratch-buffer))
(defun kill-scratch-buffer ()
;; The next line is just in case someone calls this manually
(set-buffer (get-buffer-create "*scratch*"))
;; Kill the current (*scratch*) buffer
(remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
(kill-buffer (current-buffer))
;; Make a brand new *scratch* buffer
(set-buffer (get-buffer-create "*scratch*"))
(lisp-interaction-mode)
(make-local-variable 'kill-buffer-query-functions)
(add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
;; Since we killed it, don't let caller do that.
nil)
;; Highlight previous (or current?) line
(defun pg-uline (ulinechar)
"Underline the current or the previous line with ULINECHAR"
(interactive "cUnderline with:")
(if (looking-at "^$")
(next-line -1))
(end-of-line)
(let ((linelen (current-column)))
(insert "\n")
(while (> linelen 0)
(setq linelen (1- linelen))
(insert ulinechar)))
(insert "\n"))
(global-set-key (kbd "C-c u") 'pg-uline)
;; Swapping buffers! Can't live without this
(setq cwebber/swapping-buffer nil)
(setq cwebber/swapping-window nil)
(defun cwebber/swap-buffers-in-windows ()
"Swap buffers between two windows"
(interactive)
(if (and cwebber/swapping-window
cwebber/swapping-buffer)
(let ((this-buffer (current-buffer))
(this-window (selected-window)))
(if (and (window-live-p cwebber/swapping-window)
(buffer-live-p cwebber/swapping-buffer))
(progn (switch-to-buffer cwebber/swapping-buffer)
(select-window cwebber/swapping-window)
(switch-to-buffer this-buffer)
(select-window this-window)
(message "Swapped buffers."))
(message "Old buffer/window killed. Aborting."))
(setq cwebber/swapping-buffer nil)
(setq cwebber/swapping-window nil))
(progn
(setq cwebber/swapping-buffer (current-buffer))
(setq cwebber/swapping-window (selected-window))
(message "Buffer and window marked for swapping."))))
(global-set-key (kbd "C-c p") 'cwebber/swap-buffers-in-windows)
;; other stuff
(defun add-spaces-to-region (beginning end numspaces)
"Add spaces to a whole region of text"
(interactive "r\nnNumber of spaces: ")
(save-excursion
(goto-char beginning)
(beginning-of-line)
(while (< (point) end)
(let ((bol-point 0)
(eol-point 0))
(save-excursion
(end-of-line)
(setq eol-point (point))
(beginning-of-line)
(setq bol-point (point)))
(if (not (equal bol-point eol-point))
(progn
(beginning-of-line)
(dotimes (i numspaces)
(insert " ")))))
(forward-line)
(beginning-of-line))))
(defun rename-buffer-with-directory (&optional arg)
"Useful for when you're dealing with multiple files with the
same name in different directories. No more file.txt<2>!
Running this will append the previous directory to the end of
the filename. So for example, if you opened the emacs
ChangeLog (living in the emacs/ directory), you'll get
'ChangeLog(emacs/)'. Using a prefix arg will give you number
of subdirectories, if you need it.
If you are accessing a file over Tramp, it will add 'host:' to
the parenthesis.. so if you were accessing
/ssh:example.org:/home/foobar/emacs/ChangeLog, you'd get:
'ChangeLog(example.org:emacs/)'"
(interactive "^p")
(let ((dir-name nil)
(split-path (eshell-split-path
(file-name-directory (buffer-file-name))))
(tramp-data (condition-case nil
(tramp-dissect-file-name (buffer-file-name))
(error nil))))
(setq dir-name
(apply 'concat (nthcdr (- (length split-path) arg) split-path)))
(rename-buffer
(concat (file-name-nondirectory (buffer-file-name))
(if tramp-data
(concat
"(" (aref tramp-data 2) ":" dir-name ")")
(concat "(" dir-name ")"))))))
(defun insert-virtualenv-load-line (virtualenv-dir)
(interactive "DVirtualenv directory: ")
(let ((activate-file (expand-file-name (concat virtualenv-dir "./bin/activate_this.py"))))
(if (file-exists-p activate-file)
(insert
(concat "execfile('" activate-file
"', dict(__file__='" activate-file "'))"))
(error "No ./bin/activate_this.py in that virtualenv (maybe update virtualenv?)"))))
; (global-set-key (kbd "C-c r") 'rename-buffer-with-directory)
(defun blender-style ()
(interactive)
(c-set-style "bsd")
(setq indent-tabs-mode t)
(setq tab-width 4)
(setq c-basic-offset 4))
;; En1arg3 y0ur w1|\|dow!!!
(defun undo-or-shrink-horizontally ()
"Either undo or shrink horizontally, depending on whether we're
in X or in a terminal"
(interactive)
(if (window-system)
(shrink-window-horizontally)
(undo)))
(global-set-key (kbd "C-=") 'enlarge-window)
(global-set-key (kbd "C--") 'shrink-window)
(global-set-key (kbd "C-+") 'enlarge-window-horizontally)
(global-set-key (kbd "C-_") 'undo-or-shrink-horizontally)
(global-set-key (kbd "C-c x") 'execute-extended-command)
(global-set-key [S-prior] 'beginning-of-buffer)
(global-set-key [S-next] 'end-of-buffer)
;; Apparently I'm a crufty old timer who likes the way the old mouse
;; and x11 pasting worked. This sets it back
(global-set-key [mouse-2] 'mouse-yank-at-click)
(setq mouse-drag-copy-region t
select-active-regions nil
x-select-enable-primary t
x-select-enable-clipboard nil)
;; I also like my scrollbars on the left, thanks!
(set-scroll-bar-mode 'right)
;; ----------
;; Mail stuff
;; ----------
(setq mail-source-movemail-program "/usr/bin/movemail")
; Randomly choose mail signature
(setq cwebber-mail-sigs
'("The bottom line."
"http://dustycloud.org/"))
(defun cwebber-random-mail-sig ()
(nth (random (length cwebber-mail-sigs))
cwebber-mail-sigs))
;(setq mail-signature 'cwebber-random-mail-sig)
;(setq message-signature 'cwebber-random-mail-sig)
(setq mail-signature nil)
(setq message-signature nil)
;; ---------
;; Load some custom stuff
;; ---------
(defun insert-ellipsis ()
(interactive)
(insert "…"))
(global-set-key (kbd "C-c ;") 'insert-ellipsis)
; Always compose mail with gnus. *ALWAYS*.
(setq read-mail-command 'gnus)
(setq mail-user-agent 'gnus-user-agent)
; Turn off tool-bar-mode, which is slow
(call-interactively 'tool-bar-mode)
;; UTF-8 support
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; copy-pasta
(setq x-select-enable-clipboard t)
;; highlight current line
;; Kinda cool but not really needed right now
; (global-hl-line-mode +1)
; lock files borking git-annex-assistant autocommits. Disabling for now.
;; We can re-enable both of these once .gitignore support comes to git-annex
(setq create-lockfiles nil)
; Similarly with auto-save files :(
(setq auto-save-default nil)
;; How did electric-indent-mode get turned on? Why the hell would i want that
(setq electric-indent-mode nil)
;; shift + arrow based window nav
(windmove-default-keybindings)
;; Not sure where else to put this, but hey
(defun open-srfi (srfi-num)
"Open srfi at SRFI-NUM in eww"
(interactive "nSRFI number: ")
(eww (concat "http://srfi.schemers.org/srfi-"
(int-to-string srfi-num)
"/srfi-"
(int-to-string srfi-num) ".html")))
;; Heart-and-stars page breaks!
(defun heart-and-stars-pagebreaks ()
"Replace that boring ^L character with a sparklebutt explosion"
(interactive)
(progn
(unless buffer-display-table
(setq buffer-display-table (make-display-table)))
(aset buffer-display-table ?\^L
(vconcat
(mapcar (lambda (c)
(make-glyph-code c 'escape-glyph))
".✯⁂♥♥♥⁂✯.")))))
(setq page-break-lines-char ?…)
(defun insert-uuid ()
"Insert a uuid string at point"
(interactive)
(insert (org-id-uuid)))
;; The most important thing in this whole file
(require 'tetris)
(define-key tetris-mode-map (kbd "<down>") 'tetris-rotate-next)
;; By default, we almost always want spaces not tabs.
(setq indent-tabs-mode nil)
;; Don't annoy office mates
(setq visible-bell t)
;; Don't produce weird hanging in comint buffers
(setq comint-process-echoes nil)
(defun disable-comint-process-echoes ()
(interactive)
(setq comint-process-echoes nil))
(add-hook 'inferior-lisp-mode-hook
'disable-comint-process-echoes)
;; This is I guess how you turn on tab-based indentation in racket-mode...
;; doesn't seem to hurt anything else...
(setq tab-always-indent 'complete)
;; Lambda insertion
(defun cwebber/lambda-insert ()
(interactive)
(insert-char ?\()
(insert-char ?λ)
(insert " (")
(let ((return-to (point)))
(insert "))")
(goto-char return-to)))
(global-set-key (kbd "C-c y") 'cwebber/lambda-insert)
;; Highlight glyphless characters, eg ZERO-WIDTH SPACE
(set-face-background 'glyphless-char "red")
;; The old "open in firefox" code no longer seemed to work so trying this...
(defun cwebber/open-in-firefox (url &optional new-window)
;; prevent someone passing in extra command line arguments as an attack
(if (equal (substring-no-properties url 0 1)
"-")
(error "Attempted to open URL with preceding dashes"))
(start-process (concat "firefox " url)
nil
(executable-find browse-url-firefox-program)
(if new-window
"--new-window"
"--new-tab")
url))
(setq browse-url-browser-function 'cwebber/open-in-firefox)
;; Make calendar show week numbers?!
(setq calendar-week-start-day 1
calendar-intermonth-text
'(propertize
(format "%2d"
(car
(calendar-iso-from-absolute
(calendar-absolute-from-gregorian (list month day year)))))
'font-lock-face 'font-lock-function-name-face))
(setq kill-ring-max 256)
;; Only generate line numbers as needed...
(setq linum-format 'dynamic)
(defun narrow-to-sentence ()
(interactive)
(backward-sentence)
(let ((original-point (point)))
(let ((start (point)))
(forward-sentence)
(narrow-to-region start (point)))
(goto-char original-point)))
(global-set-key (kbd "C-x n S") 'narrow-to-sentence)
;; How on earth did tabs start appearing in my code...
(setq-default indent-tabs-mode nil)