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 (load-library "vm-reply")
11 (make-variable-buffer-local 'indent-line-function)
12 ; Un-disable narrow and eval-expression
13 (put 'narrow-to-region 'disabled nil)
14 (put 'eval-expression 'disabled nil)
15 ;(standard-display-european t)
17 (setq visible-cursor nil)
19 (setq browse-url-netscape-program "mozilla")
20 (setq common-lisp-hyperspec-root "/usr/share/doc/hyperspec/")
22 ; Make sure we don't disturb links or change ownership, use numbers
23 (setq backup-by-copying-when-mismatch t)
24 (setq backup-by-copying-when-linked t)
25 ;(setq version-control t
28 ; trim-versions-without-asking t)
31 (setq require-final-newline "ask")
32 (if (string= window-system 'x) (load-library "ian-x"))
33 (load-library "ian-aliases")
34 ; (load-library "auto-pgp")
35 ; (load-library "debian-changelog-mode")
36 ; (if (string= (getenv "TERM") "bbcb32") (setq term-file-prefix nil))
37 ; (setq explicit-shell-file-name "/usr/local/bin/tcsh")
38 (setq inhibit-local-variables t)
39 (setq enable-local-variables :safe)
40 (setq enable-recursive-minibuffers t)
41 (setq compile-command "make")
42 (setq next-line-add-newlines t)
43 (setq diff-switches "-u")
44 (setq line-move-visual nil)
47 (set-default 'indent-line-function 'insert-tab)
48 (defun defuse-electrocuting-indent ()
49 "Disable electric-indent-mode if indent-line-function is daft"
51 (eq indent-line-function 'insert-tab)
52 (electric-indent-local-mode 0)))
53 (add-hook 'after-change-major-mode-hook 'defuse-electrocuting-indent)
55 (eval-after-load "sh-script"
56 '(add-hook 'sh-mode-hook (lambda () (sh-electric-here-document-mode 0))
59 (set-variable 'search-repeat-char 28)
60 (set-fringe-mode (cons 0 nil))
61 (if (string-match "^19\." emacs-version)
63 ; (setq file-name-handler-alist ; Disable nasty auto-loading of ange-ftp
64 ; (delq (rassq 'ange-ftp-completion-hook-function file-name-handler-alist)
65 ; file-name-handler-alist))
66 (require 'find-alternate-18style)
67 (defun unset-down-mouse-23 ()
68 (local-set-key [mouse-2] 'mouse-yank-at-click)
69 (local-unset-key [down-mouse-2])
70 (local-unset-key [down-mouse-3])
71 (local-unset-key [C-down-mouse-3]))
72 (add-hook 'vm-mode-hook 'unset-down-mouse-23)
73 (add-hook 'vm-mail-mode-hook 'unset-down-mouse-23)
74 (add-hook 'text-mode-hook 'unset-down-mouse-23)
75 (add-hook 'Info-mode-hook
77 (local-set-key " " 'scroll-up)
78 (local-set-key "
\7f" 'scroll-down))))
79 (add-hook 'sh-mode-hook
81 (local-set-key "<" 'self-insert-command))))
82 (define-key isearch-mode-map "
\1c" 'isearch-repeat-forward)
83 (define-key isearch-mode-map "
\1d" 'isearch-quote-char)))
86 (defun terminal-keybindings ()
87 "This function should be called by the term-setup-hook mechanism"
89 ; Set my own keybindings
91 ; Set keybindings generally (including I-search on C-\)
92 ; (global-set-key " " 'self-insert-command)
93 (global-set-key "
\1c" 'isearch-forward)
94 ; (global-set-key "
\r" 'newline)
95 (global-set-key "
\ f" 'set-mark-command)
96 (global-set-key "
\1d" 'quoted-insert)
98 ; Set keybindings on esc-map
99 (global-set-key "
\e#" 'query-replace-regexp)
100 (global-set-key "
\e+" 'toggle-truncate-lines)
101 (global-set-key "
\eg" 'goto-line)
102 (global-set-key "
\es" 'isearch-forward-regexp)
103 (global-set-key "
\e\e" 'eval-expression)
105 ; Set keybindings on ^X-map.
106 (global-set-key "
\18m" 'vm-mail)
107 (global-set-key "
\18\1c" 'save-buffer)
108 (global-set-key "
\18\1d" 'toggle-read-only)
109 (global-set-key "
\18#" 'recover-file)
110 (global-set-key "
\18\12" 'bury-buffer)
111 (global-set-key "
\18\v" 'quicker-compile)
112 (global-set-key "
\18\18" 'exchange-point-and-mark)
113 (global-set-key "
\18\1a" 'load-tramp)
114 (global-set-key "
\18g" 'magit-status)
115 (global-set-key "
\18\eg" 'magit-dispatch-popup)
116 (global-set-key "
\184
\16" 'scroll-other-window)
117 (global-set-key "
\184m" 'vm-mail-other-window)
118 (global-set-key "
\189" 'vm-visit-folder)
119 (global-set-key "
\188" 'rmail-input)
120 (global-set-key "
\18p" 'cite-region)
121 (global-set-key "
\18F" 'mail-formletter)
123 ; Set keybindings for Sun numeric pad.
124 (setq esc-bracket-map (make-keymap))
125 (define-key esc-bracket-map "D" 'backward-char)
126 (define-key esc-bracket-map "C" 'forward-char)
127 (define-key esc-bracket-map "A" 'previous-line)
128 (define-key esc-bracket-map "B" 'next-line)
129 (define-key esc-map "[" esc-bracket-map)
130 (global-set-key "\e[214z" 'beginning-of-buffer)
131 (global-set-key "\e[220z" 'end-of-buffer)
132 (global-set-key "\e[216z" 'scroll-down)
133 (global-set-key "\e[222z" 'scroll-up)
134 (global-set-key "\e[192z" 'save-buffer)
135 (global-set-key "\e[194z" 'save-some-buffers)
136 (global-set-key "\e[195z" 'undo)
137 (global-set-key "\e[193z" 'call-last-kbd-macro)
138 (global-set-key "\e[196z" 'switch-to-buffer-other-window)
139 (global-set-key "\e[197z" 'copy-region-as-kill)
140 (global-set-key "\e[198z" 'find-file)
141 (global-set-key "\e[199z" 'yank)
142 (global-set-key "\e[198z" 'find-alternate-file)
143 (global-set-key "\e[200z" 'find-file)
144 (global-set-key "\e[201z" 'kill-region)
145 (global-set-key "\e[-1z" 'info)
147 ; Set keybindings for Chiarks' x11emacs
148 (global-set-key "
\e[5~" 'scroll-down)
149 (global-set-key "
\e[6~" 'scroll-up)
151 ; Set keybindings for knackered vt100-like terminal emulators.
152 (global-set-key "\eOt" 'scroll-down)
153 (global-set-key "\eOu" 'scroll-up)
154 (global-set-key "\eOD" 'backward-char)
155 (global-set-key "\eOC" 'forward-char)
156 (global-set-key "\eOA" 'previous-line)
157 (global-set-key "\eOB" 'next-line))
158 (setq term-setup-hook 'terminal-keybindings) ; remap keys in due course
160 (setq frame-title-format
164 ((buf (current-buffer))
165 (leaf (buffer-name buf))
166 (dir default-directory))
169 ((dir (abbreviate-file-name dir))
170 (node (replace-regexp-in-string "\\..*" "" system-name)))
171 (concat leaf " " node ":" dir))
173 ("" invocation-name "@" system-name)))
174 ;(setq frame-title-format
178 ; ((buf (current-buffer))
179 ; (fn (buffer-file-name buf)))
182 ; ((fn (abbreviate-file-name fn))
183 ; (dir (file-name-directory fn))
184 ; (leaf (file-name-nondirectory fn))
185 ; (node (replace-regexp-in-string "\\..*" "" system-name)))
186 ; (concat leaf " " node ":" dir))
187 ; (buffer-name buf))))
188 ; ("" invocation-name "@" system-name)))
190 ; Autoload definitions
191 (autoload 'tar-mode "tar-mode")
192 (autoload 'uncompress-while-visiting "uncompress")
193 ; (autoload 'c++-mode "c++-mode" "Mode for editing C and C++ programs" t)
194 (autoload 'hide-ifdef-mode "hideif" "For editing code with #ifdefs" t)
195 ;(setq-default indent-tabs-mode nil)
196 (autoload 'dired-find-alternate-file "dired-alternate" "Find alternately" t)
197 (autoload 'dired-run-file "dired-alternate" "Run this file" t)
198 (autoload 'perl-mode "perl-mode" "Mode for Perl code" t)
199 ; (autoload 'rmail "rmail-fixed" "Patched mail reader" t)
200 (autoload 'quicker-compile "quicker-compile" "Patched Compile mode" t)
202 ;(autoload 'vm "vm" "Start VM on your primary inbox." t)
203 ;(autoload 'vm-visit-folder "vm" "Start VM on an arbitrary folder." t)
204 ;(autoload 'vm-visit-virtual-folder "vm" "Visit a VM virtual folder." t)
205 ;(autoload 'vm-mode "vm" "Run VM major mode on a buffer" t)
206 ;(autoload 'vm-mail "vm" "Send a mail message using VM." t)
207 ;(autoload 'vm-submit-bug-report "vm" "Send a bug report about VM." t)
209 ;(require 'vm-autoload)
211 (vm-legacy-key-bindings)
213 ; (autoload 'info "info-fixed" "Patched info browser" t)
214 (setq shell-mode-hook
216 (make-variable-buffer-local 'scroll-step)
217 (setq scroll-step 1)))
218 (setq inferior-lisp-program "sbcl")
219 ;(setq jit-lock-chunk-size 100
220 ; jit-lock-stealth-time 1.00)
221 (setq dired-mode-hook
223 (define-key dired-mode-map "F" 'dired-find-alternate-file)
224 (define-key dired-mode-map "X" 'dired-run-file)))
226 ; Prevent loading of default init file and do some of the things it did
227 ; (setq inhibit-default-init t)
229 ; Additional alist handling function
230 ;(defun alist-remove-elem (s s-list)
231 ; "Delete the element of the alist S-LIST whose car is S"
232 ; (if s-list (if (equal s (car (car s-list)))
234 ; (cons (car s-list) (alist-remove-elem s (cdr s-list))))
237 ; Load C++ mode and edit Perl in perl mode
238 (setq auto-mode-alist
239 (append '(("\\.[ch]$" . c-mode)
240 ("\\.[CH]$" . c++-mode)
241 ("\\.cc$" . c++-mode)
242 ("\\.hh$" . c++-mode)
243 ; ("\\.tar$" . tar-mode)
244 ("\\.pl$" . perl-mode)
245 ("\\.ci$" . tex-mode)
246 ("\\.asm$" . fundamental-mode)
247 ("\\.Z$" . uncompress-while-visiting))
249 (setq interpreter-mode-alist
250 (append '(("sh" . fundamental-mode)
251 ("bash" . fundamental-mode))
252 interpreter-mode-alist))
254 ; Use auto-fill when editing text
255 (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
256 ; (add-hook 'text-mode-hook '(lambda () (local-set-key " " 'self-insert-command)))
258 ; Set up newline to auto-indent & other stuff for perl, c++ and c modes.
259 (setq perl-mode-hook '(lambda ()
260 (local-set-key ";" 'self-insert-command)))
261 (setq c++-mode-hook '(lambda ()
263 (local-set-key "," 'self-insert-command)
264 (local-set-key ":" 'electric-c++-terminator)))
266 (setq c-mode-hook '(lambda ()
268 (c-set-offset 'substatement-open 0 nil)
269 (local-set-key "," 'self-insert-command)
270 (local-set-key ";" 'self-insert-command)
271 (local-set-key "/" 'self-insert-command)
272 (local-set-key "*" 'self-insert-command)
273 (local-set-key "#" 'self-insert-command)
274 (local-set-key "(" 'self-insert-command)
275 (local-set-key ")" 'self-insert-command)
276 (local-set-key "{" 'self-insert-command)
277 (local-set-key "
\r" 'newline-and-indent)))
278 (setq c-hanging-comment-ender-p nil)
280 (defun vm-mail-other-window ()
281 "Like `vm-mail' command, but display buffer in another window."
283 (switch-to-buffer-other-window (current-buffer))
287 (setq mail-precedence-key-alist
288 '((?0 . "special-delivery")
291 (?3 . "second-class")
297 (defun mail-precedence-as-key ()
298 "Set precedence by looking up last command char in mail-precedence-key-alist"
300 (message "%s" (concat "Precedence ["
301 (mapconcat '(lambda (c) (char-to-string (car c)))
302 mail-precedence-key-alist "")
304 (let* ((key (read-char))
305 (prec (assoc key mail-precedence-key-alist)))
306 (if prec (mail-precedence (cdr prec))
307 (error "mail-precedence-as-key `%s' not found" key))))
309 (defun mail-precedence-as-key-send-and-exit (arg)
310 "Set precedence by looking up last command char in mail-precedence-key-alist,
311 then call send-and-exit."
313 (mail-precedence-as-key)
314 (execute-kbd-macro "
\ 3\ 3"))
316 (defun mail-precedence (prec)
318 (mail-position-on-field "Precedence")
321 (delete-region (point) p)
323 (insert "Precedence: " prec)
326 (defun mail-mode-setup-keys ()
327 (local-set-key "
\ 3\10" 'mail-precedence-as-key)
328 (local-set-key "
\ 3p" 'mail-precedence-as-key-send-and-exit))
329 (add-hook 'mail-mode-hook 'mail-mode-setup-keys)
330 (add-hook 'vm-mail-mode-hook 'mail-mode-setup-keys)
332 (defun vm-mail-other-window ()
333 "Like `vm-mail' command, but display buffer in another window."
335 (switch-to-buffer-other-window (current-buffer))
338 (defun mail-formletter ()
339 "Run VM-mail with ,Formletter"
342 (rename-buffer (generate-new-buffer-name "form letter") t)
343 (delete-region (point-min) (point-max))
344 (insert-file (concat vm-folder-directory ",Formletter")))
346 ; This function bound to C-x C-z
348 "Load tramp using require, if it isn't loaded already"
350 (message "Loading tramp...")
351 (require 'tramp) ; -extended
352 (message "Loading tramp...done"))
354 ; This function bound to M-+
355 (defun toggle-truncate-lines ()
356 "Toggle truncation or folding of long lines"
358 (set-variable 'truncate-lines (not truncate-lines))
362 ;(setq rmail-file-name "~/mail/RMAIL"
363 ; mail-archive-file-name "~/mail/Outbound"
364 ; rmail-primary-inbox-list '("~/mbox" "~/mail/Outbound" "~/mail/Record"
365 ; "~/mail/Import" "/var/spool/mail/ian")
366 ; rmail-delete-after-output t
367 ; rmail-last-rmail-file ""
368 ; rmail-ignored-headers (concat
369 ; "^Content-Identifier:\\|^X400-[^O][A-Za-z-]+:\\|"
370 ; rmail-ignored-headers))
372 (defun make-regexps-ignore-non-address (list)
373 (apply 'append (mapcar
375 (let ((item (mapconcat
377 (let ((s (char-to-string ch)))
378 (if (string-match "[][.*+?^$\\]" s)
383 (concat "<" item ">")
384 (concat "^" item " *\\((.*)\\)?$"))))
388 (setq bbdb-north-american-phone-numbers-p nil
389 bbdb/mail-auto-create-p t
391 bbdb-notice-auto-save-file-p t
392 bbdb-message-caching-enabled t)
395 (if (file-exists-p "~/private/private.el")
396 (load-file "~/private/private.el"))
397 (if (file-exists-p "~/private/private2.el")
398 (load-file "~/private/private2.el"))
399 (setq vm-included-text-attribution-format "%F writes (\"%s\"):\n"
400 vm-reply-subject-prefix "Re: "
401 vm-folder-directory "~/mail/"
402 vm-delete-after-saving t
403 vm-delete-empty-folders t
405 vm-auto-get-new-mail nil
406 vm-auto-next-message nil
407 vm-jump-to-new-messages nil
408 vm-jump-to-unread-messages nil
409 vm-auto-displayed-mime-content-types '("text" "multipart")
410 vm-mime-digest-discard-header-regexp "only-drop-this-header"
412 vm-included-text-prefix "> "
414 vm-auto-center-summary t
415 vm-confirm-new-folders t
416 vm-circular-folders nil
417 vm-visit-when-saving 0
418 vm-move-after-deleting t
419 vm-keep-sent-messages t
420 vm-follow-summary-cursor t
421 vm-frame-per-composition nil
422 vm-frame-per-edit nil
423 vm-frame-per-summary nil
424 vm-frame-per-folder nil
425 vm-tale-is-an-idiot t
426 vm-primary-inbox (concat vm-folder-directory "INBOX")
427 vm-sinbin-inbox (concat vm-folder-directory "SINBOX")
428 vm-uninteresting-senders "ian"
429 vm-reply-ignored-addresses
430 (make-regexps-ignore-non-address
431 '("ian@chiark.chu.cam.ac.uk" "ian" "iwj10@cus.cam.ac.uk"
432 "ian@chiark.greenend.org.uk"
433 "ijackson@nyx.cs.du.edu" "ijackson@gnu.ai.mit.edu"))
434 vm-primary-inbox (concat vm-folder-directory "INBOX")
436 vm-uninteresting-senders "ian"
437 vm-reply-ignored-addresses
438 (make-regexps-ignore-non-address
439 '("ijackson@chiark.chu.cam.ac.uk" "ijackson"
440 "iwj10@thor.cam.ac.uk" "iwj10@hermes.cam.ac.uk" "iwj10@cl.cam.ac.uk"
441 "iwj10@cam.ac.uk" "Ian.Jackson@cl.cam.ac.uk"))
442 mail-archive-file-name "~/mail/Outbound"
445 vm-startup-with-summary t
447 user-mail-address "ijackson@chiark.greenend.org.uk"
450 vm-startup-with-summary nil
451 vm-summary-format "%3n %a %2d %3m %-19.19F %s\n"
452 mail-archive-file-name "~/mail/Outbound"
453 vm-mime-8bit-text-transfer-encoding '8bit)
455 (add-hook 'vm-mode-hook
457 (local-set-key "Q" 'vm-quit)
458 (local-set-key "q" "###Q")))
459 ;(add-hook 'mail-mode-hook
461 ; (if (and (boundp 'folder-buffer)
463 ; (string= (buffer-file-name folder-buffer)
464 ; (file-truename vm-sysadmin-inbox)))
466 ; (make-local-variable 'vm-mail-header-from)
467 ; (setq vm-mail-header-from
468 ; "sysadmin@chiark.greenend.org.uk (Ian Jackson)")
469 ; (make-local-variable 'mail-archive-file-name)
470 ; (setq mail-archive-file-name
471 ; "~/mail/SOutbound")))))
475 ; (vm "/u/ijackson/mail/INBOX"))
479 ; (vm vm-sinbin-inbox))
481 (defun make-session ()
482 "Makes this emacs hard to kill by requiring ^X^Cy to kill it
483 instead of just ^X^C."
485 (global-unset-key "
\18\ 3")
486 (global-set-key "
\18\ 3y" 'save-buffers-kill-emacs))
488 ; Fix problems with M-| setting window title of emacs' parent xterm
489 ;(defun envdelete-term-termcap-windowid (list)
491 ; (mapcar '(lambda (x)
493 ; (mapcar '(lambda (x)
494 ; (if (or (string-match "^TERM=" x)
495 ; (string-match "^TERMCAP=" x)
496 ; (string-match "^WINDOWID=" x))
501 ;(setq process-environment
502 ; (envdelete-term-termcap-windowid process-environment))
504 (defun add-insertion-keys (table)
505 "Adds keybindings according to TABLE. Each element of
506 TABLE should be a four-element list.
508 BINDING should be the key to bind; FUNCTION will be the name of the
509 function defined to do the insertion; DESCRIPTION will be inserted
510 into \"Inserts ... .\", and used as the descriptive string for the
511 generated function; STRING is the string which will actually be
512 inserted into the buffer when the keystroke is pressed."
514 (let* ((head (car table))
518 (string (nth 3 head)))
522 (concat "Inserts " desc ".")
524 (list 'insert string)))
525 (funcall 'local-set-key key func))
526 (setq table (cdr table))))
528 (defun ian-sgml-setup ()
531 '(("
\ 3\r" sgml-insert-new-para "new paragraph markup" "\n<p>\n")
532 ("
\ 3\14" sgml-insert-tt-emph "tt emph markup" "<tt/")
533 ("
\ 3\10" sgml-insert-prgn-emph "prgn emph markup" "<prgn/")
534 ("
\ 3\ 5" sgml-insert-em-emph "em emfh markup" "<em/")
535 ("
\ 3\16" sgml-insert-var-empfh "var emph markup" "<var/"))))
536 (setq sgml-local-catalogs '("/jura:/usr/lib/debiandoc-sgml/sgml/catalog"))
538 (add-hook 'sgml-mode-hook 'ian-sgml-setup)
540 (defvar cite-string "> " "String to insert when citing")
542 (defun cite-region (start end)
543 "Quote each line in the region with an angle-bracket and space.
545 The citation string is taken from cite-string."
549 (narrow-to-region start end)
550 (goto-char (point-min))
555 (> (point-max) (point)))
556 (insert cite-string)))))
562 (global-magit-file-mode)
564 (magit-wip-after-save-mode)
565 (magit-wip-after-apply-mode)
566 (magit-wip-before-change-mode)
567 (setq magit-no-confirm
568 (append magit-no-confirm '(safe-with-wip)))
570 (setq vc-handled-backends (delq 'Git vc-handled-backends))
572 ;; (defun hack-dir-local-variables ()
573 ;; "Read per-directory local variables for the current buffer.
574 ;; Store the directory-local variables in `dir-local-variables-alist'
575 ;; and `file-local-variables-alist', without applying them."
576 ;; (when (and enable-local-variables
577 ;; (buffer-file-name))
578 ;; ;; Find the variables file.
579 ;; (let ((variables-file (dir-locals-find-file (buffer-file-name)))
583 ;; ((stringp variables-file)
584 ;; (setq dir-name (file-name-directory (buffer-file-name)))
585 ;; (setq class (dir-locals-read-from-file variables-file)))
586 ;; ((consp variables-file)
587 ;; (setq dir-name (nth 0 variables-file))
588 ;; (setq class (nth 1 variables-file))))
591 ;; (dir-locals-collect-variables
592 ;; (dir-locals-get-class-variables class) dir-name nil)))
594 ;; (dolist (elt variables)
595 ;; (unless (memq (car elt) '(eval mode))
596 ;; (setq dir-local-variables-alist
597 ;; (assq-delete-all (car elt) dir-local-variables-alist)))
598 ;; (push elt dir-local-variables-alist))
599 ;; (hack-local-variables-filter variables dir-name)))))))
601 (delete ".git/" completion-ignored-extensions)