;   .emacs file -- full of all kinds of fun .emacs hacks
; by G.L. Dryfoos, Project Athena

;(server-start)                 ; uncomment this so that mh "comp"  or "repl"
                                ; can just start new buffer in existing emacs
                                ; window in conjunction with emacsclient

;for convenience, start these up now
(load "scribe")                 ;enables scribe-mode
(load "tex-mode")

;various minor-mode toggles
(global-set-key "\C-x\C-j" 'overwrite-mode)
(global-set-key "\C-x\C-k" 'auto-fill-mode)
(global-set-key "\C-x\C-y" 'abbrev-mode)

;I find it too easy to hit C-x C-c (kill-emacs) accidently.  These two lines
; move "kill-emacs" to C-x 4 C-c and rebind C-x C-c to the harmless "set-mark"
;
(global-set-key "\C-x\C-c"  'set-mark-command)        ;to disable kill-emacs
(global-set-key "\C-x4\C-c" 'save-buffers-kill-emacs) ;here is kill-emacs

;This lets you cycle thru all current buffers with M-z, and disables the
; mostly-useles zap-to-char
;
(global-set-key "\M-z"      'bury-buffer)             ;to disable zap-to-char

;miscellaneous stuff
(global-set-key "\C-xc"     'kill-rectangle)
(global-set-key "\C-xy"     'yank-rectangle)
(global-set-key "\C-x,"     'kill-some-buffers)
(global-set-key "\C-x%"     'query-replace-regexp)    ;corresponds to M-%
(global-set-key "\M-\C-w"   'write-region)
(global-set-key "\C-x4\C-v" 'scroll-other-window)
(global-set-key "\C-xt"     'display-time)            ;toggle display-time
(global-set-key "\M-n"      'forward-list)            ;remapped from C-M-n
(global-set-key "\M-p"      'backward-list)           ;remapped from C-M-p
(global-set-key "\M-s"      'center-line)

;Useful with "name-last-kbd-macro"
; easily assign a keybinding to a keyboard macro
;
(global-set-key "\M-o"      'm1)                      ;used with kbd macros
(global-set-key "\M-+"      'm2)                      ;used with kbd macros

;set some variables
(setq scribe-electric-parenthesis t)
(setq scribe-electric-quote nil)
(setq display-time-day-and-date t)

; Protect yourself from the Trojan file-variables section.
(setq inhibit-local-variables t)

; *=* mh stuff *=*
;
(global-set-key "\C-cr"  'mh-rmail)
(global-set-key "\C-cu"  'buffer-enable-undo)
(setq mh-summary-height 6)
(setq mh-ins-buf-prefix "} ")
(setq mh-recenter-summary-p t)
(setq mh-clean-message-header t)

;c-mode variables
; everyone has their own preferences for these -- here they all
; in one place for easy modification
;
(set-variable (quote c-tab-always-indent) t)
(set-variable (quote c-auto-newline) t)
(set-variable (quote c-indent-level) 4)
(set-variable (quote c-continued-statement-offset) 4)
(set-variable (quote c-brace-offset) 0)
(set-variable (quote c-argdecl-indent) 4)
(set-variable (quote c-label-offset) -2)
(set-variable (quote c-continued-brace-offset) -4)
(set-variable (quote c-brace-imaginary-offset) 4)
(set-variable (quote comment-column) 32)

;fancy punctuation in Scribe: Postscript octals -- more in PostScript ref
;
;C-x " -- Insert nice double-quotes in Scribe mode files
(fset 'dbl-quote "252272")
(define-key scribe-mode-map "\C-x\042" 'dbl-quote)
;
;C-x ? -- Upside down question mark in Scribe mode files
(fset 'question-down "277")
(define-key scribe-mode-map "\C-x?" 'question-down)
;
;C-x ! -- Upside down exclamation point in Scribe mode files
(fset 'bang-down "241")
(define-key scribe-mode-map "\C-x!" 'bang-down)

;accumulated macros and some key-bindings for them
(fset 'quot
   "%

} !")

;M-C-x turns ON c-auto-newline
(fset 'cnew1
   "xset-var c-aut ne 1")
(define-key c-mode-map  "\M-\C-x" 'cnew1)

;M-C-z turns OFF c-auto-newline
(fset 'cnew0
   "xset-var c-aut ne nil")
(define-key c-mode-map  "\M-\C-z" 'cnew0)

;binds C-c C-x to scribe-mode compile command
(fset 'comp-scr
   "xcompile")
(define-key scribe-mode-map "\C-c\C-x" 'comp-scr)

;perform rot13 on region
(fset 'rot13
   "1nxshe -co    tr A-Za-z N-ZA-Mn-za-m>o<
