chiark / gitweb /
Merge old CVS `ian-dotfiles' repo, as a subtree where we can pick bits
[ian-dotfiles.git] / from-cvs / files / emacs_ian.el
diff --git a/from-cvs/files/emacs_ian.el b/from-cvs/files/emacs_ian.el
new file mode 100644 (file)
index 0000000..e11181c
--- /dev/null
@@ -0,0 +1,518 @@
+; This is my real emacs start-up file (for chiark).
+; 
+(make-variable-buffer-local 'indent-line-function)
+; Un-disable narrow and eval-expression
+(put 'narrow-to-region 'disabled nil)
+(put 'eval-expression 'disabled nil)
+(standard-display-european t)
+;
+; Make sure we don't disturb links or change ownership, use numbers
+(setq backup-by-copying-when-mismatch t)
+(setq backup-by-copying-when-linked t)
+;(setq version-control t
+;      kept-new-versions 4
+;      kept-old-versions 4
+;      trim-versions-without-asking t)
+;
+; Various one-liners
+(setq require-final-newline "ask")
+(if (string= window-system 'x) (load-library "ian-x"))
+(load-library "ian-aliases")
+; (load-library "auto-pgp")
+; (load-library "debian-changelog-mode")
+; (if (string= (getenv "TERM") "bbcb32") (setq term-file-prefix nil))
+; (setq explicit-shell-file-name "/usr/local/bin/tcsh")
+(setq inhibit-local-variables t)
+(setq enable-local-variables 'ask-me)
+(setq enable-recursive-minibuffers t)
+(setq compile-command "make")
+(setq diff-switches "-u")
+(display-time)
+;
+(set-variable 'search-repeat-char 28)
+(if (string-match "^19\." emacs-version)
+    (progn
+      (setq file-name-handler-alist     ; Disable nasty auto-loading of ange-ftp
+            (delq (rassq 'ange-ftp-completion-hook-function file-name-handler-alist)
+                  file-name-handler-alist))
+      (require 'find-alternate-18style)
+      (defun unset-down-mouse-23 ()
+        (local-set-key [mouse-2] 'mouse-yank-at-click)
+        (local-unset-key [down-mouse-2])
+        (local-unset-key [down-mouse-3])
+        (local-unset-key [C-down-mouse-3]))
+      (add-hook 'vm-mode-hook 'unset-down-mouse-23)
+      (add-hook 'vm-mail-mode-hook 'unset-down-mouse-23)
+      (add-hook 'text-mode-hook 'unset-down-mouse-23)
+      (add-hook 'Info-mode-hook
+                (function (lambda ()
+                            (local-set-key " " 'scroll-up)
+                            (local-set-key "\7f" 'scroll-down))))
+      (define-key isearch-mode-map "\1c" 'isearch-repeat-forward)
+      (define-key isearch-mode-map "\1d" 'isearch-quote-char)))
+;
+(menu-bar-mode -1)
+(defun terminal-keybindings ()
+  "This function should be called by the term-setup-hook mechanism"
+  (interactive)
+  ; Set my own keybindings
+  ;
+  ; Set keybindings generally (including I-search on C-\)
+;  (global-set-key "   " 'self-insert-command)
+  (global-set-key "\1c" 'isearch-forward)
+  (global-set-key "\r" 'newline-and-indent)
+  (global-set-key "\ f" 'set-mark-command)
+  (global-set-key "\1d" 'quoted-insert)
+  ;
+  ; Set keybindings on esc-map
+  (global-set-key "\e#" 'query-replace-regexp)
+  (global-set-key "\e+" 'toggle-truncate-lines)
+  (global-set-key "\eg" 'goto-line)
+  (global-set-key "\es" 'isearch-forward-regexp)
+  (global-set-key "\e\e" 'eval-expression)
+  ;
+  ; Set keybindings on ^X-map.
+  (global-set-key "\18m" 'vm-mail)
+  (global-set-key "\18\1c" 'save-buffer)
+  (global-set-key "\18\1d" 'toggle-read-only)
+  (global-set-key "\18#" 'recover-file)
+  (global-set-key "\18\12" 'bury-buffer)
+  (global-set-key "\18\v" 'quicker-compile)
+  (global-set-key "\18\18" 'exchange-point-and-mark)
+  (global-set-key "\18\1a" 'load-ange-ftp)
+  (global-set-key "\184\16" 'scroll-other-window)
+  (global-set-key "\184m" 'vm-mail-other-window)
+  (global-set-key "\189" 'vm-visit-folder)
+  (global-set-key "\188" 'rmail-input)
+  (global-set-key "\18p" 'cite-region)
+  (global-set-key "\18F" 'mail-formletter)
+  ;
+  ; Set keybindings for Sun numeric pad.
+  (setq esc-bracket-map (make-keymap))
+  (define-key esc-bracket-map "D" 'backward-char)
+  (define-key esc-bracket-map "C" 'forward-char)
+  (define-key esc-bracket-map "A" 'previous-line)
+  (define-key esc-bracket-map "B" 'next-line)
+  (define-key esc-map "[" esc-bracket-map)
+  (global-set-key "\e[214z" 'beginning-of-buffer)
+  (global-set-key "\e[220z" 'end-of-buffer)
+  (global-set-key "\e[216z" 'scroll-down)
+  (global-set-key "\e[222z" 'scroll-up)
+  (global-set-key "\e[192z" 'save-buffer)
+  (global-set-key "\e[194z" 'save-some-buffers)
+  (global-set-key "\e[195z" 'undo)
+  (global-set-key "\e[193z" 'call-last-kbd-macro)
+  (global-set-key "\e[196z" 'switch-to-buffer-other-window)
+  (global-set-key "\e[197z" 'copy-region-as-kill)
+  (global-set-key "\e[198z" 'find-file)
+  (global-set-key "\e[199z" 'yank)
+  (global-set-key "\e[198z" 'find-alternate-file)
+  (global-set-key "\e[200z" 'find-file)
+  (global-set-key "\e[201z" 'kill-region)
+  (global-set-key "\e[-1z" 'info)
+  ;
+  ; Set keybindings for Chiarks' x11emacs
+  (global-set-key "\e[5~" 'scroll-down)
+  (global-set-key "\e[6~" 'scroll-up)
+  ;
+  ; Set keybindings for knackered vt100-like terminal emulators.
+  (global-set-key "\eOt" 'scroll-down)
+  (global-set-key "\eOu" 'scroll-up)
+  (global-set-key "\eOD" 'backward-char)
+  (global-set-key "\eOC" 'forward-char)
+  (global-set-key "\eOA" 'previous-line)
+  (global-set-key "\eOB" 'next-line))
+(setq term-setup-hook 'terminal-keybindings)     ; remap keys in due course
+;
+; Autoload definitions
+(autoload 'tar-mode "tar-mode")
+(autoload 'uncompress-while-visiting "uncompress")
+; (autoload 'c++-mode "c++-mode" "Mode for editing C and C++ programs" t)
+(autoload 'hide-ifdef-mode "hideif" "For editing code with #ifdefs" t)
+;(setq-default indent-tabs-mode nil)
+(autoload 'dired-find-alternate-file "dired-alternate" "Find alternately" t)
+(autoload 'dired-run-file "dired-alternate" "Run this file" t)
+(autoload 'perl-mode "perl-mode" "Mode for Perl code" t)
+; (autoload 'rmail "rmail-fixed" "Patched mail reader" t)
+(autoload 'quicker-compile "quicker-compile" "Patched Compile mode" t)
+
+(autoload 'vm "vm" "Start VM on your primary inbox." t)
+(autoload 'vm-visit-folder "vm" "Start VM on an arbitrary folder." t)
+(autoload 'vm-visit-virtual-folder "vm" "Visit a VM virtual folder." t)
+(autoload 'vm-mode "vm" "Run VM major mode on a buffer" t)
+(autoload 'vm-mail "vm" "Send a mail message using VM." t)
+(autoload 'vm-submit-bug-report "vm" "Send a bug report about VM." t)
+;
+; (autoload 'info "info-fixed" "Patched info browser" t)
+(setq shell-mode-hook
+      '(lambda ()
+         (make-variable-buffer-local 'scroll-step)
+         (setq scroll-step 1)))
+; (setq inferior-lisp-program "kcl")
+(setq dired-mode-hook
+      '(lambda ()
+        (define-key dired-mode-map "F" 'dired-find-alternate-file)
+        (define-key dired-mode-map "X" 'dired-run-file)))
+;
+; Prevent loading of default init file and do some of the things it did
+; (setq inhibit-default-init t)
+;
+; Additional alist handling function
+;(defun alist-remove-elem (s s-list)
+;  "Delete the element of the alist S-LIST whose car is S"
+;  (if s-list (if (equal s (car (car s-list)))
+;               (cdr s-list)
+;             (cons (car s-list) (alist-remove-elem s (cdr s-list))))
+;    (nil)))
+;
+; Load C++ mode and edit Perl in perl mode
+(setq auto-mode-alist
+      (append '(("\\.[ch]$" . c-mode)
+                ("\\.[CH]$" . c++-mode)
+                ("\\.cc$" . c++-mode)
+                ("\\.hh$" . c++-mode)
+;                ("\\.tar$" . tar-mode)
+                ("\\.pl$" . perl-mode)
+                ("\\.ci$" . tex-mode)
+                ("\\.Z$" . uncompress-while-visiting))
+              auto-mode-alist))
+(setq interpreter-mode-alist
+      (append '(("sh" . fundamental-mode)
+                ("bash" . fundamental-mode))
+              interpreter-mode-alist))
+;
+; Use auto-fill when editing text
+(add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
+; (add-hook 'text-mode-hook '(lambda () (local-set-key "       " 'self-insert-command)))
+;
+; Set up newline to auto-indent & other stuff for perl, c++ and c modes.
+(setq perl-mode-hook '(lambda () 
+                        (local-set-key ";" 'self-insert-command)))
+(setq c++-mode-hook '(lambda ()
+                       (hide-ifdef-mode 1)
+                       (local-set-key ":" 'electric-c++-terminator)))
+; c++-electric-colon
+(setq c-mode-hook '(lambda ()
+                     (hide-ifdef-mode 1)
+                     (c-set-offset 'substatement-open 0 nil)
+                     (local-set-key "\r" 'newline-and-indent)))
+(setq c-hanging-comment-ender-p nil)
+;
+(defun vm-mail-other-window ()
+  "Like `vm-mail' command, but display buffer in another window."
+  (interactive)
+  (switch-to-buffer-other-window (current-buffer))
+  (vm-mail))
+;
+; mail precedences
+(setq mail-precedence-key-alist
+      '((?0  . "special-delivery")
+        (?1  . "air-mail")
+        (?2  . "first-class")
+        (?3  . "second-class")
+        (?5  . "third-class")
+        (?\  . nil)
+        (?6  . "bulk")
+        (?9  . "junk")))
+;
+(defun mail-precedence-as-key ()
+  "Set precedence by looking up last command char in mail-precedence-key-alist"
+  (interactive)
+  (message "%s" (concat "Precedence ["
+                        (mapconcat '(lambda (c) (char-to-string (car c)))
+                                   mail-precedence-key-alist "")
+                        "] ?"))
+  (let* ((key (read-char))
+         (prec (assoc key mail-precedence-key-alist)))
+    (if prec (mail-precedence (cdr prec))
+      (error "mail-precedence-as-key `%s' not found" key))))
+;
+(defun mail-precedence-as-key-send-and-exit (arg)
+  "Set precedence by looking up last command char in mail-precedence-key-alist,
+then call send-and-exit."
+  (interactive "P")
+  (mail-precedence-as-key)
+  (execute-kbd-macro "\ 3\ 3"))
+;
+(defun mail-precedence (prec)
+  (save-excursion
+    (mail-position-on-field "Precedence")
+    (let ((p (point)))
+      (beginning-of-line)
+      (delete-region (point) p)
+      (if prec
+          (insert "Precedence: " prec)
+        (delete-char 1)))))
+;
+(defun mail-mode-setup-keys ()
+  (local-set-key "\ 3\10" 'mail-precedence-as-key)
+  (local-set-key "\ 3p" 'mail-precedence-as-key-send-and-exit))
+(add-hook 'mail-mode-hook 'mail-mode-setup-keys)
+(add-hook 'vm-mail-mode-hook 'mail-mode-setup-keys)
+;
+(defun vm-mail-other-window ()
+  "Like `vm-mail' command, but display buffer in another window."
+  (interactive)
+  (switch-to-buffer-other-window (current-buffer))
+  (vm-mail))
+;
+(defun mail-formletter ()
+  "Run VM-mail with ,Formletter"
+  (interactive)
+  (vm-mail)
+  (rename-buffer (generate-new-buffer-name "form letter") t)
+  (delete-region (point-min) (point-max))
+  (insert-file (concat vm-folder-directory ",Formletter")))
+;
+; This function bound to C-x C-z
+(defun load-ange-ftp ()
+  "Load ange-ftp using require, if it isn't loaded already"
+  (interactive)
+  (message "Loading ange-ftp...")
+  (require 'ange-ftp) ; -extended
+  (message "Loading ange-ftp...done"))
+;
+; This function bound to M-+
+(defun toggle-truncate-lines ()
+  "Toggle truncation or folding of long lines"
+  (interactive)
+  (set-variable 'truncate-lines (not truncate-lines))
+  (redraw-display))
+;
+; RMAIL stuff
+;(setq rmail-file-name "~/mail/RMAIL"
+;      mail-archive-file-name "~/mail/Outbound"
+;      rmail-primary-inbox-list '("~/mbox" "~/mail/Outbound" "~/mail/Record"
+;                                 "~/mail/Import" "/var/spool/mail/ian")
+;      rmail-delete-after-output t
+;      rmail-last-rmail-file ""
+;      rmail-ignored-headers (concat
+;                             "^Content-Identifier:\\|^X400-[^O][A-Za-z-]+:\\|"
+;                             rmail-ignored-headers))
+;
+(defun make-regexps-ignore-non-address (list)
+  (apply 'append (mapcar
+                  '(lambda (item)
+                     (let ((item (mapconcat
+                                  '(lambda (ch)
+                                     (let ((s (char-to-string ch)))
+                                       (if (string-match "[][.*+?^$\\]" s)
+                                           (concat "\\" s)
+                                         s)))
+                                  item "")))
+                       (list
+                        (concat "<" item ">")
+                        (concat "^" item " *\\((.*)\\)?$"))))
+                  list)))
+;
+; BBDB
+(setq bbdb-north-american-phone-numbers-p nil
+      bbdb/mail-auto-create-p t
+      bbdb-auto-revert-p t
+      bbdb-notice-auto-save-file-p t
+      bbdb-message-caching-enabled t)      
+;
+; VM stuff
+(load-file "~/private/private.el")
+(if (file-exists-p "~/private/private2.el")
+  (load-file "~/private/private2.el"))
+(setq vm-included-text-attribution-format "%F writes (\"%s\"):\n"
+      vm-reply-subject-prefix "Re: "
+      vm-folder-directory "~/mail/"
+      vm-delete-after-saving t
+      vm-delete-empty-folders t
+      vm-mutable-windows t
+      vm-auto-get-new-mail nil
+      vm-auto-next-message nil
+      vm-jump-to-new-messages nil
+      vm-jump-to-unread-messages nil
+      vm-mime-digest-discard-header-regexp "only-drop-this-header"
+      vm-preview-lines nil
+      vm-included-text-prefix "> "
+      vm-confirm-quit 1
+      vm-auto-center-summary t
+      vm-confirm-new-folders t
+      vm-circular-folders nil
+      vm-visit-when-saving 0
+      vm-move-after-deleting t
+      vm-keep-sent-messages t
+      vm-follow-summary-cursor t
+      vm-frame-per-composition nil
+      vm-frame-per-edit nil
+      vm-frame-per-summary nil
+      vm-frame-per-folder nil
+      vm-tale-is-an-idiot t
+      vm-primary-inbox (concat vm-folder-directory "INBOX")
+      vm-sinbin-inbox (concat vm-folder-directory "SINBOX")
+      vm-uninteresting-senders "ian"
+      vm-reply-ignored-addresses
+      (make-regexps-ignore-non-address
+       '("ian@chiark.chu.cam.ac.uk" "ian" "iwj10@cus.cam.ac.uk"
+         "ian@chiark.greenend.org.uk"
+         "ijackson@nyx.cs.du.edu" "ijackson@gnu.ai.mit.edu"))
+      vm-primary-inbox (concat vm-folder-directory "INBOX")
+
+      vm-uninteresting-senders "ian"
+      vm-reply-ignored-addresses
+      (make-regexps-ignore-non-address
+       '("ijackson@chiark.chu.cam.ac.uk" "ijackson"
+         "iwj10@thor.cam.ac.uk" "iwj10@hermes.cam.ac.uk" "iwj10@cl.cam.ac.uk"
+         "iwj10@cam.ac.uk" "Ian.Jackson@cl.cam.ac.uk"))
+      mail-archive-file-name "~/mail/Outbound"
+
+@@?!$ncipher?@@
+      vm-spool-files
+      '((vm-primary-inbox "/var/spool/mail/@@$username@@"
+                         "~/mail/INBOX.CRASH")
+        (vm-primary-inbox "~/News/r" "~/mail/INBOX.CRASH")
+       (vm-primary-inbox "~/mbox" "~/mail/INBOX.CRASH")
+       (vm-primary-inbox "~/mail/Outbound" "~/mail/INBOX.CRASH")
+       (vm-primary-inbox "~/mail/Import" "~/mail/INBOX.CRASH")
+       (vm-primary-inbox "~/mail/Record" "~/mail/INBOX.CRASH")
+       (vm-sinbin-inbox "/var/spool/mail/ian" "~/mail/SINBOX.CRASH"))
+      vm-startup-with-summary t
+
+@@:
+      vm-spool-files (list
+                      "~/mbox"
+                      "~/mail/Outbound"
+                      "~/mail/Record"
+                      "~/mail/Import"
+                      "~/mail/inbox"
+;                       "/var/spool/mail/ijackson"
+                      (concat "mail:110:pass:iwj:" ijackson-pop-password)
+                      "/u/ijackson/mail/INBOX.CRASH"
+                      "~/News/r")
+      mail-host-address "ncipher.com"
+      user-mail-address "iwj@ncipher.com"
+@@;
+
+;      vm-spool-files
+;      (list
+;       (list vm-primary-inbox "~/mbox" "~/mail/INBOX.CRASH")
+;       (list vm-primary-inbox "~/mail/Outbound" "~/mail/INBOX.CRASH")
+;       (list vm-primary-inbox "~/mail/Record" "~/mail/INBOX.CRASH")
+;       (list vm-primary-inbox "~/mail/Import" "~/mail/INBOX.CRASH")
+;       (list vm-primary-inbox "/var/spool/mail/ian" "~/mail/INBOX.CRASH")
+;       (list vm-primary-inbox "~/News/r" "~/mail/INBOX.CRASH")
+;       (list vm-sysadmin-inbox "~/mbox" "~/mail/SINBOX.CRASH")
+;       (list vm-sysadmin-inbox "~/mail/SOutbound" "~/mail/SINBOX.CRASH")
+;       (list vm-sysadmin-inbox "~/mail/Import" "~/mail/SINBOX.CRASH")
+;       (list vm-sysadmin-inbox "/var/spool/mail/sysadmin" "~/mail/SINBOX.CRASH")
+; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mbox" "/u/ijackson/mail/INBOX.CRASH")
+; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mail/Outbound"
+;       "/u/ijackson/mail/INBOX.CRASH")
+; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mail/Record" "/u/ijackson/mail/INBOX.CRASH")
+; (list "/u/ijackson/mail/INBOX" "/u/ijackson/mail/Import" "/u/ijackson/mail/INBOX.CRASH")
+;        (list "/u/ijackson/mail/INBOX"
+;         (concat "localhost:110:pass:ijackson:" ijackson-pop-password)
+;         "/u/ijackson/mail/INBOX.CRASH"))
+      vm-startup-with-summary nil
+      vm-summary-format "%3n %a %2d %3m  %-19.19F  %s\n"
+      mail-archive-file-name "~/mail/Outbound"
+      vm-mime-8bit-text-transfer-encoding '8bit)
+;
+(add-hook 'vm-mode-hook
+          '(lambda ()
+             (local-set-key "Q" 'vm-quit)
+             (local-set-key "q" "###Q")))
+(add-hook 'mail-mode-hook
+          '(lambda ()
+             (if (and (boundp 'folder-buffer)
+                      folder-buffer
+                      (string= (buffer-file-name folder-buffer)
+                               (file-truename vm-sysadmin-inbox)))
+                 (progn
+                   (make-local-variable 'vm-mail-header-from)
+                   (setq vm-mail-header-from
+                         "sysadmin@chiark.greenend.org.uk (Ian Jackson)")
+                   (make-local-variable 'mail-archive-file-name)
+                   (setq mail-archive-file-name
+                         "~/mail/SOutbound")))))
+;
+;(defun vmi ()
+;  (interactive)
+;  (vm "/u/ijackson/mail/INBOX"))
+;;
+(defun vms ()
+  (interactive)
+  (vm vm-sinbin-inbox))
+;
+(defun make-session ()
+  "Makes this emacs hard to kill by requiring ^X^Cy to kill it
+instead of just ^X^C."
+  (interactive)
+  (global-unset-key "\18\ 3")
+  (global-set-key "\18\ 3y" 'save-buffers-kill-emacs))
+;
+; Fix problems with M-| setting window title of emacs' parent xterm
+(defun envdelete-term-termcap-windowid (list)
+  (let ((l list))
+    (mapcar '(lambda (x)
+               (if x (delq x l)))
+            (mapcar '(lambda (x)
+                       (if (or (string-match "^TERM=" x)
+                               (string-match "^TERMCAP=" x)
+                               (string-match "^WINDOWID=" x))
+                           x
+                         nil))
+                    l))
+    l))
+(setq process-environment
+      (envdelete-term-termcap-windowid process-environment))
+;
+(defun add-insertion-keys (table)
+  "Adds keybindings according to TABLE.  Each element of
+TABLE should be a four-element list.
+
+BINDING should be the key to bind; FUNCTION will be the name of the
+function defined to do the insertion; DESCRIPTION will be inserted
+into \"Inserts ... .\", and used as the descriptive string for the
+generated function; STRING is the string which will actually be
+inserted into the buffer when the keystroke is pressed."
+  (while table
+    (let* ((head (car table))
+           (key (car head))
+           (func (nth 1 head))
+           (desc (nth 2 head))
+           (string (nth 3 head)))
+      (defalias func
+        (list
+         'lambda () 
+         (concat "Inserts " desc ".")
+         '(interactive)
+         (list 'insert string)))
+      (funcall 'local-set-key key func))
+    (setq table (cdr table))))
+
+(defun ian-sgml-setup ()
+  (interactive)
+  (add-insertion-keys
+   '(("\ 3\r" sgml-insert-new-para "new paragraph markup" "\n<p>\n")
+     ("\ 3\14" sgml-insert-tt-emph "tt emph markup" "<tt/")
+     ("\ 3\10" sgml-insert-prgn-emph "prgn emph markup" "<prgn/")
+     ("\ 3\ 5" sgml-insert-em-emph "em emfh markup" "<em/")
+     ("\ 3\16" sgml-insert-var-empfh "var emph markup" "<var/"))))
+(setq sgml-local-catalogs '("/jura:/usr/lib/debiandoc-sgml/sgml/catalog"))
+  
+(add-hook 'sgml-mode-hook 'ian-sgml-setup)
+;
+(defvar cite-string "> " "String to insert when citing")
+;
+(defun cite-region (start end)
+  "Quote each line in the region with an angle-bracket and space.
+
+The citation string is taken from cite-string."
+  (interactive "r")
+  (save-excursion
+    (save-restriction
+      (narrow-to-region start end)
+      (goto-char (point-min))
+      (insert cite-string)
+      (while
+          (and
+           (= (forward-line) 0)
+           (> (point-max) (point)))
+        (insert cite-string)))))
+;
+; End of this file.