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