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