;;; disabling commands and key bindings

; The following disable key sequences that can cause big or unnoticed mistakes
(put 'zap-to-char 'disabled t)             ; M-z
; other general emacs confusions
(put 'upcase-region 'disabled t)    ; C-x C-u is confused with C-x u for undo
(global-unset-key "\C-x\C-l")       ; downcase of region can be disaster
;(global-unset-key "\C-z")           ; can still suspend with C-x C-z
(global-unset-key "\C-xf")          ; can use set-fill-column explicitly

; I don't use emacs to change directories, just to get to files
(setq find-file-run-dired nil)      ; never run dired


;;; preserve links of files when editing
(setq backup-by-copying-when-linked 't)

;;; customization of mode-line
(display-time)


;;; key bindings for ISN which eats all the C-s and C-q chars
(global-set-key "\M-s" 'isearch-forward-regexp)
(global-set-key "\C-\\" 'quoted-insert)
(setq search-repeat-char ?\C-a)
(setq search-quote-char ?\C-\\)


;;; sun emacs function key customization, etc.
(setq sun-esc-bracket 't)

(setq sun-raw-map-hook
     '(lambda ()
	 (define-key sun-raw-map "225z" 'goto-line)  ; F1
	 (define-key sun-raw-map "226z" 'shell)	     ; F2
	 (define-key sun-raw-map "227z" 'begin)	     ; F3
	 ))

(if (equal (getenv "TERM") "sun")
    (load "term/sun"))


;;; customization of mail mode
(setq mail-mode-hook
      '(lambda ()
	 (fset 'mail-start
	       "\C-n\C-n\C-n,\C-m\C-iGary\C-p\C-p\C-p\C-p")
	 (fset 'ssg-ok
   "r\C-rcc:\C-[\C-k\C-k,C-sreply-to: \C-[\C-@\M-f\M-w\M->\C-y,\C-m\C-iThanks!\\C-m\C-iGary\C-p\C-p\C-e")
	 (auto-fill-mode 1)
	 (setq fill-column 79)))

;;; public directory name macro
(fset 'pub "/usr/unsup/larch/")

;;; customization of TeX modes

(setq LaTeX-mode-hook
      '(lambda ()
	 ; type "M-x begin" after typing in the name of an environment
	 ; (C-c C-f in LaTeX mode is similar,
	 ; but is used after typing \begin{env})
	 (fset 'begin
	       "\C-u-1\M-@\C-u\C-xxb\\begin{\C-u\C-xgb}\C-m\\end{\C-u\C-xgb}\C-a\C-o")
	 (fset 'itemize
	       "itemize\M-xbegin\C-m\\item\C-m")
	 (fset 'enumerate
	       "enumerate\M-xbegin\C-m\\item\C-m")
	 (fset 'note
	       "note\M-xbegin\C-m")
	 (fset 'slide
	       "slide\M-xbegin\C-mcenter\M-xbegin\C-m\\Large\C-p\C-p\C-e{}\C-u2\C-n\C-m")
	 ))

(setq TeX-mode-hook
      '(lambda ()
	 (fset 'bf
	       "{\\bf }\C-b")
	 (fset 'em
	       "{\\em \\/}\C-u3\C-b")
	 (fset 'it
	       "{\\it \\/}\C-u3\C-b")
	 (fset 'rm
	       "{\\rm }\C-b")
	 (fset 'tt
	       "{\\tt }\C-b")
	 (fset 'proof
	       "\\PROOF\C-m\\QED\C-a\C-o")
	 (fset 'math
	       "$$\C-b")
	 (local-set-key "\M-$" 'math)
	 ; all my TeX files are actually LaTeX
	 (if (not (string-equal mode-name "LaTeX"))
	     (run-hooks 'LaTeX-mode-hook))
	 ))


;;; mode for BibTeX bibliography database files
(setq auto-mode-alist
      (append '(("\\.bib$" . bibtex-mode))
	      auto-mode-alist))
(autoload 'bibtex-mode "bibtex"
	  "Major mode for editing BibTeX database files." t)
(setq bibtex-mode-hook
      '(lambda ()
	 (fset 'bibtex-authors
	       "\C-r{\C-f\C-w\C-y
\C-y\C-@\C-u2\C-b\C-w\C-sYear\C-[
\C-u2\C-p
\C-y\C-u2\C-b19\C-c\"\C-rKey\C-[
\C-p\C-@\C-s\"\C-b\C-w\C-y
\C-y\C-p\C-r\"\C-[\C-f")
	 (fset 'bibtex-no-opt-no-quotes
	       "\C-c\C-o\C-c\"")
	 (define-key bibtex-mode-map "\C-c\C-[a" 'bibtex-authors)
	 (define-key bibtex-mode-map "\C-co" 'bibtex-no-opt-no-quotes)
	 ))

;;; Files mentioned below are found in "~leavens/emacs"
;;; Best way to set this is by exporting the EMACSLOADPATH environment
;;; variable from the shell.  Alternatively use
;;; (setq load-path (cons "/home/.../emacs" load-path))


;;; a mode for CLU programs
(defvar clu-home (getenv "/usr/unsup/clu"))

(setq auto-mode-alist
      (append '(("\\.clu$" . clu-mode)
                ("\\.spc$" . clu-mode))
              auto-mode-alist))

(autoload 'clu-mode "clu" "CLU mode" t nil)

(setq clu-doc-file-name (concat clu-home "/emacs/CLU-DOC"))

;;; a mode for Smalltalk-80 programs with GNU smalltalk
(setq auto-mode-alist
      (append '(("\\.st$" . smalltalk-mode))
	      auto-mode-alist))
(autoload 'smalltalk-mode "st" nil t)



;;; a mode for Standard ML programs
;;; can use (load-library "sml-init") instead for debugging
(setq auto-mode-alist 
      (append '(("\\.sml$" . sml-mode))
	      auto-mode-alist)) 

(autoload 'sml-mode "sml-mode" "Major mode for editing SML." t)
(autoload 'sml-shell "sml-mode" "Inferior shell invoking SML." t)

(defun sml () (interactive)
  ; Like sml-shell, but we display the sml process window after invoking it;
  ; this will bring it up even if it has already been started.
  ; Also, "sml" is shorter to type than "sml-shell".
  (sml-shell)
  (pop-to-buffer (concat "*" sml-process-name "*")))

;;; mode for C++ programs
(setq auto-mode-alist
      (append '(("\\.cc$" . c++-mode)
		("\\.C$" . c++-mode))
	      auto-mode-alist))
(autoload 'c++-mode "c++" "Major mode for editing C++." t)

(defun delete-on-backspace ()
  "makes C-h do the job of delete (delete still works), puts help on C-x C-h."
  (interactive)
  (global-set-key "\C-h" 'backward-delete-char-untabify)
  ;;; The code below puts help on C-x C-h, which gets
  ;;; you to the help map.  To get the help menu after that type C-h or ?.
  ;;; You can also directly invoke help's menu by M-x help-for-help.
  (define-key ctl-x-map "\C-h" 'help-command)
)

(setq prolog-mode-hook
      '(lambda ()
	 (setq prolog-consult-string "consult(user).\n")
	 (setq prolog-eof-string nil)
	 ))

(autoload 'chez-xscheme "chez-xscheme"
	  "mode for chez scheme program interaction" t)
(autoload 'scheme-mode "chez-xscheme"
	  "mode for chez scheme programming and interaction" t)

(setq auto-mode-alist
      (append '(("\\.ss$" . scheme-mode))
	      auto-mode-alist))

(fset 'split-for-lcd-bottom
   "\C-x2\C-u2\C-x^\C-xo")

(defun split-for-lcd ()
  (interactive)
  (split-window-vertically)
  (enlarge-window 2)
  (other-window 1))

(defun meeting-scheme ()
  (interactive)
  (setq scheme-program-name "meeting-scheme")
  (do-whatever-meeting-scheme))

(defun meeting-scheme-practice ()
  (interactive)
  (setq scheme-program-name "meeting-scheme-practice")
  (do-whatever-meeting-scheme))

(defun do-whatever-meeting-scheme ()
  (interactive)
  (split-for-lcd)
  (load "chez-xscheme")
  (run-scheme nil)
  (pop-to-buffer "*scheme*"))
