chiark / gitweb /
belgrano
[ian-dotfiles.git] / files / emacs_ian.el
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 ;
8 ; Make sure we don't disturb links or change ownership, use numbers
9 (setq backup-by-copying-when-mismatch t)
10 (setq backup-by-copying-when-linked t)
11 ;(setq version-control t
12 ;      kept-new-versions 4
13 ;      kept-old-versions 4
14 ;      trim-versions-without-asking t)
15 ;
16 ; Various one-liners
17 (setq require-final-newline "ask")
18 (if (string= window-system 'x) (load-library "ian-x"))
19 (load-library "ian-aliases")
20 ; (load-library "auto-pgp")
21 ; (load-library "debian-changelog-mode")
22 ; (if (string= (getenv "TERM") "bbcb32") (setq term-file-prefix nil))
23 ; (setq explicit-shell-file-name "/usr/local/bin/tcsh")
24 (setq inhibit-local-variables t)
25 (setq enable-local-variables 'ask-me)
26 (setq enable-recursive-minibuffers t)
27 (setq compile-command "make")
28 (setq diff-switches "-u")
29 (display-time)
30 ;
31 (set-variable 'search-repeat-char 28)
32 (if (string-match "^19\." emacs-version)
33     (progn
34       (setq file-name-handler-alist     ; Disable nasty auto-loading of ange-ftp
35             (delq (rassq 'ange-ftp-completion-hook-function file-name-handler-alist)
36                   file-name-handler-alist))
37       (require 'find-alternate-18style)
38       (defun unset-down-mouse-23 ()
39         (local-set-key [mouse-2] 'mouse-yank-at-click)
40         (local-unset-key [down-mouse-2])
41         (local-unset-key [down-mouse-3])
42         (local-unset-key [C-down-mouse-3]))
43       (add-hook 'vm-mode-hook 'unset-down-mouse-23)
44       (add-hook 'vm-mail-mode-hook 'unset-down-mouse-23)
45       (add-hook 'text-mode-hook 'unset-down-mouse-23)
46       (add-hook 'Info-mode-hook
47                 (function (lambda ()
48                             (local-set-key " " 'scroll-up)
49                             (local-set-key "\7f" 'scroll-down))))
50       (define-key isearch-mode-map "\1c" 'isearch-repeat-forward)
51       (define-key isearch-mode-map "\1d" 'isearch-quote-char)))
52 ;
53 (menu-bar-mode -1)
54 (defun terminal-keybindings ()
55   "This function should be called by the term-setup-hook mechanism"
56   (interactive)
57   ; Set my own keybindings
58   ;
59   ; Set keybindings generally (including I-search on C-\)
60 ;  (global-set-key "    " 'self-insert-command)
61   (global-set-key "\1c" 'isearch-forward)
62   (global-set-key "\r" 'newline-and-indent)
63   (global-set-key "\ f" 'set-mark-command)
64   (global-set-key "\1d" 'quoted-insert)
65   ;
66   ; Set keybindings on esc-map
67   (global-set-key "\e#" 'query-replace-regexp)
68   (global-set-key "\e+" 'toggle-truncate-lines)
69   (global-set-key "\eg" 'goto-line)
70   (global-set-key "\es" 'isearch-forward-regexp)
71   (global-set-key "\e\e" 'eval-expression)
72   ;
73   ; Set keybindings on ^X-map.
74   (global-set-key "\18m" 'vm-mail)
75   (global-set-key "\18\1c" 'save-buffer)
76   (global-set-key "\18\1d" 'toggle-read-only)
77   (global-set-key "\18#" 'recover-file)
78   (global-set-key "\18\12" 'bury-buffer)
79   (global-set-key "\18\v" 'quicker-compile)
80   (global-set-key "\18\18" 'exchange-point-and-mark)
81   (global-set-key "\18\1a" 'load-ange-ftp)
82   (global-set-key "\184\16" 'scroll-other-window)
83   (global-set-key "\184m" 'vm-mail-other-window)
84   (global-set-key "\189" 'vm-visit-folder)
85   (global-set-key "\188" 'rmail-input)
86   (global-set-key "\18p" 'cite-region)
87   (global-set-key "\18F" 'mail-formletter)
88   ;
89   ; Set keybindings for Sun numeric pad.
90   (setq esc-bracket-map (make-keymap))
91   (define-key esc-bracket-map "D" 'backward-char)
92   (define-key esc-bracket-map "C" 'forward-char)
93   (define-key esc-bracket-map "A" 'previous-line)
94   (define-key esc-bracket-map "B" 'next-line)
95   (define-key esc-map "[" esc-bracket-map)
96   (global-set-key "\e[214z" 'beginning-of-buffer)
97   (global-set-key "\e[220z" 'end-of-buffer)
98   (global-set-key "\e[216z" 'scroll-down)
99   (global-set-key "\e[222z" 'scroll-up)
100   (global-set-key "\e[192z" 'save-buffer)
101   (global-set-key "\e[194z" 'save-some-buffers)
102   (global-set-key "\e[195z" 'undo)
103   (global-set-key "\e[193z" 'call-last-kbd-macro)
104   (global-set-key "\e[196z" 'switch-to-buffer-other-window)
105   (global-set-key "\e[197z" 'copy-region-as-kill)
106   (global-set-key "\e[198z" 'find-file)
107   (global-set-key "\e[199z" 'yank)
108   (global-set-key "\e[198z" 'find-alternate-file)
109   (global-set-key "\e[200z" 'find-file)
110   (global-set-key "\e[201z" 'kill-region)
111   (global-set-key "\e[-1z" 'info)
112   ;
113   ; Set keybindings for Chiarks' x11emacs
114   (global-set-key "\e[5~" 'scroll-down)
115   (global-set-key "\e[6~" 'scroll-up)
116   ;
117   ; Set keybindings for knackered vt100-like terminal emulators.
118   (global-set-key "\eOt" 'scroll-down)
119   (global-set-key "\eOu" 'scroll-up)
120   (global-set-key "\eOD" 'backward-char)
121   (global-set-key "\eOC" 'forward-char)
122   (global-set-key "\eOA" 'previous-line)
123   (global-set-key "\eOB" 'next-line))
124 (setq term-setup-hook 'terminal-keybindings)     ; remap keys in due course
125 ;
126 ; Autoload definitions
127 (autoload 'tar-mode "tar-mode")
128 (autoload 'uncompress-while-visiting "uncompress")
129 ; (autoload 'c++-mode "c++-mode" "Mode for editing C and C++ programs" t)
130 (autoload 'hide-ifdef-mode "hideif" "For editing code with #ifdefs" t)
131 ;(setq-default indent-tabs-mode nil)
132 (autoload 'dired-find-alternate-file "dired-alternate" "Find alternately" t)
133 (autoload 'dired-run-file "dired-alternate" "Run this file" t)
134 (autoload 'perl-mode "perl-mode" "Mode for Perl code" t)
135 ; (autoload 'rmail "rmail-fixed" "Patched mail reader" t)
136 (autoload 'quicker-compile "quicker-compile" "Patched Compile mode" t)
137
138 (autoload 'vm "vm" "Start VM on your primary inbox." t)
139 (autoload 'vm-visit-folder "vm" "Start VM on an arbitrary folder." t)
140 (autoload 'vm-visit-virtual-folder "vm" "Visit a VM virtual folder." t)
141 (autoload 'vm-mode "vm" "Run VM major mode on a buffer" t)
142 (autoload 'vm-mail "vm" "Send a mail message using VM." t)
143 (autoload 'vm-submit-bug-report "vm" "Send a bug report about VM." t)
144 ;
145 ; (autoload 'info "info-fixed" "Patched info browser" t)
146 (setq shell-mode-hook
147       '(lambda ()
148          (make-variable-buffer-local 'scroll-step)
149          (setq scroll-step 1)))
150 ; (setq inferior-lisp-program "kcl")
151 (setq dired-mode-hook
152       '(lambda ()
153          (define-key dired-mode-map "F" 'dired-find-alternate-file)
154          (define-key dired-mode-map "X" 'dired-run-file)))
155 ;
156 ; Prevent loading of default init file and do some of the things it did
157 ; (setq inhibit-default-init t)
158 ;
159 ; Additional alist handling function
160 ;(defun alist-remove-elem (s s-list)
161 ;  "Delete the element of the alist S-LIST whose car is S"
162 ;  (if s-list (if (equal s (car (car s-list)))
163 ;                (cdr s-list)
164 ;              (cons (car s-list) (alist-remove-elem s (cdr s-list))))
165 ;    (nil)))
166 ;
167 ; Load C++ mode and edit Perl in perl mode
168 (setq auto-mode-alist
169       (append '(("\\.[ch]$" . c-mode)
170                 ("\\.[CH]$" . c++-mode)
171                 ("\\.cc$" . c++-mode)
172                 ("\\.hh$" . c++-mode)
173 ;                ("\\.tar$" . tar-mode)
174                 ("\\.pl$" . perl-mode)
175                 ("\\.ci$" . tex-mode)
176                 ("\\.Z$" . uncompress-while-visiting))
177               auto-mode-alist))
178 (setq interpreter-mode-alist
179       (append '(("sh" . fundamental-mode)
180                 ("bash" . fundamental-mode))
181               interpreter-mode-alist))
182 ;
183 ; Use auto-fill when editing text
184 (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
185 (add-hook 'text-mode-hook '(lambda () (local-set-key "  " 'self-insert-command)))
186 ;
187 ; Set up newline to auto-indent & other stuff for perl, c++ and c modes.
188 (setq perl-mode-hook '(lambda () 
189                         (local-set-key ";" 'self-insert-command)))
190 (setq c++-mode-hook '(lambda ()
191                        (hide-ifdef-mode 1)
192                        (local-set-key ":" 'electric-c++-terminator)))
193 ; c++-electric-colon
194 (setq c-mode-hook '(lambda ()
195                      (hide-ifdef-mode 1)
196                      (c-set-offset 'substatement-open 0 nil)
197                      (local-set-key "\r" 'newline-and-indent)))
198 (setq c-hanging-comment-ender-p nil)
199 ;
200 (defun vm-mail-other-window ()
201   "Like `vm-mail' command, but display buffer in another window."
202   (interactive)
203   (switch-to-buffer-other-window (current-buffer))
204   (vm-mail))
205 ;
206 ; mail precedences
207 (setq mail-precedence-key-alist
208       '((?0  . "special-delivery")
209         (?1  . "air-mail")
210         (?2  . "first-class")
211         (?3  . "second-class")
212         (?5  . "third-class")
213         (?\  . nil)
214         (?6  . "bulk")
215         (?9  . "junk")))
216 ;
217 (defun mail-precedence-as-key ()
218   "Set precedence by looking up last command char in mail-precedence-key-alist"
219   (interactive)
220   (message "%s" (concat "Precedence ["
221                         (mapconcat '(lambda (c) (char-to-string (car c)))
222                                    mail-precedence-key-alist "")
223                         "] ?"))
224   (let* ((key (read-char))
225          (prec (assoc key mail-precedence-key-alist)))
226     (if prec (mail-precedence (cdr prec))
227       (error "mail-precedence-as-key `%s' not found" key))))
228 ;
229 (defun mail-precedence-as-key-send-and-exit (arg)
230   "Set precedence by looking up last command char in mail-precedence-key-alist,
231 then call send-and-exit."
232   (interactive "P")
233   (mail-precedence-as-key)
234   (execute-kbd-macro "\ 3\ 3"))
235 ;
236 (defun mail-precedence (prec)
237   (save-excursion
238     (mail-position-on-field "Precedence")
239     (let ((p (point)))
240       (beginning-of-line)
241       (delete-region (point) p)
242       (if prec
243           (insert "Precedence: " prec)
244         (delete-char 1)))))
245 ;
246 (defun mail-mode-setup-keys ()
247   (local-set-key "\ 3\10" 'mail-precedence-as-key)
248   (local-set-key "\ 3p" 'mail-precedence-as-key-send-and-exit))
249 (add-hook 'mail-mode-hook 'mail-mode-setup-keys)
250 (add-hook 'vm-mail-mode-hook 'mail-mode-setup-keys)
251 ;
252 (defun vm-mail-other-window ()
253   "Like `vm-mail' command, but display buffer in another window."
254   (interactive)
255   (switch-to-buffer-other-window (current-buffer))
256   (vm-mail))
257 ;
258 (defun mail-formletter ()
259   "Run VM-mail with ,Formletter"
260   (interactive)
261   (vm-mail)
262   (rename-buffer (generate-new-buffer-name "form letter") t)
263   (delete-region (point-min) (point-max))
264   (insert-file (concat vm-folder-directory ",Formletter")))
265 ;
266 ; This function bound to C-x C-z
267 (defun load-ange-ftp ()
268   "Load ange-ftp using require, if it isn't loaded already"
269   (interactive)
270   (message "Loading ange-ftp...")
271   (require 'ange-ftp) ; -extended
272   (message "Loading ange-ftp...done"))
273 ;
274 ; This function bound to M-+
275 (defun toggle-truncate-lines ()
276   "Toggle truncation or folding of long lines"
277   (interactive)
278   (set-variable 'truncate-lines (not truncate-lines))
279   (redraw-display))
280 ;
281 ; RMAIL stuff
282 ;(setq rmail-file-name "~/mail/RMAIL"
283 ;      mail-archive-file-name "~/mail/Outbound"
284 ;      rmail-primary-inbox-list '("~/mbox" "~/mail/Outbound" "~/mail/Record"
285 ;                                 "~/mail/Import" "/var/spool/mail/ian")
286 ;      rmail-delete-after-output t
287 ;      rmail-last-rmail-file ""
288 ;      rmail-ignored-headers (concat
289 ;                             "^Content-Identifier:\\|^X400-[^O][A-Za-z-]+:\\|"
290 ;                             rmail-ignored-headers))
291 ;
292 (defun make-regexps-ignore-non-address (list)
293   (apply 'append (mapcar
294                   '(lambda (item)
295                      (let ((item (mapconcat
296                                   '(lambda (ch)
297                                      (let ((s (char-to-string ch)))
298                                        (if (string-match "[][.*+?^$\\]" s)
299                                            (concat "\\" s)
300                                          s)))
301                                   item "")))
302                        (list
303                         (concat "<" item ">")
304                         (concat "^" item " *\\((.*)\\)?$"))))
305                   list)))
306 ;
307 ; BBDB
308 (setq bbdb-north-american-phone-numbers-p nil
309       bbdb/mail-auto-create-p t
310       bbdb-auto-revert-p t
311       bbdb-notice-auto-save-file-p t
312       bbdb-message-caching-enabled t)      
313 ;
314 ; VM stuff
315 (load-file "~/private/private.el")
316 (setq vm-included-text-attribution-format "%F writes (\"%s\"):\n"
317       vm-reply-subject-prefix "Re: "
318       vm-folder-directory "~/mail/"
319       vm-delete-after-saving t
320       vm-delete-empty-folders t
321       vm-mutable-windows nil
322       vm-auto-get-new-mail nil
323       vm-auto-next-message nil
324       vm-jump-to-new-messages nil
325       vm-jump-to-unread-messages nil
326       vm-preview-lines nil
327       vm-included-text-prefix "> "
328       vm-confirm-quit 1
329       vm-auto-center-summary t
330       vm-confirm-new-folders t
331       vm-circular-folders nil
332       vm-visit-when-saving 0
333       vm-move-after-deleting t
334       vm-keep-sent-messages t
335       vm-follow-summary-cursor t
336       vm-frame-per-composition nil
337       vm-frame-per-edit nil
338       vm-frame-per-summary nil
339       vm-frame-per-folder nil
340       vm-tale-is-an-idiot t
341       vm-primary-inbox (concat vm-folder-directory "INBOX")
342       vm-sysadmin-inbox (concat vm-folder-directory "SINBOX")
343       vm-uninteresting-senders "ian"
344       vm-reply-ignored-addresses
345       (make-regexps-ignore-non-address
346        '("ian@chiark.chu.cam.ac.uk" "ian" "iwj10@cus.cam.ac.uk"
347          "ian@chiark.greenend.org.uk"
348          "ijackson@nyx.cs.du.edu" "ijackson@gnu.ai.mit.edu"))
349 ;      vm-spool-files
350 ;      (list
351 ;       (list vm-primary-inbox "~/mbox" "~/mail/INBOX.CRASH")
352 ;       (list vm-primary-inbox "~/mail/Outbound" "~/mail/INBOX.CRASH")
353 ;       (list vm-primary-inbox "~/mail/Record" "~/mail/INBOX.CRASH")
354 ;       (list vm-primary-inbox "~/mail/Import" "~/mail/INBOX.CRASH")
355 ;       (list vm-primary-inbox "/var/spool/mail/ian" "~/mail/INBOX.CRASH")
356 ;       (list vm-primary-inbox "~/News/r" "~/mail/INBOX.CRASH")
357 ;       (list vm-sysadmin-inbox "~/mbox" "~/mail/SINBOX.CRASH")
358 ;       (list vm-sysadmin-inbox "~/mail/SOutbound" "~/mail/SINBOX.CRASH")
359 ;       (list vm-sysadmin-inbox "~/mail/Import" "~/mail/SINBOX.CRASH")
360 ;       (list vm-sysadmin-inbox "/var/spool/mail/sysadmin" "~/mail/SINBOX.CRASH")
361 ; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mbox" "/u/ijackson/mail/INBOX.CRASH")
362 ; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mail/Outbound"
363 ;       "/u/ijackson/mail/INBOX.CRASH")
364 ; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mail/Record" "/u/ijackson/mail/INBOX.CRASH")
365 ; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mail/Import" "/u/ijackson/mail/INBOX.CRASH")
366 ;        (list "/u/ijackson/mail/INBOX"
367 ;         (concat "localhost:110:pass:ijackson:" ijackson-pop-password)
368 ;         "/u/ijackson/mail/INBOX.CRASH"))
369       vm-startup-with-summary nil
370       vm-summary-format "%3n %a %2d %3m  %-19.19F  %s\n"
371       mail-archive-file-name "~/mail/Outbound"
372       vm-mime-8bit-text-transfer-encoding '8bit)
373 ;
374 (add-hook 'vm-mode-hook
375           '(lambda ()
376              (local-set-key "Q" 'vm-quit)
377              (local-set-key "q" "#Q")))
378 (add-hook 'mail-mode-hook
379           '(lambda ()
380              (if (and (boundp 'folder-buffer)
381                       folder-buffer
382                       (string= (buffer-file-name folder-buffer)
383                                (file-truename vm-sysadmin-inbox)))
384                  (progn
385                    (make-local-variable 'vm-mail-header-from)
386                    (setq vm-mail-header-from
387                          "sysadmin@chiark.greenend.org.uk (Ian Jackson)")
388                    (make-local-variable 'mail-archive-file-name)
389                    (setq mail-archive-file-name
390                          "~/mail/SOutbound")))))
391 ;
392 (defun vmi ()
393   (interactive)
394   (vm "/u/ijackson/mail/INBOX"))
395 ;
396 (defun vms ()
397   (interactive)
398   (vm vm-sysadmin-inbox))
399 ;
400 (defun make-session ()
401   "Makes this emacs hard to kill by requiring ^X^Cy to kill it
402 instead of just ^X^C."
403   (interactive)
404   (global-unset-key "\18\ 3")
405   (global-set-key "\18\ 3y" 'save-buffers-kill-emacs))
406 ;
407 ; Fix problems with M-| setting window title of emacs' parent xterm
408 (defun envdelete-term-termcap-windowid (list)
409   (let ((l list))
410     (mapcar '(lambda (x)
411                (if x (delq x l)))
412             (mapcar '(lambda (x)
413                        (if (or (string-match "^TERM=" x)
414                                (string-match "^TERMCAP=" x)
415                                (string-match "^WINDOWID=" x))
416                            x
417                          nil))
418                     l))
419     l))
420 (setq process-environment
421       (envdelete-term-termcap-windowid process-environment))
422 ;
423 (defun add-insertion-keys (table)
424   "Adds keybindings according to TABLE.  Each element of
425 TABLE should be a four-element list.
426
427 BINDING should be the key to bind; FUNCTION will be the name of the
428 function defined to do the insertion; DESCRIPTION will be inserted
429 into \"Inserts ... .\", and used as the descriptive string for the
430 generated function; STRING is the string which will actually be
431 inserted into the buffer when the keystroke is pressed."
432   (while table
433     (let* ((head (car table))
434            (key (car head))
435            (func (nth 1 head))
436            (desc (nth 2 head))
437            (string (nth 3 head)))
438       (defalias func
439         (list
440          'lambda () 
441          (concat "Inserts " desc ".")
442          '(interactive)
443          (list 'insert string)))
444       (funcall 'local-set-key key func))
445     (setq table (cdr table))))
446
447 (defun ian-sgml-setup ()
448   (interactive)
449   (add-insertion-keys
450    '(("\ 3\r" sgml-insert-new-para "new paragraph markup" "\n<p>\n")
451      ("\ 3\14" sgml-insert-tt-emph "tt emph markup" "<tt/")
452      ("\ 3\10" sgml-insert-prgn-emph "prgn emph markup" "<prgn/")
453      ("\ 3\ 5" sgml-insert-em-emph "em emfh markup" "<em/")
454      ("\ 3\16" sgml-insert-var-empfh "var emph markup" "<var/"))))
455 (setq sgml-local-catalogs '("/jura:/usr/lib/debiandoc-sgml/sgml/catalog"))
456   
457 (add-hook 'sgml-mode-hook 'ian-sgml-setup)
458 ;
459 (defvar cite-string "> " "String to insert when citing")
460 ;
461 (defun cite-region (start end)
462   "Quote each line in the region with an angle-bracket and space.
463
464 The citation string is taken from cite-string."
465   (interactive "r")
466   (save-excursion
467     (save-restriction
468       (narrow-to-region start end)
469       (goto-char (point-min))
470       (insert cite-string)
471       (while
472           (and
473            (= (forward-line) 0)
474            (> (point-max) (point)))
475         (insert cite-string)))))
476 ;
477 ; End of this file.