1 ; This is my real emacs start-up file (for chiark).
4 (defalias 'perl-mode 'cperl-mode)
5 (setq cperl-invalid-face nil
7 cperl-continued-statement-offset 4)
9 (make-variable-buffer-local 'indent-line-function)
10 ; Un-disable narrow and eval-expression
11 (put 'narrow-to-region 'disabled nil)
12 (put 'eval-expression 'disabled nil)
13 ;(standard-display-european t)
15 (setq browse-url-netscape-program "mozilla")
16 (setq common-lisp-hyperspec-root "/usr/share/doc/hyperspec/")
18 ; Make sure we don't disturb links or change ownership, use numbers
19 (setq backup-by-copying-when-mismatch t)
20 (setq backup-by-copying-when-linked t)
21 ;(setq version-control t
24 ; trim-versions-without-asking t)
27 (setq require-final-newline "ask")
28 (if (string= window-system 'x) (load-library "ian-x"))
29 (load-library "ian-aliases")
30 ; (load-library "auto-pgp")
31 ; (load-library "debian-changelog-mode")
32 ; (if (string= (getenv "TERM") "bbcb32") (setq term-file-prefix nil))
33 ; (setq explicit-shell-file-name "/usr/local/bin/tcsh")
34 (setq inhibit-local-variables t)
35 (setq enable-local-variables 'ask-me)
36 (setq enable-recursive-minibuffers t)
37 (setq compile-command "make")
38 (setq next-line-add-newlines t)
39 (setq diff-switches "-u")
40 (setq line-move-visual nil)
43 (set-default 'indent-line-function 'insert-tab)
44 (set-variable 'search-repeat-char 28)
45 (set-fringe-mode (cons 0 nil))
46 (if (string-match "^19\." emacs-version)
48 ; (setq file-name-handler-alist ; Disable nasty auto-loading of ange-ftp
49 ; (delq (rassq 'ange-ftp-completion-hook-function file-name-handler-alist)
50 ; file-name-handler-alist))
51 (require 'find-alternate-18style)
52 (defun unset-down-mouse-23 ()
53 (local-set-key [mouse-2] 'mouse-yank-at-click)
54 (local-unset-key [down-mouse-2])
55 (local-unset-key [down-mouse-3])
56 (local-unset-key [C-down-mouse-3]))
57 (add-hook 'vm-mode-hook 'unset-down-mouse-23)
58 (add-hook 'vm-mail-mode-hook 'unset-down-mouse-23)
59 (add-hook 'text-mode-hook 'unset-down-mouse-23)
60 (add-hook 'Info-mode-hook
62 (local-set-key " " 'scroll-up)
63 (local-set-key "
\7f" 'scroll-down))))
64 (add-hook 'sh-mode-hook
66 (local-set-key "<" 'self-insert-command))))
67 (define-key isearch-mode-map "
\1c" 'isearch-repeat-forward)
68 (define-key isearch-mode-map "
\1d" 'isearch-quote-char)))
71 (defun terminal-keybindings ()
72 "This function should be called by the term-setup-hook mechanism"
74 ; Set my own keybindings
76 ; Set keybindings generally (including I-search on C-\)
77 ; (global-set-key " " 'self-insert-command)
78 (global-set-key "
\1c" 'isearch-forward)
79 ; (global-set-key "
\r" 'newline)
80 (global-set-key "
\ f" 'set-mark-command)
81 (global-set-key "
\1d" 'quoted-insert)
83 ; Set keybindings on esc-map
84 (global-set-key "
\e#" 'query-replace-regexp)
85 (global-set-key "
\e+" 'toggle-truncate-lines)
86 (global-set-key "
\eg" 'goto-line)
87 (global-set-key "
\es" 'isearch-forward-regexp)
88 (global-set-key "
\e\e" 'eval-expression)
90 ; Set keybindings on ^X-map.
91 (global-set-key "
\18m" 'vm-mail)
92 (global-set-key "
\18\1c" 'save-buffer)
93 (global-set-key "
\18\1d" 'toggle-read-only)
94 (global-set-key "
\18#" 'recover-file)
95 (global-set-key "
\18\12" 'bury-buffer)
96 (global-set-key "
\18\v" 'quicker-compile)
97 (global-set-key "
\18\18" 'exchange-point-and-mark)
98 (global-set-key "
\18\1a" 'load-tramp)
99 (global-set-key "
\184
\16" 'scroll-other-window)
100 (global-set-key "
\184m" 'vm-mail-other-window)
101 (global-set-key "
\189" 'vm-visit-folder)
102 (global-set-key "
\188" 'rmail-input)
103 (global-set-key "
\18p" 'cite-region)
104 (global-set-key "
\18F" 'mail-formletter)
106 ; Set keybindings for Sun numeric pad.
107 (setq esc-bracket-map (make-keymap))
108 (define-key esc-bracket-map "D" 'backward-char)
109 (define-key esc-bracket-map "C" 'forward-char)
110 (define-key esc-bracket-map "A" 'previous-line)
111 (define-key esc-bracket-map "B" 'next-line)
112 (define-key esc-map "[" esc-bracket-map)
113 (global-set-key "\e[214z" 'beginning-of-buffer)
114 (global-set-key "\e[220z" 'end-of-buffer)
115 (global-set-key "\e[216z" 'scroll-down)
116 (global-set-key "\e[222z" 'scroll-up)
117 (global-set-key "\e[192z" 'save-buffer)
118 (global-set-key "\e[194z" 'save-some-buffers)
119 (global-set-key "\e[195z" 'undo)
120 (global-set-key "\e[193z" 'call-last-kbd-macro)
121 (global-set-key "\e[196z" 'switch-to-buffer-other-window)
122 (global-set-key "\e[197z" 'copy-region-as-kill)
123 (global-set-key "\e[198z" 'find-file)
124 (global-set-key "\e[199z" 'yank)
125 (global-set-key "\e[198z" 'find-alternate-file)
126 (global-set-key "\e[200z" 'find-file)
127 (global-set-key "\e[201z" 'kill-region)
128 (global-set-key "\e[-1z" 'info)
130 ; Set keybindings for Chiarks' x11emacs
131 (global-set-key "
\e[5~" 'scroll-down)
132 (global-set-key "
\e[6~" 'scroll-up)
134 ; Set keybindings for knackered vt100-like terminal emulators.
135 (global-set-key "\eOt" 'scroll-down)
136 (global-set-key "\eOu" 'scroll-up)
137 (global-set-key "\eOD" 'backward-char)
138 (global-set-key "\eOC" 'forward-char)
139 (global-set-key "\eOA" 'previous-line)
140 (global-set-key "\eOB" 'next-line))
141 (setq term-setup-hook 'terminal-keybindings) ; remap keys in due course
143 (setq frame-title-format
147 ((buf (current-buffer))
148 (leaf (buffer-name buf))
149 (dir default-directory))
152 ((dir (abbreviate-file-name dir))
153 (node (replace-regexp-in-string "\\..*" "" system-name)))
154 (concat leaf " " node ":" dir))
156 ("" invocation-name "@" system-name)))
157 ;(setq frame-title-format
161 ; ((buf (current-buffer))
162 ; (fn (buffer-file-name buf)))
165 ; ((fn (abbreviate-file-name fn))
166 ; (dir (file-name-directory fn))
167 ; (leaf (file-name-nondirectory fn))
168 ; (node (replace-regexp-in-string "\\..*" "" system-name)))
169 ; (concat leaf " " node ":" dir))
170 ; (buffer-name buf))))
171 ; ("" invocation-name "@" system-name)))
173 ; Autoload definitions
174 (autoload 'tar-mode "tar-mode")
175 (autoload 'uncompress-while-visiting "uncompress")
176 ; (autoload 'c++-mode "c++-mode" "Mode for editing C and C++ programs" t)
177 (autoload 'hide-ifdef-mode "hideif" "For editing code with #ifdefs" t)
178 ;(setq-default indent-tabs-mode nil)
179 (autoload 'dired-find-alternate-file "dired-alternate" "Find alternately" t)
180 (autoload 'dired-run-file "dired-alternate" "Run this file" t)
181 (autoload 'perl-mode "perl-mode" "Mode for Perl code" t)
182 ; (autoload 'rmail "rmail-fixed" "Patched mail reader" t)
183 (autoload 'quicker-compile "quicker-compile" "Patched Compile mode" t)
185 ;(autoload 'vm "vm" "Start VM on your primary inbox." t)
186 ;(autoload 'vm-visit-folder "vm" "Start VM on an arbitrary folder." t)
187 ;(autoload 'vm-visit-virtual-folder "vm" "Visit a VM virtual folder." t)
188 ;(autoload 'vm-mode "vm" "Run VM major mode on a buffer" t)
189 ;(autoload 'vm-mail "vm" "Send a mail message using VM." t)
190 ;(autoload 'vm-submit-bug-report "vm" "Send a bug report about VM." t)
192 ;(require 'vm-autoload)
194 (vm-legacy-key-bindings)
196 ; (autoload 'info "info-fixed" "Patched info browser" t)
197 (setq shell-mode-hook
199 (make-variable-buffer-local 'scroll-step)
200 (setq scroll-step 1)))
201 (setq inferior-lisp-program "sbcl")
202 ;(setq jit-lock-chunk-size 100
203 ; jit-lock-stealth-time 1.00)
204 (setq dired-mode-hook
206 (define-key dired-mode-map "F" 'dired-find-alternate-file)
207 (define-key dired-mode-map "X" 'dired-run-file)))
209 ; Prevent loading of default init file and do some of the things it did
210 ; (setq inhibit-default-init t)
212 ; Additional alist handling function
213 ;(defun alist-remove-elem (s s-list)
214 ; "Delete the element of the alist S-LIST whose car is S"
215 ; (if s-list (if (equal s (car (car s-list)))
217 ; (cons (car s-list) (alist-remove-elem s (cdr s-list))))
220 ; Load C++ mode and edit Perl in perl mode
221 (setq auto-mode-alist
222 (append '(("\\.[ch]$" . c-mode)
223 ("\\.[CH]$" . c++-mode)
224 ("\\.cc$" . c++-mode)
225 ("\\.hh$" . c++-mode)
226 ; ("\\.tar$" . tar-mode)
227 ("\\.pl$" . perl-mode)
228 ("\\.ci$" . tex-mode)
229 ("\\.asm$" . fundamental-mode)
230 ("\\.Z$" . uncompress-while-visiting))
232 (setq interpreter-mode-alist
233 (append '(("sh" . fundamental-mode)
234 ("bash" . fundamental-mode))
235 interpreter-mode-alist))
237 ; Use auto-fill when editing text
238 (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
239 ; (add-hook 'text-mode-hook '(lambda () (local-set-key " " 'self-insert-command)))
241 ; Set up newline to auto-indent & other stuff for perl, c++ and c modes.
242 (setq perl-mode-hook '(lambda ()
243 (local-set-key ";" 'self-insert-command)))
244 (setq c++-mode-hook '(lambda ()
246 (local-set-key "," 'self-insert-command)
247 (local-set-key ":" 'electric-c++-terminator)))
249 (setq c-mode-hook '(lambda ()
251 (c-set-offset 'substatement-open 0 nil)
252 (local-set-key "," 'self-insert-command)
253 (local-set-key ";" 'self-insert-command)
254 (local-set-key "/" 'self-insert-command)
255 (local-set-key "*" 'self-insert-command)
256 (local-set-key "#" 'self-insert-command)
257 (local-set-key "(" 'self-insert-command)
258 (local-set-key ")" 'self-insert-command)
259 (local-set-key "{" 'self-insert-command)
260 (local-set-key "
\r" 'newline-and-indent)))
261 (setq c-hanging-comment-ender-p nil)
263 (defun vm-mail-other-window ()
264 "Like `vm-mail' command, but display buffer in another window."
266 (switch-to-buffer-other-window (current-buffer))
270 (setq mail-precedence-key-alist
271 '((?0 . "special-delivery")
274 (?3 . "second-class")
280 (defun mail-precedence-as-key ()
281 "Set precedence by looking up last command char in mail-precedence-key-alist"
283 (message "%s" (concat "Precedence ["
284 (mapconcat '(lambda (c) (char-to-string (car c)))
285 mail-precedence-key-alist "")
287 (let* ((key (read-char))
288 (prec (assoc key mail-precedence-key-alist)))
289 (if prec (mail-precedence (cdr prec))
290 (error "mail-precedence-as-key `%s' not found" key))))
292 (defun mail-precedence-as-key-send-and-exit (arg)
293 "Set precedence by looking up last command char in mail-precedence-key-alist,
294 then call send-and-exit."
296 (mail-precedence-as-key)
297 (execute-kbd-macro "
\ 3\ 3"))
299 (defun mail-precedence (prec)
301 (mail-position-on-field "Precedence")
304 (delete-region (point) p)
306 (insert "Precedence: " prec)
309 (defun mail-mode-setup-keys ()
310 (local-set-key "
\ 3\10" 'mail-precedence-as-key)
311 (local-set-key "
\ 3p" 'mail-precedence-as-key-send-and-exit))
312 (add-hook 'mail-mode-hook 'mail-mode-setup-keys)
313 (add-hook 'vm-mail-mode-hook 'mail-mode-setup-keys)
315 (defun vm-mail-other-window ()
316 "Like `vm-mail' command, but display buffer in another window."
318 (switch-to-buffer-other-window (current-buffer))
321 (defun mail-formletter ()
322 "Run VM-mail with ,Formletter"
325 (rename-buffer (generate-new-buffer-name "form letter") t)
326 (delete-region (point-min) (point-max))
327 (insert-file (concat vm-folder-directory ",Formletter")))
329 ; This function bound to C-x C-z
331 "Load tramp using require, if it isn't loaded already"
333 (message "Loading tramp...")
334 (require 'tramp) ; -extended
335 (message "Loading tramp...done"))
337 ; This function bound to M-+
338 (defun toggle-truncate-lines ()
339 "Toggle truncation or folding of long lines"
341 (set-variable 'truncate-lines (not truncate-lines))
345 ;(setq rmail-file-name "~/mail/RMAIL"
346 ; mail-archive-file-name "~/mail/Outbound"
347 ; rmail-primary-inbox-list '("~/mbox" "~/mail/Outbound" "~/mail/Record"
348 ; "~/mail/Import" "/var/spool/mail/ian")
349 ; rmail-delete-after-output t
350 ; rmail-last-rmail-file ""
351 ; rmail-ignored-headers (concat
352 ; "^Content-Identifier:\\|^X400-[^O][A-Za-z-]+:\\|"
353 ; rmail-ignored-headers))
355 (defun make-regexps-ignore-non-address (list)
356 (apply 'append (mapcar
358 (let ((item (mapconcat
360 (let ((s (char-to-string ch)))
361 (if (string-match "[][.*+?^$\\]" s)
366 (concat "<" item ">")
367 (concat "^" item " *\\((.*)\\)?$"))))
371 (setq bbdb-north-american-phone-numbers-p nil
372 bbdb/mail-auto-create-p t
374 bbdb-notice-auto-save-file-p t
375 bbdb-message-caching-enabled t)
378 (if (file-exists-p "~/private/private.el")
379 (load-file "~/private/private.el"))
380 (if (file-exists-p "~/private/private2.el")
381 (load-file "~/private/private2.el"))
382 (setq vm-included-text-attribution-format "%F writes (\"%s\"):\n"
383 vm-reply-subject-prefix "Re: "
384 vm-folder-directory "~/mail/"
385 vm-delete-after-saving t
386 vm-delete-empty-folders t
388 vm-auto-get-new-mail nil
389 vm-auto-next-message nil
390 vm-jump-to-new-messages nil
391 vm-jump-to-unread-messages nil
392 vm-auto-displayed-mime-content-types '("text" "multipart")
393 vm-mime-digest-discard-header-regexp "only-drop-this-header"
395 vm-included-text-prefix "> "
397 vm-auto-center-summary t
398 vm-confirm-new-folders t
399 vm-circular-folders nil
400 vm-visit-when-saving 0
401 vm-move-after-deleting t
402 vm-keep-sent-messages t
403 vm-follow-summary-cursor t
404 vm-frame-per-composition nil
405 vm-frame-per-edit nil
406 vm-frame-per-summary nil
407 vm-frame-per-folder nil
408 vm-tale-is-an-idiot t
409 vm-primary-inbox (concat vm-folder-directory "INBOX")
410 vm-sinbin-inbox (concat vm-folder-directory "SINBOX")
411 vm-uninteresting-senders "ian"
412 vm-reply-ignored-addresses
413 (make-regexps-ignore-non-address
414 '("ian@chiark.chu.cam.ac.uk" "ian" "iwj10@cus.cam.ac.uk"
415 "ian@chiark.greenend.org.uk"
416 "ijackson@nyx.cs.du.edu" "ijackson@gnu.ai.mit.edu"))
417 vm-primary-inbox (concat vm-folder-directory "INBOX")
419 vm-uninteresting-senders "ian"
420 vm-reply-ignored-addresses
421 (make-regexps-ignore-non-address
422 '("ijackson@chiark.chu.cam.ac.uk" "ijackson"
423 "iwj10@thor.cam.ac.uk" "iwj10@hermes.cam.ac.uk" "iwj10@cl.cam.ac.uk"
424 "iwj10@cam.ac.uk" "Ian.Jackson@cl.cam.ac.uk"))
425 mail-archive-file-name "~/mail/Outbound"
428 vm-startup-with-summary t
430 user-mail-address "ijackson@chiark.greenend.org.uk"
433 vm-startup-with-summary nil
434 vm-summary-format "%3n %a %2d %3m %-19.19F %s\n"
435 mail-archive-file-name "~/mail/Outbound"
436 vm-mime-8bit-text-transfer-encoding '8bit)
438 (add-hook 'vm-mode-hook
440 (local-set-key "Q" 'vm-quit)
441 (local-set-key "q" "###Q")))
442 ;(add-hook 'mail-mode-hook
444 ; (if (and (boundp 'folder-buffer)
446 ; (string= (buffer-file-name folder-buffer)
447 ; (file-truename vm-sysadmin-inbox)))
449 ; (make-local-variable 'vm-mail-header-from)
450 ; (setq vm-mail-header-from
451 ; "sysadmin@chiark.greenend.org.uk (Ian Jackson)")
452 ; (make-local-variable 'mail-archive-file-name)
453 ; (setq mail-archive-file-name
454 ; "~/mail/SOutbound")))))
458 ; (vm "/u/ijackson/mail/INBOX"))
462 ; (vm vm-sinbin-inbox))
464 (defun make-session ()
465 "Makes this emacs hard to kill by requiring ^X^Cy to kill it
466 instead of just ^X^C."
468 (global-unset-key "
\18\ 3")
469 (global-set-key "
\18\ 3y" 'save-buffers-kill-emacs))
471 ; Fix problems with M-| setting window title of emacs' parent xterm
472 ;(defun envdelete-term-termcap-windowid (list)
474 ; (mapcar '(lambda (x)
476 ; (mapcar '(lambda (x)
477 ; (if (or (string-match "^TERM=" x)
478 ; (string-match "^TERMCAP=" x)
479 ; (string-match "^WINDOWID=" x))
484 ;(setq process-environment
485 ; (envdelete-term-termcap-windowid process-environment))
487 (defun add-insertion-keys (table)
488 "Adds keybindings according to TABLE. Each element of
489 TABLE should be a four-element list.
491 BINDING should be the key to bind; FUNCTION will be the name of the
492 function defined to do the insertion; DESCRIPTION will be inserted
493 into \"Inserts ... .\", and used as the descriptive string for the
494 generated function; STRING is the string which will actually be
495 inserted into the buffer when the keystroke is pressed."
497 (let* ((head (car table))
501 (string (nth 3 head)))
505 (concat "Inserts " desc ".")
507 (list 'insert string)))
508 (funcall 'local-set-key key func))
509 (setq table (cdr table))))
511 (defun ian-sgml-setup ()
514 '(("
\ 3\r" sgml-insert-new-para "new paragraph markup" "\n<p>\n")
515 ("
\ 3\14" sgml-insert-tt-emph "tt emph markup" "<tt/")
516 ("
\ 3\10" sgml-insert-prgn-emph "prgn emph markup" "<prgn/")
517 ("
\ 3\ 5" sgml-insert-em-emph "em emfh markup" "<em/")
518 ("
\ 3\16" sgml-insert-var-empfh "var emph markup" "<var/"))))
519 (setq sgml-local-catalogs '("/jura:/usr/lib/debiandoc-sgml/sgml/catalog"))
521 (add-hook 'sgml-mode-hook 'ian-sgml-setup)
523 (defvar cite-string "> " "String to insert when citing")
525 (defun cite-region (start end)
526 "Quote each line in the region with an angle-bracket and space.
528 The citation string is taken from cite-string."
532 (narrow-to-region start end)
533 (goto-char (point-min))
538 (> (point-max) (point)))
539 (insert cite-string)))))
544 ;; (defun hack-dir-local-variables ()
545 ;; "Read per-directory local variables for the current buffer.
546 ;; Store the directory-local variables in `dir-local-variables-alist'
547 ;; and `file-local-variables-alist', without applying them."
548 ;; (when (and enable-local-variables
549 ;; (buffer-file-name))
550 ;; ;; Find the variables file.
551 ;; (let ((variables-file (dir-locals-find-file (buffer-file-name)))
555 ;; ((stringp variables-file)
556 ;; (setq dir-name (file-name-directory (buffer-file-name)))
557 ;; (setq class (dir-locals-read-from-file variables-file)))
558 ;; ((consp variables-file)
559 ;; (setq dir-name (nth 0 variables-file))
560 ;; (setq class (nth 1 variables-file))))
563 ;; (dir-locals-collect-variables
564 ;; (dir-locals-get-class-variables class) dir-name nil)))
566 ;; (dolist (elt variables)
567 ;; (unless (memq (car elt) '(eval mode))
568 ;; (setq dir-local-variables-alist
569 ;; (assq-delete-all (car elt) dir-local-variables-alist)))
570 ;; (push elt dir-local-variables-alist))
571 ;; (hack-local-variables-filter variables dir-name)))))))
573 (delete ".git/" completion-ignored-extensions)