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