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