dot/emacs: Save minibuffer history, and retain more of it.
[profile] / dot / emacs
1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
2 ;;;
3 ;;; Emacs configuration file
4 ;;;
5 ;;; (c) 1996-1999 Mark Wooding
6 ;;;
7
8 ;;;----- Licensing notice ---------------------------------------------------
9 ;;;
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
14 ;;;
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23
24 (let ((path "~/lib/emacs/")
25 (pkgs (list "bbdb/" "multiple-cursors/" "rust-mode/"))
26 pkg)
27 (setq load-path (nconc load-path (list path)))
28 (while (setq pkg (pop pkgs))
29 (let ((dir (concat path pkg)))
30 (if (file-exists-p dir)
31 (setq load-path (nconc load-path (list dir))))))
32 (let ((boot (concat path "mdw-pkgs.el")))
33 (if (file-exists-p boot)
34 (load boot))))
35
36 (require 'cl)
37 (require 'dot-emacs)
38
39 ;;;--------------------------------------------------------------------------
40 ;;; Some random initialisation.
41
42 (setq mdw-init-window (selected-window))
43
44 ;; Load some other bits of code.
45
46 (maybe-autoload 'cc-mode "cc-mode" nil t)
47 (maybe-autoload 'rexx-mode "rexx-mode" nil t)
48 (maybe-autoload 'cvs-update "pcl-cvs" nil t)
49 (maybe-autoload 'debian-changelog-mode "debian-changelog-mode" nil t)
50 (maybe-autoload 'git-status "git" nil t)
51 (maybe-autoload 'git-blame-mode "git-blame" nil t)
52 (maybe-autoload 'stgit "stgit" nil t)
53 (maybe-autoload 'nc-timesheet-prepare "nc-timesheet" nil t nil)
54 (maybe-autoload 'nc-timesheet-submit "nc-timesheet" nil t nil)
55 (maybe-autoload 'org-bbdb-anniversaries "org" nil t)
56
57 (and (library-exists-p "debian-changelog-mode")
58 (add-to-list 'auto-mode-alist
59 `(,(concat "/debian/"
60 "\\("
61 "[" "[:lower:]" "[:digit:]" "]"
62 "[" "[:lower:]" "[:digit:]" ".+-" "]+"
63 "\\."
64 "\\)?"
65 "changelog\\'")
66 . debian-changelog-mode)))
67
68 (and (library-exists-p "vc-git")
69 (not (memq 'GIT vc-handled-backends))
70 (not (memq 'Git vc-handled-backends))
71 (not (memq 'git vc-handled-backends))
72 (setq vc-handled-backends (cons 'GIT vc-handled-backends)))
73
74 (setq magit-log-cutoff-length 512)
75 (defun mdw-magit-try-load-config-extensions ()
76 (trap (magit-load-config-extensions)))
77 (add-hook 'magit-mode-hook 'mdw-magit-try-load-config-extensions)
78
79 (trap (or mdw-fast-startup (require 'p4)))
80
81 (trap (or mdw-fast-startup (require 'tex-site)))
82
83 (trap (or mdw-fast-startup t (semantic-load-enable-code-helpers)))
84 (setq semanticdb-default-save-directory "~/.emacs.d/semanticdb/")
85 (eval-after-load "senator"
86 '(setq isearch-mode-hook
87 (remq 'senator-isearch-mode-hook isearch-mode-hook)
88 isearch-mode-end-hook
89 (remq 'senator-isearch-mode-hook isearch-mode-end-hook)))
90
91 ;; Skeleton stuff.
92
93 (trap (or mdw-fast-startup (require 'skel-init)))
94
95 ;; Window system-dependent things.
96
97 (require 'paren)
98 (trap (show-paren-mode t))
99 (or window-system (mdw-emacs-version-p 22) (menu-bar-mode -1))
100
101 ;; Multiple cursors.
102
103 (global-set-key [?\C-c ?r] 'mdw-multiple-cursors-keymap)
104 (autoload 'mdw-multiple-cursors-keymap "mdw-multiple-cursors.el"
105 "A keymap for Magnar Sveen's awesome multiple-cursors." nil 'keymap)
106
107 ;; Rust mode.
108
109 (autoload 'rust-mode "rust-mode" nil t)
110 (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
111
112 ;; Temporary directory handling.
113
114 (defun mdw-check-dir-exists (dir)
115 (and dir
116 (file-directory-p dir)
117 dir))
118 (setq tmpdir (or (mdw-check-dir-exists (getenv "TMPDIR"))
119 (mdw-check-dir-exists (format "/tmp/%s" (user-login-name)))
120 "/tmp"))
121
122 ;; Emacs server behaviour.
123
124 (and (or window-system (mdw-emacs-version-p 23))
125 (not mdw-fast-startup)
126 (progn (setq server-temp-file-regexp (concat "^" tmpdir "\\|/draft$")
127 edit-server-new-frame nil
128 gnuserv-frame t)
129 (trap (server-start))
130 (trap (progn
131 (require 'edit-server)
132 (edit-server-start)
133 (let ((edit (get-process "edit-server")))
134 (and edit
135 (set-process-query-on-exit-flag edit nil)))))))
136
137 ;; Saving state.
138
139 (or mdw-fast-startup (savehist-mode 1))
140 (setq history-length 200)
141
142 ;; Control backup behaviour.
143
144 (setq backup-by-copying nil)
145 (setq backup-by-copying-when-linked t)
146 (setq backup-by-copying-when-mismatch t)
147
148 (setq mdw-backup-disable-regexps
149 '("/\\.git/COMMIT_EDITMSG$"
150 "/\\.stgit\\(-edit\\.txt\\|msg\\.txt\\|\\.msg\\)$"
151 "^/tmp/" "^/var/tmp/"))
152
153 ;; Safe variables.
154
155 (setq safe-local-variable-values
156 '((make-backup-files . nil)))
157
158 ;; Calculator fiddling.
159
160 (setq calc-settings-file "~/.emacs-calc")
161 (load calc-settings-file)
162
163 ;; ---- Some mail and news configuration ---
164
165 (setq mail-from-style 'angles
166 mail-signature t
167 mail-yank-prefix "> "
168 mail-archive-file-name nil
169 message-default-mail-headers ""
170 message-default-news-headers ""
171 compose-mail-user-agent-warnings nil)
172
173 (setq rmail-display-summary t)
174 (setq rmail-file-name "~/Mail/rmail")
175
176 (setq sendmail-program "~/bin/sendmail-hack"
177 send-mail-function 'sendmail-send-it
178 mail-interactive t
179 sendmail-error-reporting-interactive '("-odb" "-oee"))
180 (autoload 'sendmail-send-it "sendmail")
181 (autoload 'smtpmail-send-it "smtpmail")
182
183 (setq mail-user-agent 'message-user-agent
184 read-mail-command 'gnus)
185 (setq message-signature-separator "^-- \\(\\|\\[mdw\\]\\)$"
186 message-yank-prefix "> "
187 message-yank-cited-prefix "> "
188 message-send-mail-function 'message-send-mail-with-sendmail
189 message-interactive t
190 message-sendmail-extra-arguments '("-odb" "-oee")
191 message-sendmail-envelope-from 'header
192 message-indent-citation-function '(message-indent-citation
193 mdw-trim-spaces-after-citing))
194
195 (defun mdw-trim-spaces-after-citing ()
196 (save-excursion
197 (save-restriction
198 (narrow-to-region (point) (mark t))
199 (while (re-search-forward "^> +$" nil t)
200 (replace-match ">")))))
201
202 (and (fboundp 'turn-on-gnus-dired-mode)
203 (not mdw-fast-startup)
204 (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode))
205
206 (or mdw-fast-startup
207 (trap (bbdb-initialize 'gnus 'sendmail 'message)))
208 (setq bbdb-file "~/etc/brain/bbdb"
209 bbdb-north-american-phone-numbers-p nil
210 bbdb-dwim-net-address-allow-redundancy t
211 bbdb-extract-address-components-func 'bbdb-extract-address-components
212 bbdb/news-auto-create-p
213 (lambda ()
214 (let ((group gnus-newsgroup-name))
215 (and (string-match "^nn\\(imap\\|folder\\)\\+" group)
216 (not (string-match ":\\(crap\\|spam\\|lists\\|corpus\\)\\."
217 group)))))
218 bbdb-user-mail-names
219 (concat "^"
220 "\\(" "\\(mdw\\|markw\\|root\\|postmaster\\)"
221 "\\([-+][^@]*\\|\\)"
222 "@\\(\\(dist\\|esc\\)orted\\.org\\.uk\\|odin\\.gg\\)"
223 "\\|" "\\(" "\\(mdw\\|mwooding\\)"
224 "\\(\\+[^@]*\\)?"
225 "\\|" "0" "\\(mdw\\|mwooding\\)" "k\\.[^@]*"
226 "\\)" "@"
227 "\\(chiark\\|slimy\\|coriolis\\)\\.greenend\\.org\\.uk"
228 "\\|" "distorted\\.mdw@g\\(\\|oogle\\)mail.com"
229 "\\|" "mwooding@\\(good\\|blackberry\\)\\.com"
230 "\\|" "mark\\.wooding@trustonic\\.com"
231 "\\)$")
232 bbdb-canonicalize-net-hook
233 (lambda (addr)
234 (cond ((null addr)
235 nil)
236 ((or (string-match "^mailer-daemon@" addr)
237 (string-match "\.invalid$" addr)
238 (string-match (concat "^reply-[0-9a-f]+-[0-9a-f]+_"
239 "HTML-[0-9]+-[0-9]+-[0-9]+"
240 "@\\(nationwide-communications\\."
241 "co\\.uk\\)$")
242 addr)
243 (string-match (concat "^[0-9]+@bugs\\."
244 "\\(" "debian\\.org"
245 "\\|" "distorted\\.org\\.uk"
246 "\\)$")
247 addr)
248 (string-match (concat "^MicrosoftExchange[0-9a-f]*"
249 "@newincco\\.onmicrosoft\\.com")
250 addr)
251 (member (md5 addr)
252 '("8815c5583970856799c85a3ee0eb6a9f" ;work wiki spam
253 "0b94ab4d25dacaa5ac07243a09c9e22e" ;work bug spam
254 "35fb1633379a1e4d4be3b139cae20111" ;work crucible spam
255 ))
256 (and (string-match "^news\\([0-9]+\\)@\\(.*\\)$" addr)
257 (string= (md5 (match-string 2 addr))
258 "879b795aed959b1a000e9f95c132b16c")))
259 nil)
260 ((string-match "^\\([^@+]+\\)\\+[^@]*\\(@.*\\)$" addr)
261 (concat (match-string 1 addr) (match-string 2 addr)))
262 (t addr))))
263
264 ;; Customization.
265
266 (setq custom-file "~/.emacs-custom")
267 (trap (load custom-file))
268
269 (trap (load "~/.emacs-local"))
270
271 ;; Internationalization twiddling.
272
273 (trap
274 ;; Have top-bit-set characters work properly in terminals.
275 (let ((im (current-input-mode)))
276 (apply #'set-input-mode
277 (nconc (list (nth 0 im) (nth 1 im) 0) (nthcdr 3 im)))))
278
279 ;; Don't disable any commands.
280
281 (mapatoms #'(lambda (sym) (put sym 'disabled nil)))
282
283 ;; Split a wide window.
284
285 (mdw-divvy-window)
286
287 ;; Postscript printing.
288
289 (setq ps-paper-type 'a4
290 ps-print-color-p nil
291 ps-landscape-mode t
292 ps-number-of-columns 2
293 ps-font-family 'Courier
294 ps-font-size 6.5)
295
296 ;; Splash screen stuff.
297
298 (or window-system
299 (setq inhibit-splash-screen t
300 inhibit-startup-message t))
301
302 ;; Other goodies.
303
304 (trap (resize-minibuffer-mode 1)) ;Make minibuffer grow dynamically
305 (auto-compression-mode 1) ;Enable automatic compression
306 (setq enable-local-variables :safe
307 enable-local-eval nil)
308 (setq dabbrev-case-replace nil) ;Retain case when completing
309 (setq linum-format "%7d ")
310 (setq next-line-add-newlines nil) ;Don't add weird newlines
311 (setq split-height-threshold nil) ;Reuse windows where sensible
312 (setq display-buffer-reuse-frames nil ;Don't confuse me by showing buffers
313 iswitchb-default-method 'samewindow) ;in other random frames
314 (setq dired-deletion-confirmer ;Make deletion easier in dired
315 (symbol-function 'y-or-n-p)
316 dired-listing-switches "-alF" ;Do `ls -F' things in dired windows
317 wdired-allow-to-change-permissions 'advanced)
318 (setq read-quoted-char-radix 16) ;C-q HEX-STUFF [RET]
319 (setq case-fold-file-names nil) ;Don't translate file names (grr...)
320 (setq scroll-step 5) ;Don't scroll too much at a time
321 (setq-default fill-column mdw-text-width) ;I use rather narrow windows
322 (setq-default comment-column 40) ;Set a standard comment column
323 (setq-default truncate-partial-width-windows nil
324 truncate-lines t)
325 (setq default-indicate-empty-lines t)
326 (setq view-read-only t)
327 (setq whitespace-style '(trailing empty indentation face lines-tail
328 space-before-tab space-after-tab)
329 whitespace-line-column mdw-text-width)
330 (setq woman-use-own-frame nil ;Keep man pages somewhere sensible
331 woman-fill-column 72) ;Right margin position.
332 (setq diff-switches "-u" ;I like reading unified diffs
333 cvs-diff-flags (list diff-switches))
334 (setq echo-keystrokes 10) ;Long delay before keystrokes echo
335 (setq ange-ftp-ftp-program-name "pftp") ;Use passive FTP
336 (setq find-ls-option ;Build file lists efficiently
337 '("-print0 | xargs -0r ls -ld" . "ld"))
338 (setq bookmark-save-flag 0) ;Save bookmarks automatically
339 (setq vc-follow-symlinks t)
340 (setq x-gtk-file-dialog-help-text nil)
341 (setq Info-fontify-maximum-menu-size 100000)
342 (setq set-mark-command-repeat-pop t)
343 (setq password-cache-expiry nil)
344 (setq-default proced-filter 'all
345 proced-sort 'user)
346 (setq ispell-program-name "aspell-hack"
347 ispell-local-dictionary "en_GB-ize-w_accents"
348 flyspell-default-dictionary "en_GB-ize-w_accents"
349 ispell-local-dictionary-alist
350 '(("en_GB-ize-w_accents" "[[:alpha:]]" "[^[:alpha:]]" "'" t
351 ("-d" "en_GB-ize-w_accents") nil utf-8))
352 ispell-silently-savep t)
353 (trap
354 (require 'uniquify)
355 (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
356 (setq uniquify-after-kill-buffer-p t))
357 (transient-mark-mode t)
358 (setq mark-even-if-inactive t
359 shift-select-mode nil
360 delete-active-region nil
361 delete-selection-mode nil)
362 (trap
363 (tooltip-mode 0)
364 (tool-bar-mode 0))
365 (trap (or mdw-fast-startup (global-auto-revert-mode t)))
366 (setq psgml-html-build-new-buffer nil)
367
368 (defvar mdw-black-background t)
369
370 (eval-after-load "outline"
371 '(progn
372 (trap (require 'foldout))
373 (define-key outline-mode-prefix-map [?\C-r] 'reveal-mode)
374 (define-key outline-mode-prefix-map [?\C--] 'mdw-outline-collapse-all)))
375
376 (setq imenu-auto-rescan t
377 imenu-auto-rescan-maxout (* 128 1024)
378 imenu-max-items 60)
379
380 (setq cltl2-root-url (mdw-config 'cltl-url))
381 (setq common-lisp-hyperspec-root (mdw-config 'hyperspec-url))
382
383 (setq rfcview-rfc-location-pattern
384 "/ftp@mirror.distorted.org.uk:/pub/mirrors/rfc/rfc%s.txt"
385 rfcview-std-location-pattern
386 "/ftp@mirror.distorted.org.uk:/pub/mirrors/rfc/std/std%s.txt"
387 rfcview-index-location
388 "/ftp@mirror.distorted.org.uk:/pub/mirrors/rfc/rfc-index.txt")
389
390 ;;;--------------------------------------------------------------------------
391 ;;; W3 and URL fetching stuff.
392
393 (let ((proxy (mdw-config 'http-proxy)))
394 (setq url-proxy-services
395 `(("http" . ,proxy)
396 ("ftp" . ,proxy)
397 ("gopher" . ,proxy))))
398 (setq url-cookie-untrusted-urls '("."))
399
400 (setq browse-url-browser-function (mdw-good-url-browser)
401 browse-url-generic-program "mdw-chrome"
402 browse-url-mozilla-program "mdw-iceweasel")
403
404 (setq w3m-default-display-inline-images t
405 w3m-use-cookies t)
406
407 (eval-after-load "w3m"
408 '(let ((entries '(("application/pdf" "\\.pdf\\'" ("xdg-open" file) nil)
409 ("application/x-pdf" "\\.pdf\\'" ("xdg-open" file) nil))))
410 (dolist (e entries)
411 (setq w3m-content-type-alist
412 (cons e (remove* (car e) w3m-content-type-alist
413 :key #'car :test #'string=))))))
414
415 (setq w3-do-incremental-display t
416 w3-use-menus '(file edit view go bookmark options
417 buffers style search emacs nil help)
418 w3-display-inline-image t
419 w3-keybinding 'info)
420
421 ;;;--------------------------------------------------------------------------
422 ;;; Calendar configuration.
423
424 (setq diary-file
425 (let ((main-diary "~/etc/brain/diary")
426 (index "~/etc/index.diary"))
427 (if (file-exists-p index)
428 index
429 main-diary)))
430
431 ;; Trivial stuff for the sunrise/sunset calculations.
432
433 (setq calendar-latitude 52.2)
434 (setq calendar-longitude 0.1)
435 (setq calendar-location-name "Cambridge, UK")
436
437 ;; Holidays.
438
439 (and (not mdw-fast-startup)
440 (trap
441 (require 'ew-hols)
442 (setq other-holidays (append english-and-welsh-bank-holidays
443 other-holidays))))
444
445 ;; Date format fiddling.
446
447 (setq european-calendar-style t
448 calendar-date-style 'european
449 calendar-time-display-form
450 '(24-hours ":" minutes
451 (if time-zone " (") time-zone (if time-zone ")")))
452
453 (setq diary-date-forms
454 '((day "[-/]" month "[^-/0-9]")
455 (day " *" monthname "[ \t]*\\(\^M\\|\n\\)")
456 (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|[0-9]+[:aApP]\\)")
457 (day "[-/]" month "[-/]" year "[^0-9]")
458 (day " *" monthname " *" year "[^0-9]")
459 (year "[-/]" month "[-/]" day "[^0-9]")
460 (dayname "\\W")))
461
462 ;; Fancy diary handling.
463
464 (add-hook 'diary-display-hook 'fancy-diary-display)
465 (setq diary-list-include-blanks t)
466 (cond ((mdw-emacs-version-p 23 1)
467 (add-hook 'list-diary-entries-hook 'diary-include-other-diary-files)
468 (add-hook 'mark-diary-entries-hook 'diary-mark-included-diary-files))
469 (t
470 (add-hook 'list-diary-entries-hook 'include-other-diary-files)
471 (add-hook 'mark-diary-entries-hook 'mark-included-diary-files)))
472
473 ;; Appointment management.
474
475 (add-hook 'diary-hook 'appt-make-list)
476 (setq appt-issue-message t)
477 (setq appt-display-interval 3)
478 (setq appt-message-warning-time 10)
479 (and (not mdw-fast-startup)
480 (trap (require 'org)
481 (require 'bbdb)
482 (appt-activate 1)))
483
484 ;; Org-mode agenda.
485
486 (setq org-agenda-include-diary t
487 org-directory "~/etc/brain.local/"
488 org-default-notes-file (concat org-directory "local.org")
489 org-tags-column -77
490 org-agenda-align-tags-to-column org-tags-column)
491
492 ;; Cosmetic stuff.
493
494 (setq calendar-view-diary-initially-flag nil
495 calendar-view-holidays-initially-flag nil
496 calendar-mark-diary-entries-flag t)
497
498 (setq display-time-24hr-format t)
499 (display-time)
500 (column-number-mode 1)
501 (trap
502 (if (and window-system (not mdw-fast-startup))
503 (let ((calendar-view-diary-initially-flag t))
504 (calendar))))
505
506 ;;;--------------------------------------------------------------------------
507 ;;; MailCrypt.
508
509 ;; Define more mode hooks for MailCrypt.
510
511 (setq mdw-mc-modes
512 '((mdwmail-mode (encrypt . mdwmail-mc-encrypt)
513 (sign . mdwmail-mc-sign))))
514
515 ;; Load the MailCrypt support.
516
517 (trap
518 (and (string-match "linux" (symbol-name system-type))
519 (not mdw-fast-startup)
520 (progn (require 'mailcrypt-init)
521 (require 'mailcrypt)
522 (setq mc-default-scheme 'mc-scheme-gpg)
523 (setq mc-pgp-user-id "mdw-nsict-pgp")
524 (setq mc-gpg-user-id "mdw-nsict-gpg")
525 (setq mc-modes-alist (append mc-modes-alist mdw-mc-modes))
526 (setq mc-pgp-always-sign t)
527 (setq mc-gpg-always-sign t)
528 (setq mc-always-replace 'never)
529 (setq mc-passwd-timeout 3600)
530 (setq mc-temp-directory tmpdir)
531 (setq mc-modes-alist (append mc-modes-alist mdw-mc-modes))
532 (define-key mc-write-mode-map "\C-c/S" 'mc-sign-region)
533 (define-key mc-write-mode-map "\C-c/E" 'mc-encrypt-region)
534 (add-hook 'text-mode-hook 'mc-install-write-mode))))
535
536 ;;;--------------------------------------------------------------------------
537 ;;; Other common declarations.
538
539 ;; Default frame size.
540
541 (setq frame-background-mode (if mdw-black-background 'dark 'light)
542 default-frame-alist
543 `((width . ,(+ mdw-column-width
544 (if (>= emacs-major-version 21) 0 1)))
545 (height . 33)
546 (vertical-scroll-bars . right)
547 (cursor-type . bar)
548 (cursor-blink . t)
549 (left-fringe . 5)
550 (right-fringe . 5)
551 (scroll-bar-width . 15)
552 (tool-bar-lines . 0)
553 (menu-bar-lines . 1)
554 (cursor-color . "red")
555 (background-mode . ,frame-background-mode))
556 initial-frame-alist
557 `((width . ,(+ mdw-column-width
558 (if (>= emacs-major-version 21) 0 1)))
559 (menu-bar-lines . ,(if window-system 1 0)))
560 window-system-default-frame-alist
561 '((pm (font . "-os2-System VIO-medium-r-normal--*-40-*-*-m-*-cp850")
562 (menu-font . "8.Helv")
563 (background-color . "lightgrey"))
564 (w32 (font . "fixed613 10")
565 (background-color . "black")
566 (foreground-color . "white"))
567 (nil (menu-bar-lines . 0))))
568 (let ((backg (frame-parameter nil 'background-color)))
569 (if (and backg window-system)
570 (push (cons 'background-color backg) default-frame-alist)))
571
572 ;; Other frame fiddling.
573
574 (setq frame-title-format '("" invocation-name "@" system-name ": %b"))
575
576 ;; Global keymap changes.
577
578 (trap
579 (windmove-default-keybindings))
580 (setq windmove-wrap-around t)
581 (trap (iswitchb-mode))
582 (progn
583 (global-set-key [?\e ?\e] 'mdw-wrong)
584 (global-set-key [?\e ?\C-\] ?\C-\]] 'keyboard-escape-quit)
585 (global-set-key [?\C-c ?w left] 'windmove-left)
586 (global-set-key [?\C-c ?w ?h] 'windmove-left)
587 (global-set-key [?\C-c ?w up] 'windmove-up)
588 (global-set-key [?\C-c ?w ?k] 'windmove-up)
589 (global-set-key [?\C-c ?w down] 'windmove-down)
590 (global-set-key [?\C-c ?w ?j] 'windmove-down)
591 (global-set-key [?\C-c ?w right] 'windmove-right)
592 (global-set-key [?\C-c ?w ?l] 'windmove-right)
593 (global-set-key [?\C-c ?g ?l] 'org-store-link)
594 (global-set-key [?\C-c ?g ?a] 'org-agenda)
595 (global-set-key [?\C-c ?g ?b] 'org-iswitchb)
596 (global-set-key [?\C-c ?t ?i] 'timeclock-in)
597 (global-set-key [?\C-c ?t ?c] 'timeclock-change)
598 (global-set-key [?\C-c ?t ?o] 'timeclock-out)
599 (global-set-key [?\C-c ?t ?r] 'timeclock-reread-log)
600 (global-set-key [?\C-c ?t ?w] 'timeclock-workday-remaining-string)
601 (global-set-key [?\C-c ?t ?s] 'timeclock-status-string)
602 (global-set-key [?\C-c ?k] 'compile)
603 (global-set-key [?\C-x ?3] 'mdw-split-window-horizontally)
604 (global-set-key [?\M-#] 'calc-dispatch)
605 (global-set-key [?\C-x ?/] 'auto-fill-mode)
606 (global-set-key [?\C-c ?w ?d] 'mdw-divvy-window)
607 (global-set-key [insertchar] 'overwrite-mode)
608 (global-set-key [?\C-x ?\C-n] 'skel-create-file)
609 (global-set-key [?\C-x ?4 ?n] 'skel-create-file-other-window)
610 (global-set-key [?\C-x ?5 ?n] 'skel-create-file-other-frame)
611 (global-set-key [delete] 'delete-char)
612 (global-set-key [?\M-q] 'mdw-fill-paragraph)
613 (global-set-key [?\C-h ?\C-m] 'manual-entry)
614 (global-set-key [C-M-backspace] 'backward-kill-sexp)
615 (global-set-key [mode-line C-mouse-1] 'mouse-tear-off-window)
616 (global-set-key [vertical-scroll-bar C-down-mouse-1]
617 'mouse-drag-vertical-line)
618 (global-set-key [vertical-scroll-bar C-mouse-1]
619 #'(lambda () (interactive)))
620 (global-set-key [M-S-mouse-3] 'imenu)
621 (global-set-key [XF86WakeUp] "")
622 (global-set-key [?\C-c ?d ?w] 'devhelp-word-at-point)
623 (global-set-key [?\C-c ?d ?a] 'devhelp-assistant-word-at-point)
624 (global-set-key [f11] 'mdw-toggle-full-screen)
625 (and (not mdw-fast-startup) (fboundp 'hippie-expand)
626 (global-set-key [?\M-?] 'hippie-expand)))
627
628 (eval-after-load "hippie-exp"
629 '(setq hippie-expand-try-functions-list
630 (remove-if (lambda (name)
631 (memq name '(try-expand-list
632 try-expand-list-all-buffers)))
633 hippie-expand-try-functions-list)))
634
635 (eval-after-load "dired"
636 '(progn
637 (or (lookup-key dired-mode-map [?\C-x ?\C-q])
638 (define-key dired-mode-map [?\C-x ?\C-q]
639 'wdired-change-to-wdired-mode))
640 (trap (require 'dired-x))
641 (and (fboundp 'dired-do-relsymlink)
642 (define-key dired-mode-map [?\C-c ?\C-s] 'dired-do-relsymlink))))
643
644 (add-hook 'org-mode-hook
645 #'(lambda () (mdw-clobber-evil-keymap org-mode-map)))
646 (add-hook 'org-agenda-mode-hook
647 #'(lambda () (mdw-clobber-evil-keymap org-agenda-mode-map)))
648 (or mdw-fast-startup
649 (trap (progn
650 (org-remember-insinuate)
651 (global-set-key [?\C-c ?g ?r] 'org-remember))))
652
653 ;; Minor mode listing
654
655 (setq minor-mode-alist
656 (mdw-uniquify-alist '((reveal-mode (hs-minor-mode
657 " hs/r"
658 (global-reveal-mode
659 "" " Reveal")))
660 (hs-minor-mode (reveal-mode "" " hs"))
661 (abbrev-mode "")
662 (gtags-mode ""))
663 minor-mode-alist))
664
665 ;; Recognising types of files.
666
667 (setq auto-mode-alist
668 (append `(("\\.p[lm]$" . cperl-mode)
669 ("\\.m$" . objc-mode)
670 ("\\.mxd$" . c-mode)
671 ("\\.cs$" . csharp-mode)
672 ("\\.go$" . go-mode)
673 ("\\.org$" . org-mode)
674 ("\\.make$" . makefile-mode)
675 ("\\.mk?d$" . markdown-mode)
676 ;; ("/[ch]/" . c-mode)
677 (,(concat "/\\("
678 "\\.stgit\\.msg" "\\|"
679 "\\.topmsg" "\\|"
680 "\\.git/COMMIT_EDITMSG" "\\|"
681 "svn-commit\\.tmp" "\\|"
682 "svk-commit[^/.]*\\.tmp"
683 "\\)$")
684 . text-mode)
685 (,(concat "^" tmpdir "/\\("
686 "svk-commit[^/.]*\\.tmp" "\\|"
687 "gitci\\.[^/.]*" "\\|"
688 "cvs[^/.]\\{6\\}" "\\|"
689 "quilt_header\.[^/.]\\{6\\}"
690 "\\)$")
691 . text-mode)
692 ("\\.calc?$" . apcalc-mode)
693 ("/\\(s\\|sh\\)/" . arm-assembler-mode)
694 ("\\.\\(cmd\\|exec\\|rexx\\)$" . rexx-mode)
695 ("\\.st$" . smalltalk-mode)
696 ("\\.msgs$" . messages-mode)
697 ("/all-cmds\\.in$" . cpp-messages-mode)
698 ("\\.\\(tex\\|dtx\\)$" . latex-mode)
699 ("\\.gc$" . haskell.-mode)
700 (,(concat "^" (getenv "HOME") "/News/") . mdwmail-mode)
701 (,(concat "^" tmpdir "/\\(SLRN\\|snd\\|pico\\|mutt\\)")
702 . mdwmail-mode))
703 auto-mode-alist))
704
705 (setq interpreter-mode-alist
706 (append `(("runlisp" . lisp-mode)
707 ("@BASH@" . sh-mode)
708 ("@PYTHON@" . python-mode)
709 ("@PERL@" . cperl-mode)
710 ("perl" . cperl-mode)
711 ("@TCLSH@" . tcl-mode)
712 ("@WISH@" . tcl-mode)
713 ("tclsh" . tcl-mode)
714 ("wish" . tcl-mode))
715 interpreter-mode-alist))
716
717 (setq completion-ignored-extensions
718 (append `(".hc" ".hi") completion-ignored-extensions))
719 (dolist (dir (remove-if-not (lambda (ext)
720 (= (aref ext (- (length ext) 1)) ?/))
721 completion-ignored-extensions))
722 (if (/= (aref dir 0) ?/)
723 (setq completion-ignored-extensions
724 (cons (concat "/" dir)
725 (remove dir completion-ignored-extensions)))))
726
727 ;; Some common local definitions.
728
729 (make-variable-buffer-local 'mdw-auto-indent)
730
731 (mapc (lambda (hook) (add-hook hook 'mdw-misc-mode-config))
732 '(c-mode-hook c++-mode-hook objc-mode-hook java-mode-hook
733 csharp-mode-hook perl-mode-hook cperl-mode-hook dylan-mode-hook
734 python-mode-hook pyrec-mode-hook icon-mode-hook awk-mode-hook
735 tcl-mode-hook go-mode-hook js-mode-hook javascript-mode-hook
736 conf-mode-hook m4-mode-hook autoconf-mode-hook autotest-mode-hook
737 a68-mode-hook a68-mode-hooks asm-mode-hook fsharp-mode-hook
738 scala-mode-hook rust-mode-hook TeX-mode-hook LaTeX-mode-hook
739 TeXinfo-mode-hook tex-mode-hook latex-mode-hook
740 texinfo-mode-hook emacs-lisp-mode-hook scheme-mode-hook
741 lisp-mode-hook lisp-interaction-mode-hook makefile-mode-hook
742 inferior-lisp-mode-hook slime-repl-mode-hook
743 sml-mode-hook haskell-mode-hook erlang-mode-hook
744 smalltalk-mode-hook rexx-mode-hook
745 arm-assembler-mode-hook))
746
747 (global-font-lock-mode t)
748
749 ;;;--------------------------------------------------------------------------
750 ;;; Rootly editingness.
751
752 (eval-after-load "tramp"
753 '(let ((fix-args (if (mdw-version-< tramp-version "2.1")
754 #'append #'list)))
755 (setq tramp-methods
756 (mdw-uniquify-alist
757 `(("become"
758 (tramp-connection-function tramp-open-connection-su)
759 (tramp-remote-sh "/bin/sh")
760 (tramp-login-program "become")
761 (tramp-copy-program nil)
762 (tramp-copy-args nil)
763 (tramp-copy-keep-date-arg nil)
764 (tramp-login-args ,(funcall fix-args `("TERM=dumb" "%u"))))
765 ("really"
766 (tramp-connection-function tramp-open-connection-su)
767 (tramp-login-program "really")
768 (tramp-login-args ,(funcall fix-args
769 `("-u" "%u")
770 `("--")
771 `("env" "TERM=dumb" "/bin/sh")))
772 (tramp-copy-program nil)
773 (tramp-copy-args nil)
774 (tramp-copy-keep-date-arg nil)
775 (tramp-remote-sh "/bin/sh"))
776 ,@tramp-methods)))
777 (setq tramp-default-method "ssh")
778 (let ((rootlyness (cond ((executable-find "really") "really")
779 ((executable-find "become") "become")
780 ((executable-find "sudo") "sudo")
781 (t "su")))
782 (this-host (concat "\\`\\(localhost\\|"
783 (system-name) "\\|\\)\\'"))
784 (this-user (concat "\\`\\(" (user-login-name) "\\|"
785 (user-real-login-name) "\\|\\)\\'")))
786 (setq tramp-default-method-alist
787 `((,this-host nil ,rootlyness)
788 (nil ,this-user "ssh")
789 (nil "." ,rootlyness)))
790 (setq tramp-default-proxies-alist
791 `((,this-host nil nil)
792 (nil "." "/ssh:%h:"))))))
793
794 ;;;--------------------------------------------------------------------------
795 ;;; General fontification.
796
797 ;; Configure lazy fontification.
798
799 (and (fboundp 'lazy-lock-mode)
800 (setq font-lock-support-mode 'lazy-lock-mode))
801 ; (setq lazy-lock-defer-contextually t)
802 (setq lazy-lock-defer-time nil
803 font-lock-maximum-decoration 3
804 lazy-lock-minimum-size 0
805 lazy-lock-stealth-time 5
806 lazy-lock-stealth-lines 100
807 lazy-lock-stealth-verbose t)
808
809 (progn
810 (add-hook 'c-mode-hook 'mdw-fontify-c-and-c++ t)
811 (add-hook 'objc-mode-hook 'mdw-fontify-c-and-c++ t)
812 (add-hook 'c++-mode-hook 'mdw-fontify-c-and-c++ t)
813 (add-hook 'asm-mode-hook 'mdw-fontify-asm t)
814 (add-hook 'go-mode-hook 'mdw-fontify-go t)
815 (add-hook 'rust-mode-hook 'mdw-fontify-rust t)
816
817 (add-hook 'icon-mode-hook 'mdw-fontify-icon t)
818
819 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
820 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t)
821
822 (add-hook 'java-mode-hook 'mdw-fontify-java t)
823 (add-hook 'scala-mode-hook 'mdw-fontify-scala t)
824 (add-hook 'js-mode-hook 'mdw-fontify-javascript t)
825 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
826 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
827 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t)
828
829 (add-hook 'awk-mode-hook 'mdw-fontify-awk t)
830
831 (add-hook 'perl-mode-hook 'mdw-fontify-perl t)
832 (add-hook 'cperl-mode-hook 'mdw-fontify-perl t))
833
834 (progn
835 (setq-default py-indent-offset 2
836 python-indent 2
837 python-indent-offset 2
838 py-python-command-args
839 `("-i" "-colors" ,(if mdw-black-background
840 "Linux" "LightBG")))
841 (add-hook 'python-mode-hook 'mdw-fontify-python t)
842 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
843
844 (setq-default tcl-indent-level 2)
845 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t)
846
847 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t)
848
849 (setq sml-nested-if-indent t
850 sml-case-indent nil
851 sml-indent-level 4
852 sml-type-of-indent nil)
853 (add-hook 'sml-mode-hook 'mdw-fontify-sml t)
854
855 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t)
856 (setq-default haskell-indent-offset 2)
857
858 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t)
859
860 (add-hook 'texinfo-mode-hook 'mdw-fontify-texinfo t)
861 (add-hook 'TeXinfo-mode-hook 'mdw-fontify-texinfo t)
862
863 (setq LaTeX-table-label "tbl:")
864 (setq TeX-auto-untabify nil)
865 (add-hook 'TeX-mode-hook 'mdw-fontify-tex t)
866 (add-hook 'tex-mode-hook 'mdw-fontify-tex t)
867 (add-hook 'LaTeX-mode-hook 'mdw-fontify-tex t)
868 (add-hook 'latex-mode-hook 'mdw-fontify-tex t)
869
870 (add-hook 'sh-mode-hook #'mdw-setup-sh-script-mode)
871 (add-hook 'autoconf-mode-hook #'mdw-setup-m4)
872 (add-hook 'autotest-mode-hook #'mdw-setup-m4)
873 (add-hook 'm4-mode-hook #'mdw-setup-m4)
874
875 (add-hook 'smalltalk-mode-hook 'mdw-fontify-smalltalk t)
876 (add-hook 'smalltalk-mode-hook 'mdw-setup-smalltalk t)
877
878 (add-hook 'a68-mode-hook 'mdw-fontify-algol-68 t)
879 (add-hook 'a68-mode-hooks 'mdw-fontify-algol-68 t)
880 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t)
881
882 (progn
883 (add-hook 'emacs-lisp-mode-hook 'mdw-fontify-lispy t)
884 (add-hook 'scheme-mode-hook 'mdw-fontify-lispy t)
885 (add-hook 'lisp-mode-hook 'mdw-fontify-lispy t)
886 (add-hook 'inferior-lisp-mode-hook 'mdw-fontify-lispy t)
887 (add-hook 'lisp-interaction-mode-hook 'mdw-fontify-lispy t)
888 (add-hook 'slime-repl-mode-hook 'mdw-fontify-lispy t)
889 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
890 (add-hook 'inferior-lisp-mode-hook
891 #'(lambda ()
892 (local-set-key "\C-m" 'comint-send-and-indent)) t))
893
894 (add-hook 'text-mode-hook 'mdw-text-mode t)
895
896 ;;;--------------------------------------------------------------------------
897 ;;; TeX stuff.
898
899 (setq TeX-output-view-style
900 '(("^dvi$"
901 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
902 "%(o?)dvips -t landscape %d -o && xdg-open %f")
903 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
904 "%(o?)dvips %d -o && xdg-open %f")
905 ("^dvi$"
906 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
907 "%(o?)xdvi %dS -paper a4r -s 0 %d")
908 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
909 "%(o?)xdvi %dS -paper a4 %d")
910 ("^dvi$"
911 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
912 "%(o?)xdvi %dS -paper a5r -s 0 %d")
913 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
914 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
915 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
916 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
917 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
918 ("^dvi$" "." "%(o?)xdvi %dS %d")
919 ("^pdf$" "." "xdg-open %o")
920 ("^html?$" "." "sensible-browser %o")))
921
922 (setq TeX-view-program-list
923 '(("mupdf" "mupdf %o" (mode-io-correlate " %(outpage)"))))
924
925 (setq TeX-view-program-selection
926 '(((output-dvi style-pstricks) "dvips and gv")
927 (output-dvi "xdvi")
928 (output-pdf "mupdf")
929 (output-html "sensible-browser")))
930
931 (setq TeX-open-quote "\""
932 TeX-close-quote "\"")
933
934 (setq reftex-use-external-file-finders t
935 reftex-auto-recenter-toc t)
936
937 (setq reftex-label-alist
938 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
939 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
940 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
941 ("proposition" ?P "prop:" "~\\ref{%s}" t
942 ("propositions?" "prop\\.") -2)
943 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
944 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
945 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
946 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
947 (setq reftex-section-prefixes
948 '((0 . "part:")
949 (1 . "ch:")
950 (t . "sec:")))
951
952 (setq bibtex-field-delimiters 'double-quotes
953 bibtex-entry-format '(realign opts-or-alts required-fields
954 numerical-fields last-comma delimiters
955 unify-case)
956 bibtex-include-OPTkey nil)
957
958 ;;;--------------------------------------------------------------------------
959 ;;; SLIME setup.
960
961 (trap
962 (if (not mdw-fast-startup)
963 (progn
964 (require 'slime-autoloads)
965 (slime-setup '(slime-autodoc slime-c-p-c)))))
966
967 (let ((stuff '((cmucl ("cmucl"))
968 (sbcl ("sbcl") :coding-system utf-8-unix)
969 (clisp ("clisp") :coding-system utf-8-unix))))
970 (or (boundp 'slime-lisp-implementations)
971 (setq slime-lisp-implementations nil))
972 (while stuff
973 (let* ((head (car stuff))
974 (found (assq (car head) slime-lisp-implementations)))
975 (setq stuff (cdr stuff))
976 (if found
977 (rplacd found (cdr head))
978 (setq slime-lisp-implementations
979 (cons head slime-lisp-implementations))))))
980 (setq slime-default-lisp 'sbcl)
981
982 ;;;--------------------------------------------------------------------------
983 ;;; Blogging.
984
985 (setq weblogger-config-alist
986 '(("vox"
987 ("user" . "mdw")
988 ("server-url" . "http://vox.distorted.org.uk/admin/mt-xmlrpc.cgi")
989 ("weblog" . "1"))))
990
991 ;;;--------------------------------------------------------------------------
992 ;;; Shell mode.
993
994 ;; Make the shell mode aware of my prompt.
995
996 (setq shell-prompt-pattern "^[^]#$%>»}\n]*\\([]#$%»}]\\|>>?\\) *")
997 (setq comint-password-prompt-regexp
998 (concat "\\(\\([Ee]nter \\|[Oo]ld \\|[Nn]ew \\|[a-zA-Z0-9_]*'s \\|^\\)"
999 "[Pp]assword\\|[Pp]ass ?phrase\\(\\| [-a-zA-Z0-9._]+\\)\\):")
1000 comint-file-name-chars "~/A-Za-z0-9+@:_.$#%,={}-"
1001 shell-file-name-chars comint-file-name-chars)
1002
1003 ;; Notice passwords, and make C-a work right.
1004
1005 (add-hook 'shell-mode-hook #'mdw-sh-mode-setup)
1006 (add-hook 'shell-mode-hook #'ansi-color-for-comint-mode-on)
1007 (setq shell-font-lock-keywords nil)
1008
1009 (add-hook 'term-mode-hook #'mdw-term-mode-setup)
1010
1011 ;;;--------------------------------------------------------------------------
1012 ;;; Finishing touches.
1013
1014 (trap (select-window mdw-init-window))
1015 (provide 'emacs-init)
1016
1017 ;;;----- That's all, folks --------------------------------------------------