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