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 (defun defuse-electrocuting-indent ()
45 "Disable electric-indent-mode if indent-line-function is daft"
47 (eq indent-line-function 'insert-tab)
48 (electric-indent-local-mode 0)))
49 (add-hook 'after-change-major-mode-hook 'defuse-electrocuting-indent)
51 (set-variable 'search-repeat-char 28)
52 (set-fringe-mode (cons 0 nil))
53 (if (string-match "^19\." emacs-version)
55 ; (setq file-name-handler-alist ; Disable nasty auto-loading of ange-ftp
56 ; (delq (rassq 'ange-ftp-completion-hook-function file-name-handler-alist)
57 ; file-name-handler-alist))
58 (require 'find-alternate-18style)
59 (defun unset-down-mouse-23 ()
60 (local-set-key [mouse-2] 'mouse-yank-at-click)
61 (local-unset-key [down-mouse-2])
62 (local-unset-key [down-mouse-3])
63 (local-unset-key [C-down-mouse-3]))
64 (add-hook 'vm-mode-hook 'unset-down-mouse-23)
65 (add-hook 'vm-mail-mode-hook 'unset-down-mouse-23)
66 (add-hook 'text-mode-hook 'unset-down-mouse-23)
67 (add-hook 'Info-mode-hook
69 (local-set-key " " 'scroll-up)
70 (local-set-key "
\7f" 'scroll-down))))
71 (add-hook 'sh-mode-hook
73 (local-set-key "<" 'self-insert-command))))
74 (define-key isearch-mode-map "
\1c" 'isearch-repeat-forward)
75 (define-key isearch-mode-map "
\1d" 'isearch-quote-char)))
78 (defun terminal-keybindings ()
79 "This function should be called by the term-setup-hook mechanism"
81 ; Set my own keybindings
83 ; Set keybindings generally (including I-search on C-\)
84 ; (global-set-key " " 'self-insert-command)
85 (global-set-key "
\1c" 'isearch-forward)
86 ; (global-set-key "
\r" 'newline)
87 (global-set-key "
\ f" 'set-mark-command)
88 (global-set-key "
\1d" 'quoted-insert)
90 ; Set keybindings on esc-map
91 (global-set-key "
\e#" 'query-replace-regexp)
92 (global-set-key "
\e+" 'toggle-truncate-lines)
93 (global-set-key "
\eg" 'goto-line)
94 (global-set-key "
\es" 'isearch-forward-regexp)
95 (global-set-key "
\e\e" 'eval-expression)
97 ; Set keybindings on ^X-map.
98 (global-set-key "
\18m" 'vm-mail)
99 (global-set-key "
\18\1c" 'save-buffer)
100 (global-set-key "
\18\1d" 'toggle-read-only)
101 (global-set-key "
\18#" 'recover-file)
102 (global-set-key "
\18\12" 'bury-buffer)
103 (global-set-key "
\18\v" 'quicker-compile)
104 (global-set-key "
\18\18" 'exchange-point-and-mark)
105 (global-set-key "
\18\1a" 'load-tramp)
106 (global-set-key "
\18g" 'magit-status)
107 (global-set-key "
\18\eg" 'magit-dispatch-popup)
108 (global-set-key "
\184
\16" 'scroll-other-window)
109 (global-set-key "
\184m" 'vm-mail-other-window)
110 (global-set-key "
\189" 'vm-visit-folder)
111 (global-set-key "
\188" 'rmail-input)
112 (global-set-key "
\18p" 'cite-region)
113 (global-set-key "
\18F" 'mail-formletter)
115 ; Set keybindings for Sun numeric pad.
116 (setq esc-bracket-map (make-keymap))
117 (define-key esc-bracket-map "D" 'backward-char)
118 (define-key esc-bracket-map "C" 'forward-char)
119 (define-key esc-bracket-map "A" 'previous-line)
120 (define-key esc-bracket-map "B" 'next-line)
121 (define-key esc-map "[" esc-bracket-map)
122 (global-set-key "\e[214z" 'beginning-of-buffer)
123 (global-set-key "\e[220z" 'end-of-buffer)
124 (global-set-key "\e[216z" 'scroll-down)
125 (global-set-key "\e[222z" 'scroll-up)
126 (global-set-key "\e[192z" 'save-buffer)
127 (global-set-key "\e[194z" 'save-some-buffers)
128 (global-set-key "\e[195z" 'undo)
129 (global-set-key "\e[193z" 'call-last-kbd-macro)
130 (global-set-key "\e[196z" 'switch-to-buffer-other-window)
131 (global-set-key "\e[197z" 'copy-region-as-kill)
132 (global-set-key "\e[198z" 'find-file)
133 (global-set-key "\e[199z" 'yank)
134 (global-set-key "\e[198z" 'find-alternate-file)
135 (global-set-key "\e[200z" 'find-file)
136 (global-set-key "\e[201z" 'kill-region)
137 (global-set-key "\e[-1z" 'info)
139 ; Set keybindings for Chiarks' x11emacs
140 (global-set-key "
\e[5~" 'scroll-down)
141 (global-set-key "
\e[6~" 'scroll-up)
143 ; Set keybindings for knackered vt100-like terminal emulators.
144 (global-set-key "\eOt" 'scroll-down)
145 (global-set-key "\eOu" 'scroll-up)
146 (global-set-key "\eOD" 'backward-char)
147 (global-set-key "\eOC" 'forward-char)
148 (global-set-key "\eOA" 'previous-line)
149 (global-set-key "\eOB" 'next-line))
150 (setq term-setup-hook 'terminal-keybindings) ; remap keys in due course
152 (setq frame-title-format
156 ((buf (current-buffer))
157 (leaf (buffer-name buf))
158 (dir default-directory))
161 ((dir (abbreviate-file-name dir))
162 (node (replace-regexp-in-string "\\..*" "" system-name)))
163 (concat leaf " " node ":" dir))
165 ("" invocation-name "@" system-name)))
166 ;(setq frame-title-format
170 ; ((buf (current-buffer))
171 ; (fn (buffer-file-name buf)))
174 ; ((fn (abbreviate-file-name fn))
175 ; (dir (file-name-directory fn))
176 ; (leaf (file-name-nondirectory fn))
177 ; (node (replace-regexp-in-string "\\..*" "" system-name)))
178 ; (concat leaf " " node ":" dir))
179 ; (buffer-name buf))))
180 ; ("" invocation-name "@" system-name)))
182 ; Autoload definitions
183 (autoload 'tar-mode "tar-mode")
184 (autoload 'uncompress-while-visiting "uncompress")
185 ; (autoload 'c++-mode "c++-mode" "Mode for editing C and C++ programs" t)
186 (autoload 'hide-ifdef-mode "hideif" "For editing code with #ifdefs" t)
187 ;(setq-default indent-tabs-mode nil)
188 (autoload 'dired-find-alternate-file "dired-alternate" "Find alternately" t)
189 (autoload 'dired-run-file "dired-alternate" "Run this file" t)
190 (autoload 'perl-mode "perl-mode" "Mode for Perl code" t)
191 ; (autoload 'rmail "rmail-fixed" "Patched mail reader" t)
192 (autoload 'quicker-compile "quicker-compile" "Patched Compile mode" t)
194 ;(autoload 'vm "vm" "Start VM on your primary inbox." t)
195 ;(autoload 'vm-visit-folder "vm" "Start VM on an arbitrary folder." t)
196 ;(autoload 'vm-visit-virtual-folder "vm" "Visit a VM virtual folder." t)
197 ;(autoload 'vm-mode "vm" "Run VM major mode on a buffer" t)
198 ;(autoload 'vm-mail "vm" "Send a mail message using VM." t)
199 ;(autoload 'vm-submit-bug-report "vm" "Send a bug report about VM." t)
201 ;(require 'vm-autoload)
203 (vm-legacy-key-bindings)
205 ; (autoload 'info "info-fixed" "Patched info browser" t)
206 (setq shell-mode-hook
208 (make-variable-buffer-local 'scroll-step)
209 (setq scroll-step 1)))
210 (setq inferior-lisp-program "sbcl")
211 ;(setq jit-lock-chunk-size 100
212 ; jit-lock-stealth-time 1.00)
213 (setq dired-mode-hook
215 (define-key dired-mode-map "F" 'dired-find-alternate-file)
216 (define-key dired-mode-map "X" 'dired-run-file)))
218 ; Prevent loading of default init file and do some of the things it did
219 ; (setq inhibit-default-init t)
221 ; Additional alist handling function
222 ;(defun alist-remove-elem (s s-list)
223 ; "Delete the element of the alist S-LIST whose car is S"
224 ; (if s-list (if (equal s (car (car s-list)))
226 ; (cons (car s-list) (alist-remove-elem s (cdr s-list))))
229 ; Load C++ mode and edit Perl in perl mode
230 (setq auto-mode-alist
231 (append '(("\\.[ch]$" . c-mode)
232 ("\\.[CH]$" . c++-mode)
233 ("\\.cc$" . c++-mode)
234 ("\\.hh$" . c++-mode)
235 ; ("\\.tar$" . tar-mode)
236 ("\\.pl$" . perl-mode)
237 ("\\.ci$" . tex-mode)
238 ("\\.asm$" . fundamental-mode)
239 ("\\.Z$" . uncompress-while-visiting))
241 (setq interpreter-mode-alist
242 (append '(("sh" . fundamental-mode)
243 ("bash" . fundamental-mode))
244 interpreter-mode-alist))
246 ; Use auto-fill when editing text
247 (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
248 ; (add-hook 'text-mode-hook '(lambda () (local-set-key " " 'self-insert-command)))
250 ; Set up newline to auto-indent & other stuff for perl, c++ and c modes.
251 (setq perl-mode-hook '(lambda ()
252 (local-set-key ";" 'self-insert-command)))
253 (setq c++-mode-hook '(lambda ()
255 (local-set-key "," 'self-insert-command)
256 (local-set-key ":" 'electric-c++-terminator)))
258 (setq c-mode-hook '(lambda ()
260 (c-set-offset 'substatement-open 0 nil)
261 (local-set-key "," 'self-insert-command)
262 (local-set-key ";" 'self-insert-command)
263 (local-set-key "/" 'self-insert-command)
264 (local-set-key "*" 'self-insert-command)
265 (local-set-key "#" 'self-insert-command)
266 (local-set-key "(" 'self-insert-command)
267 (local-set-key ")" 'self-insert-command)
268 (local-set-key "{" 'self-insert-command)
269 (local-set-key "
\r" 'newline-and-indent)))
270 (setq c-hanging-comment-ender-p nil)
272 (defun vm-mail-other-window ()
273 "Like `vm-mail' command, but display buffer in another window."
275 (switch-to-buffer-other-window (current-buffer))
279 (setq mail-precedence-key-alist
280 '((?0 . "special-delivery")
283 (?3 . "second-class")
289 (defun mail-precedence-as-key ()
290 "Set precedence by looking up last command char in mail-precedence-key-alist"
292 (message "%s" (concat "Precedence ["
293 (mapconcat '(lambda (c) (char-to-string (car c)))
294 mail-precedence-key-alist "")
296 (let* ((key (read-char))
297 (prec (assoc key mail-precedence-key-alist)))
298 (if prec (mail-precedence (cdr prec))
299 (error "mail-precedence-as-key `%s' not found" key))))
301 (defun mail-precedence-as-key-send-and-exit (arg)
302 "Set precedence by looking up last command char in mail-precedence-key-alist,
303 then call send-and-exit."
305 (mail-precedence-as-key)
306 (execute-kbd-macro "
\ 3\ 3"))
308 (defun mail-precedence (prec)
310 (mail-position-on-field "Precedence")
313 (delete-region (point) p)
315 (insert "Precedence: " prec)
318 (defun mail-mode-setup-keys ()
319 (local-set-key "
\ 3\10" 'mail-precedence-as-key)
320 (local-set-key "
\ 3p" 'mail-precedence-as-key-send-and-exit))
321 (add-hook 'mail-mode-hook 'mail-mode-setup-keys)
322 (add-hook 'vm-mail-mode-hook 'mail-mode-setup-keys)
324 (defun vm-mail-other-window ()
325 "Like `vm-mail' command, but display buffer in another window."
327 (switch-to-buffer-other-window (current-buffer))
330 (defun mail-formletter ()
331 "Run VM-mail with ,Formletter"
334 (rename-buffer (generate-new-buffer-name "form letter") t)
335 (delete-region (point-min) (point-max))
336 (insert-file (concat vm-folder-directory ",Formletter")))
338 ; This function bound to C-x C-z
340 "Load tramp using require, if it isn't loaded already"
342 (message "Loading tramp...")
343 (require 'tramp) ; -extended
344 (message "Loading tramp...done"))
346 ; This function bound to M-+
347 (defun toggle-truncate-lines ()
348 "Toggle truncation or folding of long lines"
350 (set-variable 'truncate-lines (not truncate-lines))
354 ;(setq rmail-file-name "~/mail/RMAIL"
355 ; mail-archive-file-name "~/mail/Outbound"
356 ; rmail-primary-inbox-list '("~/mbox" "~/mail/Outbound" "~/mail/Record"
357 ; "~/mail/Import" "/var/spool/mail/ian")
358 ; rmail-delete-after-output t
359 ; rmail-last-rmail-file ""
360 ; rmail-ignored-headers (concat
361 ; "^Content-Identifier:\\|^X400-[^O][A-Za-z-]+:\\|"
362 ; rmail-ignored-headers))
364 (defun make-regexps-ignore-non-address (list)
365 (apply 'append (mapcar
367 (let ((item (mapconcat
369 (let ((s (char-to-string ch)))
370 (if (string-match "[][.*+?^$\\]" s)
375 (concat "<" item ">")
376 (concat "^" item " *\\((.*)\\)?$"))))
380 (setq bbdb-north-american-phone-numbers-p nil
381 bbdb/mail-auto-create-p t
383 bbdb-notice-auto-save-file-p t
384 bbdb-message-caching-enabled t)
387 (if (file-exists-p "~/private/private.el")
388 (load-file "~/private/private.el"))
389 (if (file-exists-p "~/private/private2.el")
390 (load-file "~/private/private2.el"))
391 (setq vm-included-text-attribution-format "%F writes (\"%s\"):\n"
392 vm-reply-subject-prefix "Re: "
393 vm-folder-directory "~/mail/"
394 vm-delete-after-saving t
395 vm-delete-empty-folders t
397 vm-auto-get-new-mail nil
398 vm-auto-next-message nil
399 vm-jump-to-new-messages nil
400 vm-jump-to-unread-messages nil
401 vm-auto-displayed-mime-content-types '("text" "multipart")
402 vm-mime-digest-discard-header-regexp "only-drop-this-header"
404 vm-included-text-prefix "> "
406 vm-auto-center-summary t
407 vm-confirm-new-folders t
408 vm-circular-folders nil
409 vm-visit-when-saving 0
410 vm-move-after-deleting t
411 vm-keep-sent-messages t
412 vm-follow-summary-cursor t
413 vm-frame-per-composition nil
414 vm-frame-per-edit nil
415 vm-frame-per-summary nil
416 vm-frame-per-folder nil
417 vm-tale-is-an-idiot t
418 vm-primary-inbox (concat vm-folder-directory "INBOX")
419 vm-sinbin-inbox (concat vm-folder-directory "SINBOX")
420 vm-uninteresting-senders "ian"
421 vm-reply-ignored-addresses
422 (make-regexps-ignore-non-address
423 '("ian@chiark.chu.cam.ac.uk" "ian" "iwj10@cus.cam.ac.uk"
424 "ian@chiark.greenend.org.uk"
425 "ijackson@nyx.cs.du.edu" "ijackson@gnu.ai.mit.edu"))
426 vm-primary-inbox (concat vm-folder-directory "INBOX")
428 vm-uninteresting-senders "ian"
429 vm-reply-ignored-addresses
430 (make-regexps-ignore-non-address
431 '("ijackson@chiark.chu.cam.ac.uk" "ijackson"
432 "iwj10@thor.cam.ac.uk" "iwj10@hermes.cam.ac.uk" "iwj10@cl.cam.ac.uk"
433 "iwj10@cam.ac.uk" "Ian.Jackson@cl.cam.ac.uk"))
434 mail-archive-file-name "~/mail/Outbound"
437 vm-startup-with-summary t
439 user-mail-address "ijackson@chiark.greenend.org.uk"
442 vm-startup-with-summary nil
443 vm-summary-format "%3n %a %2d %3m %-19.19F %s\n"
444 mail-archive-file-name "~/mail/Outbound"
445 vm-mime-8bit-text-transfer-encoding '8bit)
447 (add-hook 'vm-mode-hook
449 (local-set-key "Q" 'vm-quit)
450 (local-set-key "q" "###Q")))
451 ;(add-hook 'mail-mode-hook
453 ; (if (and (boundp 'folder-buffer)
455 ; (string= (buffer-file-name folder-buffer)
456 ; (file-truename vm-sysadmin-inbox)))
458 ; (make-local-variable 'vm-mail-header-from)
459 ; (setq vm-mail-header-from
460 ; "sysadmin@chiark.greenend.org.uk (Ian Jackson)")
461 ; (make-local-variable 'mail-archive-file-name)
462 ; (setq mail-archive-file-name
463 ; "~/mail/SOutbound")))))
467 ; (vm "/u/ijackson/mail/INBOX"))
471 ; (vm vm-sinbin-inbox))
473 (defun make-session ()
474 "Makes this emacs hard to kill by requiring ^X^Cy to kill it
475 instead of just ^X^C."
477 (global-unset-key "
\18\ 3")
478 (global-set-key "
\18\ 3y" 'save-buffers-kill-emacs))
480 ; Fix problems with M-| setting window title of emacs' parent xterm
481 ;(defun envdelete-term-termcap-windowid (list)
483 ; (mapcar '(lambda (x)
485 ; (mapcar '(lambda (x)
486 ; (if (or (string-match "^TERM=" x)
487 ; (string-match "^TERMCAP=" x)
488 ; (string-match "^WINDOWID=" x))
493 ;(setq process-environment
494 ; (envdelete-term-termcap-windowid process-environment))
496 (defun add-insertion-keys (table)
497 "Adds keybindings according to TABLE. Each element of
498 TABLE should be a four-element list.
500 BINDING should be the key to bind; FUNCTION will be the name of the
501 function defined to do the insertion; DESCRIPTION will be inserted
502 into \"Inserts ... .\", and used as the descriptive string for the
503 generated function; STRING is the string which will actually be
504 inserted into the buffer when the keystroke is pressed."
506 (let* ((head (car table))
510 (string (nth 3 head)))
514 (concat "Inserts " desc ".")
516 (list 'insert string)))
517 (funcall 'local-set-key key func))
518 (setq table (cdr table))))
520 (defun ian-sgml-setup ()
523 '(("
\ 3\r" sgml-insert-new-para "new paragraph markup" "\n<p>\n")
524 ("
\ 3\14" sgml-insert-tt-emph "tt emph markup" "<tt/")
525 ("
\ 3\10" sgml-insert-prgn-emph "prgn emph markup" "<prgn/")
526 ("
\ 3\ 5" sgml-insert-em-emph "em emfh markup" "<em/")
527 ("
\ 3\16" sgml-insert-var-empfh "var emph markup" "<var/"))))
528 (setq sgml-local-catalogs '("/jura:/usr/lib/debiandoc-sgml/sgml/catalog"))
530 (add-hook 'sgml-mode-hook 'ian-sgml-setup)
532 (defvar cite-string "> " "String to insert when citing")
534 (defun cite-region (start end)
535 "Quote each line in the region with an angle-bracket and space.
537 The citation string is taken from cite-string."
541 (narrow-to-region start end)
542 (goto-char (point-min))
547 (> (point-max) (point)))
548 (insert cite-string)))))
554 (global-magit-file-mode)
556 (magit-wip-after-save-mode)
557 (magit-wip-after-apply-mode)
558 (magit-wip-before-change-mode)
559 (setq magit-no-confirm
560 (append magit-no-confirm '(safe-with-wip)))
562 (setq vc-handled-backends (delq 'Git vc-handled-backends))
564 ;; (defun hack-dir-local-variables ()
565 ;; "Read per-directory local variables for the current buffer.
566 ;; Store the directory-local variables in `dir-local-variables-alist'
567 ;; and `file-local-variables-alist', without applying them."
568 ;; (when (and enable-local-variables
569 ;; (buffer-file-name))
570 ;; ;; Find the variables file.
571 ;; (let ((variables-file (dir-locals-find-file (buffer-file-name)))
575 ;; ((stringp variables-file)
576 ;; (setq dir-name (file-name-directory (buffer-file-name)))
577 ;; (setq class (dir-locals-read-from-file variables-file)))
578 ;; ((consp variables-file)
579 ;; (setq dir-name (nth 0 variables-file))
580 ;; (setq class (nth 1 variables-file))))
583 ;; (dir-locals-collect-variables
584 ;; (dir-locals-get-class-variables class) dir-name nil)))
586 ;; (dolist (elt variables)
587 ;; (unless (memq (car elt) '(eval mode))
588 ;; (setq dir-local-variables-alist
589 ;; (assq-delete-all (car elt) dir-local-variables-alist)))
590 ;; (push elt dir-local-variables-alist))
591 ;; (hack-local-variables-filter variables dir-name)))))))
593 (delete ".git/" completion-ignored-extensions)