chiark / gitweb /
Merge old CVS `ian-dotfiles' repo, as a subtree where we can pick bits
[ian-dotfiles.git] / home / emacs / ian.el.~1.5.~
1 ; This is my real emacs start-up file (for chiark).
2
3 (make-variable-buffer-local 'indent-line-function)
4 ; Un-disable narrow and eval-expression
5 (put 'narrow-to-region 'disabled nil)
6 (put 'eval-expression 'disabled nil)
7 (standard-display-european t)
8 ;
9 ; Make sure we don't disturb links or change ownership, use numbers
10 (setq backup-by-copying-when-mismatch t)
11 (setq backup-by-copying-when-linked t)
12 ;(setq version-control t
13 ;      kept-new-versions 4
14 ;      kept-old-versions 4
15 ;      trim-versions-without-asking t)
16 ;
17 ; Various one-liners
18 (setq require-final-newline "ask")
19 (if (string= window-system 'x) (load-library "ian-x"))
20 (load-library "ian-aliases")
21 ; (load-library "auto-pgp")
22 ; (load-library "debian-changelog-mode")
23 ; (if (string= (getenv "TERM") "bbcb32") (setq term-file-prefix nil))
24 ; (setq explicit-shell-file-name "/usr/local/bin/tcsh")
25 (setq inhibit-local-variables t)
26 (setq enable-local-variables 'ask-me)
27 (setq enable-recursive-minibuffers t)
28 (setq compile-command "make")
29 (setq diff-switches "-u")
30 (display-time)
31 ;
32 (set-variable 'search-repeat-char 28)
33 (if (string-match "^19\." emacs-version)
34     (progn
35       (setq file-name-handler-alist     ; Disable nasty auto-loading of ange-ftp
36             (delq (rassq 'ange-ftp-completion-hook-function file-name-handler-alist)
37                   file-name-handler-alist))
38       (require 'find-alternate-18style)
39       (defun unset-down-mouse-23 ()
40         (local-set-key [mouse-2] 'mouse-yank-at-click)
41         (local-unset-key [down-mouse-2])
42         (local-unset-key [down-mouse-3])
43         (local-unset-key [C-down-mouse-3]))
44       (add-hook 'vm-mode-hook 'unset-down-mouse-23)
45       (add-hook 'vm-mail-mode-hook 'unset-down-mouse-23)
46       (add-hook 'text-mode-hook 'unset-down-mouse-23)
47       (add-hook 'Info-mode-hook
48                 (function (lambda ()
49                             (local-set-key " " 'scroll-up)
50                             (local-set-key "\7f" 'scroll-down))))
51       (define-key isearch-mode-map "\1c" 'isearch-repeat-forward)
52       (define-key isearch-mode-map "\1d" 'isearch-quote-char)))
53 ;
54 (menu-bar-mode -1)
55 (defun terminal-keybindings ()
56   "This function should be called by the term-setup-hook mechanism"
57   (interactive)
58   ; Set my own keybindings
59   ;
60   ; Set keybindings generally (including I-search on C-\)
61 ;  (global-set-key "    " 'self-insert-command)
62   (global-set-key "\1c" 'isearch-forward)
63   (global-set-key "\r" 'newline-and-indent)
64   (global-set-key "\ f" 'set-mark-command)
65   (global-set-key "\1d" 'quoted-insert)
66   ;
67   ; Set keybindings on esc-map
68   (global-set-key "\e#" 'query-replace-regexp)
69   (global-set-key "\e+" 'toggle-truncate-lines)
70   (global-set-key "\eg" 'goto-line)
71   (global-set-key "\es" 'isearch-forward-regexp)
72   (global-set-key "\e\e" 'eval-expression)
73   ;
74   ; Set keybindings on ^X-map.
75   (global-set-key "\18m" 'vm-mail)
76   (global-set-key "\18\1c" 'save-buffer)
77   (global-set-key "\18\1d" 'toggle-read-only)
78   (global-set-key "\18#" 'recover-file)
79   (global-set-key "\18\12" 'bury-buffer)
80   (global-set-key "\18\v" 'quicker-compile)
81   (global-set-key "\18\18" 'exchange-point-and-mark)
82   (global-set-key "\18\1a" 'load-ange-ftp)
83   (global-set-key "\184\16" 'scroll-other-window)
84   (global-set-key "\184m" 'vm-mail-other-window)
85   (global-set-key "\189" 'vm-visit-folder)
86   (global-set-key "\188" 'rmail-input)
87   (global-set-key "\18p" 'cite-region)
88   (global-set-key "\18F" 'mail-formletter)
89   ;
90   ; Set keybindings for Sun numeric pad.
91   (setq esc-bracket-map (make-keymap))
92   (define-key esc-bracket-map "D" 'backward-char)
93   (define-key esc-bracket-map "C" 'forward-char)
94   (define-key esc-bracket-map "A" 'previous-line)
95   (define-key esc-bracket-map "B" 'next-line)
96   (define-key esc-map "[" esc-bracket-map)
97   (global-set-key "\e[214z" 'beginning-of-buffer)
98   (global-set-key "\e[220z" 'end-of-buffer)
99   (global-set-key "\e[216z" 'scroll-down)
100   (global-set-key "\e[222z" 'scroll-up)
101   (global-set-key "\e[192z" 'save-buffer)
102   (global-set-key "\e[194z" 'save-some-buffers)
103   (global-set-key "\e[195z" 'undo)
104   (global-set-key "\e[193z" 'call-last-kbd-macro)
105   (global-set-key "\e[196z" 'switch-to-buffer-other-window)
106   (global-set-key "\e[197z" 'copy-region-as-kill)
107   (global-set-key "\e[198z" 'find-file)
108   (global-set-key "\e[199z" 'yank)
109   (global-set-key "\e[198z" 'find-alternate-file)
110   (global-set-key "\e[200z" 'find-file)
111   (global-set-key "\e[201z" 'kill-region)
112   (global-set-key "\e[-1z" 'info)
113   ;
114   ; Set keybindings for Chiarks' x11emacs
115   (global-set-key "\e[5~" 'scroll-down)
116   (global-set-key "\e[6~" 'scroll-up)
117   ;
118   ; Set keybindings for knackered vt100-like terminal emulators.
119   (global-set-key "\eOt" 'scroll-down)
120   (global-set-key "\eOu" 'scroll-up)
121   (global-set-key "\eOD" 'backward-char)
122   (global-set-key "\eOC" 'forward-char)
123   (global-set-key "\eOA" 'previous-line)
124   (global-set-key "\eOB" 'next-line))
125 (setq term-setup-hook 'terminal-keybindings)     ; remap keys in due course
126 ;
127 ; Autoload definitions
128 (autoload 'tar-mode "tar-mode")
129 (autoload 'uncompress-while-visiting "uncompress")
130 ; (autoload 'c++-mode "c++-mode" "Mode for editing C and C++ programs" t)
131 (autoload 'hide-ifdef-mode "hideif" "For editing code with #ifdefs" t)
132 ;(setq-default indent-tabs-mode nil)
133 (autoload 'dired-find-alternate-file "dired-alternate" "Find alternately" t)
134 (autoload 'dired-run-file "dired-alternate" "Run this file" t)
135 (autoload 'perl-mode "perl-mode" "Mode for Perl code" t)
136 ; (autoload 'rmail "rmail-fixed" "Patched mail reader" t)
137 (autoload 'quicker-compile "quicker-compile" "Patched Compile mode" t)
138
139 (autoload 'vm "vm" "Start VM on your primary inbox." t)
140 (autoload 'vm-visit-folder "vm" "Start VM on an arbitrary folder." t)
141 (autoload 'vm-visit-virtual-folder "vm" "Visit a VM virtual folder." t)
142 (autoload 'vm-mode "vm" "Run VM major mode on a buffer" t)
143 (autoload 'vm-mail "vm" "Send a mail message using VM." t)
144 (autoload 'vm-submit-bug-report "vm" "Send a bug report about VM." t)
145 ;
146 ; (autoload 'info "info-fixed" "Patched info browser" t)
147 (setq shell-mode-hook
148       '(lambda ()
149          (make-variable-buffer-local 'scroll-step)
150          (setq scroll-step 1)))
151 ; (setq inferior-lisp-program "kcl")
152 (setq dired-mode-hook
153       '(lambda ()
154          (define-key dired-mode-map "F" 'dired-find-alternate-file)
155          (define-key dired-mode-map "X" 'dired-run-file)))
156 ;
157 ; Prevent loading of default init file and do some of the things it did
158 ; (setq inhibit-default-init t)
159 ;
160 ; Additional alist handling function
161 ;(defun alist-remove-elem (s s-list)
162 ;  "Delete the element of the alist S-LIST whose car is S"
163 ;  (if s-list (if (equal s (car (car s-list)))
164 ;                (cdr s-list)
165 ;              (cons (car s-list) (alist-remove-elem s (cdr s-list))))
166 ;    (nil)))
167 ;
168 ; Load C++ mode and edit Perl in perl mode
169 (setq auto-mode-alist
170       (append '(("\\.[ch]$" . c-mode)
171                 ("\\.[CH]$" . c++-mode)
172                 ("\\.cc$" . c++-mode)
173                 ("\\.hh$" . c++-mode)
174 ;                ("\\.tar$" . tar-mode)
175                 ("\\.pl$" . perl-mode)
176                 ("\\.ci$" . tex-mode)
177                 ("\\.Z$" . uncompress-while-visiting))
178               auto-mode-alist))
179 (setq interpreter-mode-alist
180       (append '(("sh" . fundamental-mode)
181                 ("bash" . fundamental-mode))
182               interpreter-mode-alist))
183 ;
184 ; Use auto-fill when editing text
185 (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
186 ; (add-hook 'text-mode-hook '(lambda () (local-set-key "        " 'self-insert-command)))
187 ;
188 ; Set up newline to auto-indent & other stuff for perl, c++ and c modes.
189 (setq perl-mode-hook '(lambda () 
190                         (local-set-key ";" 'self-insert-command)))
191 (setq c++-mode-hook '(lambda ()
192                        (hide-ifdef-mode 1)
193                        (local-set-key ":" 'electric-c++-terminator)))
194 ; c++-electric-colon
195 (setq c-mode-hook '(lambda ()
196                      (hide-ifdef-mode 1)
197                      (c-set-offset 'substatement-open 0 nil)
198                      (local-set-key "\r" 'newline-and-indent)))
199 (setq c-hanging-comment-ender-p nil)
200 ;
201 (defun vm-mail-other-window ()
202   "Like `vm-mail' command, but display buffer in another window."
203   (interactive)
204   (switch-to-buffer-other-window (current-buffer))
205   (vm-mail))
206 ;
207 ; mail precedences
208 (setq mail-precedence-key-alist
209       '((?0  . "special-delivery")
210         (?1  . "air-mail")
211         (?2  . "first-class")
212         (?3  . "second-class")
213         (?5  . "third-class")
214         (?\  . nil)
215         (?6  . "bulk")
216         (?9  . "junk")))
217 ;
218 (defun mail-precedence-as-key ()
219   "Set precedence by looking up last command char in mail-precedence-key-alist"
220   (interactive)
221   (message "%s" (concat "Precedence ["
222                         (mapconcat '(lambda (c) (char-to-string (car c)))
223                                    mail-precedence-key-alist "")
224                         "] ?"))
225   (let* ((key (read-char))
226          (prec (assoc key mail-precedence-key-alist)))
227     (if prec (mail-precedence (cdr prec))
228       (error "mail-precedence-as-key `%s' not found" key))))
229 ;
230 (defun mail-precedence-as-key-send-and-exit (arg)
231   "Set precedence by looking up last command char in mail-precedence-key-alist,
232 then call send-and-exit."
233   (interactive "P")
234   (mail-precedence-as-key)
235   (execute-kbd-macro "\ 3\ 3"))
236 ;
237 (defun mail-precedence (prec)
238   (save-excursion
239     (mail-position-on-field "Precedence")
240     (let ((p (point)))
241       (beginning-of-line)
242       (delete-region (point) p)
243       (if prec
244           (insert "Precedence: " prec)
245         (delete-char 1)))))
246 ;
247 (defun mail-mode-setup-keys ()
248   (local-set-key "\ 3\10" 'mail-precedence-as-key)
249   (local-set-key "\ 3p" 'mail-precedence-as-key-send-and-exit))
250 (add-hook 'mail-mode-hook 'mail-mode-setup-keys)
251 (add-hook 'vm-mail-mode-hook 'mail-mode-setup-keys)
252 ;
253 (defun vm-mail-other-window ()
254   "Like `vm-mail' command, but display buffer in another window."
255   (interactive)
256   (switch-to-buffer-other-window (current-buffer))
257   (vm-mail))
258 ;
259 (defun mail-formletter ()
260   "Run VM-mail with ,Formletter"
261   (interactive)
262   (vm-mail)
263   (rename-buffer (generate-new-buffer-name "form letter") t)
264   (delete-region (point-min) (point-max))
265   (insert-file (concat vm-folder-directory ",Formletter")))
266 ;
267 ; This function bound to C-x C-z
268 (defun load-ange-ftp ()
269   "Load ange-ftp using require, if it isn't loaded already"
270   (interactive)
271   (message "Loading ange-ftp...")
272   (require 'ange-ftp) ; -extended
273   (message "Loading ange-ftp...done"))
274 ;
275 ; This function bound to M-+
276 (defun toggle-truncate-lines ()
277   "Toggle truncation or folding of long lines"
278   (interactive)
279   (set-variable 'truncate-lines (not truncate-lines))
280   (redraw-display))
281 ;
282 ; RMAIL stuff
283 ;(setq rmail-file-name "~/mail/RMAIL"
284 ;      mail-archive-file-name "~/mail/Outbound"
285 ;      rmail-primary-inbox-list '("~/mbox" "~/mail/Outbound" "~/mail/Record"
286 ;                                 "~/mail/Import" "/var/spool/mail/ian")
287 ;      rmail-delete-after-output t
288 ;      rmail-last-rmail-file ""
289 ;      rmail-ignored-headers (concat
290 ;                             "^Content-Identifier:\\|^X400-[^O][A-Za-z-]+:\\|"
291 ;                             rmail-ignored-headers))
292 ;
293 (defun make-regexps-ignore-non-address (list)
294   (apply 'append (mapcar
295                   '(lambda (item)
296                      (let ((item (mapconcat
297                                   '(lambda (ch)
298                                      (let ((s (char-to-string ch)))
299                                        (if (string-match "[][.*+?^$\\]" s)
300                                            (concat "\\" s)
301                                          s)))
302                                   item "")))
303                        (list
304                         (concat "<" item ">")
305                         (concat "^" item " *\\((.*)\\)?$"))))
306                   list)))
307 ;
308 ; BBDB
309 (setq bbdb-north-american-phone-numbers-p nil
310       bbdb/mail-auto-create-p t
311       bbdb-auto-revert-p t
312       bbdb-notice-auto-save-file-p t
313       bbdb-message-caching-enabled t)      
314 ;
315 ; VM stuff
316 (load-file "~/private/private.el")
317 (if (file-exists-p "~/private/private2.el")
318   (load-file "~/private/private2.el"))
319 (setq vm-included-text-attribution-format "%F writes (\"%s\"):\n"
320       vm-reply-subject-prefix "Re: "
321       vm-folder-directory "~/mail/"
322       vm-delete-after-saving t
323       vm-delete-empty-folders t
324       vm-mutable-windows t
325       vm-auto-get-new-mail nil
326       vm-auto-next-message nil
327       vm-jump-to-new-messages nil
328       vm-jump-to-unread-messages nil
329       vm-mime-digest-discard-header-regexp "only-drop-this-header"
330       vm-preview-lines nil
331       vm-included-text-prefix "> "
332       vm-confirm-quit 1
333       vm-auto-center-summary t
334       vm-confirm-new-folders t
335       vm-circular-folders nil
336       vm-visit-when-saving 0
337       vm-move-after-deleting t
338       vm-keep-sent-messages t
339       vm-follow-summary-cursor t
340       vm-frame-per-composition nil
341       vm-frame-per-edit nil
342       vm-frame-per-summary nil
343       vm-frame-per-folder nil
344       vm-tale-is-an-idiot t
345       vm-primary-inbox (concat vm-folder-directory "INBOX")
346       vm-sinbin-inbox (concat vm-folder-directory "SINBOX")
347       vm-uninteresting-senders "ian"
348       vm-reply-ignored-addresses
349       (make-regexps-ignore-non-address
350        '("ian@chiark.chu.cam.ac.uk" "ian" "iwj10@cus.cam.ac.uk"
351          "ian@chiark.greenend.org.uk"
352          "ijackson@nyx.cs.du.edu" "ijackson@gnu.ai.mit.edu"))
353       vm-primary-inbox (concat vm-folder-directory "INBOX")
354
355       vm-uninteresting-senders "ian"
356       vm-reply-ignored-addresses
357       (make-regexps-ignore-non-address
358        '("ijackson@chiark.chu.cam.ac.uk" "ijackson"
359          "iwj10@thor.cam.ac.uk" "iwj10@hermes.cam.ac.uk" "iwj10@cl.cam.ac.uk"
360          "iwj10@cam.ac.uk" "Ian.Jackson@cl.cam.ac.uk"))
361       mail-archive-file-name "~/mail/Outbound"
362
363
364       vm-spool-files
365       '((vm-primary-inbox "/var/spool/mail/ian"
366                           "~/mail/INBOX.CRASH")
367         (vm-primary-inbox "~/News/r" "~/mail/INBOX.CRASH")
368         (vm-primary-inbox "~/mbox" "~/mail/INBOX.CRASH")
369         (vm-primary-inbox "~/mail/Outbound" "~/mail/INBOX.CRASH")
370         (vm-primary-inbox "~/mail/Import" "~/mail/INBOX.CRASH")
371         (vm-primary-inbox "~/mail/Record" "~/mail/INBOX.CRASH")
372         (vm-sinbin-inbox "/var/spool/mail/ian" "~/mail/SINBOX.CRASH"))
373       vm-startup-with-summary t