;; to display the date and time in the mode line:
;;
;;(setq display-time-day-and-date t)
;;(display-time)

;; how many lines to leave at top of screen when scrolling
;;
(setq next-screen-context-lines 1)

(setq cal-tex-diary t)
(setq cal-tex-holidays t)
(setq view-read-only t)

;; turn off the menu bar
(if (eq window-system 'x)
  (menu-bar-mode 1)
  (menu-bar-mode -1))

;;(if (eq window-system 'x)
;;  (enable-flow-control -1)
;;  (enable-flow-control 1))


(setq tex-dvi-view-command
   (if (eq window-system 'x) "xdvi" "dvi2tty * | cat -s"))


;; turn off line number mode
;; or not
;; (line-number-mode -1)

;;
;; if invoked with a command-line argument, then turn off flow
;; control 
;; or not
;;
;; (if (cdr command-line-args)
;;    (enable-flow-control 1)
;; )

(setq-default fill-column 70)
(setq default-major-mode 'text-mode)
(setq text-mode-hook 'turn-on-auto-fill)
(setq require-final-newline t)
(setq inhibit-startup-message t)
(setq auto-save-interval 100)
(setq search-slow-speed 2400)
(setq colon-double-space t)
(setq mail-yank-prefix "> ")
(setq mail-yank-ignored-headers ":")

;; expand mail aliases when typed
(add-hook 'mail-setup-hook 'mail-abbrevs-setup)

(setq window-min-height 2)

(global-set-key "\C-cg" 'goto-line)
(global-set-key "\C-cw" 'what-line)
(global-set-key "\C-cr" 'replace-regexp)

(global-set-key "\C-x\C-\M-k" 'kill-paragraph)

;;(global-set-key "\C-x\C-i" 'insert-buffer)
;; replaces indent-rigidly

(global-set-key "\C-x4s" 'ispell-buffer)
(global-set-key "\C-x\C-\M-v" 'view-buffer)


;; (global-set-key "\C-xf" 'find-file)
;; replaces 'set-fill-column, which is a stupid thing to bind

(global-set-key "\C-\\" 'isearch-forward)
(global-set-key "\C-x\C-\\" 'save-buffer)
(global-set-key "\C-^" 'quoted-insert)
(global-set-key "\C-x\C-^" 'toggle-read-only)

(defun my-read-sig () "Insert ~/.signature at end of file"
  (interactive "*")
  (save-excursion
    (goto-char (point-max))
    (skip-chars-backward " \t\n")
    (end-of-line)
    (delete-region (point) (point-max))
    (insert "\n\n--\n")
    (insert-file-contents "~/.signature")
    )
  )

(global-set-key "\C-xw" 'my-read-sig)

(defun my-left-shift () "Remove white space at start of line"
  (interactive "*")
  (save-excursion
;;  (goto-char (point-min))
    (replace-regexp "^ *" "")
    )
  )


(global-set-key "\C-x\M-<" 'my-left-shift)
(global-set-key "\C-x\M-," 'my-left-shift)

(defun my-untabify-buffer () "Remove tab stops from buffer"
  (interactive "*")
  (save-excursion
    (untabify (point-min) (point-max))
    )
  )

(global-set-key "\C-x\C-\M-h" 'my-untabify-buffer)

;; bind the arrow keys

(global-set-key "\M-[a" 'previous-line)
(global-set-key "\M-[b" 'next-line)
(global-set-key "\M-[c" 'forward-char)
(global-set-key "\M-[d" 'backward-char)

(defun myyow () "Insert a Zippy quotation" (interactive "*")
  (save-excursion
    (goto-char (point-max))
    (skip-chars-backward " \t\n")
    (end-of-line)
    (delete-region (point) (point-max))
    (insert "\n\n")
    (insert "Random quotation:\012")
    (yow 1)
    (insert "\n")))

(global-set-key "\M-\C-y" 'myyow)

(defun myquote ()
  "Insert \" > \" at the start of each new line"
  (interactive "*")
  (save-excursion
    (query-replace-regexp "^" "\\& > ")))

(global-set-key "\C-x\M->" 'myquote)
(global-set-key "\C-x\M-." 'myquote)

(defun my-returnreceipt ()
  "Insert a return-receipt-to in mail"
  (interactive "*")
  (save-excursion
  (goto-line 1)
  (search-forward "--text follows this line--")
  (beginning-of-line)
  (insert "Return-receipt-to: gross@bc.edu\n")))

(global-set-key "\C-c\C-r" 'my-returnreceipt)

(defun my-find-file-other-window-read-only ()
  "Find file read-only in other window"
  (interactive)
  (find-file-other-window (expand-file-name 
      (read-file-name "Find file read-only in other window: ")))
  (toggle-read-only)
)

;;(global-set-key "\C-x4r" 'my-find-file-other-window-read-only)

(defun my-count-lines-page-other-window ()
  "Count lines in other window"
  (interactive)
  (save-excursion
    (other-window 1)
    (count-lines-page)
    (other-window -1)
  )
)

(global-set-key "\C-x4l" 'my-count-lines-page-other-window)

(defun my-insert-date ()
  "Insert date string at point"
  (interactive)
  (insert-string (format-time-string "%Y-%m-%d %a %T %Z"))
;;  (insert-string (current-time-string))
)

(global-set-key "\M-&" 'my-insert-date)

(defun my-fill-buffer-to-end () "Fills buffer to end" (interactive "*")
  (save-excursion (fill-region (point) (point-max) nil nil nil)))

(global-set-key "\C-x\M-q" 'my-fill-buffer-to-end)

(defun my-expand-spaces () "Doubles all spaces" (interactive "*")
  (save-excursion (while (search-forward " " nil t)
		    (replace-match "  " nil t))))

(global-set-key "\C-x\M-\ " 'my-expand-spaces)

;; If autoloading then the lines:
   (autoload 'vm "vm" "Start VM on your primary inbox." t)
   (autoload 'vm-other-frame "vm" "Like `vm' but starts in another frame." 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)
   (setq vm-mail-window-percentage 60)
   (setq vm-confirm-new-folders t)
   (setq vm-included-text-attribution-format "%F,\n")
   (setq vm-preview-read-messages t)
   (setq vm-mutable-windows nil)
;; (set-variable 'vm-preview-lines 4)

;;
;; only start up vm if emacs is invoked with no command line args:
;; or not
;;
;;(if (not (cdr command-line-args))
;;    (setq term-setup-hook 'vm))

;;
;; make sure to load the right terminal package
;; and enable the arrows
;;
;;
;;(if (equal (getenv "TERM")  "vt100")
;;    (load "term/vt100" nil t))
;;(enable-arrow-keys)


   (setq mail-default-reply-to "Rob Gross <gross@bc.edu>")

;; (setq mail-archive-file-name "OUTBOX")

;; Stuff for calc: 


;;; Mode settings stored by Calc on Tue Oct  4 16:54:31 1994
(setq calc-prefer-frac t)
(setq calc-float-format '(fix 4))
(setq calc-angle-mode 'rad)
(setq calc-display-trail nil)
;;; End of mode settings

;;(setq search-repeat-char 13)

(put 'eval-expression 'disabled nil)

;;(setq search-exit-char 13)

;;; Commands added by calc-private-autoloads on Mon Dec  6 14:27:30 1999.
(autoload 'calc-dispatch	   "calc" "Calculator Options" t)
(autoload 'full-calc		   "calc" "Full-screen Calculator" t)
(autoload 'full-calc-keypad	   "calc" "Full-screen X Calculator" t)
(autoload 'calc-eval		   "calc" "Use Calculator from Lisp")
(autoload 'defmath		   "calc" nil t t)
(autoload 'calc			   "calc" "Calculator Mode" t)
(autoload 'quick-calc		   "calc" "Quick Calculator" t)
(autoload 'calc-keypad		   "calc" "X windows Calculator" t)
(autoload 'calc-embedded	   "calc" "Use Calc inside any buffer" t)
(autoload 'calc-embedded-activate  "calc" "Activate =>'s in buffer" t)
(autoload 'calc-grab-region	   "calc" "Grab region of Calc data" t)
(autoload 'calc-grab-rectangle	   "calc" "Grab rectangle of data" t)
(setq load-path (nconc load-path (list "~/emacslib/calc-2.02f")))
(global-set-key "\e#" 'calc-dispatch)
;;; End of Calc autoloads.

(put 'narrow-to-page 'disabled nil)

(setq gnus-show-all-headers nil)
(setq gnus-ignored-headers 
        "^Path:\\|^Posting-Version:\\|^Article-I.D.:\
\\|^Expires:\\|^Date-Received:\\|^References:\
\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Organization:\
\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Distribution:\
\\|^Nf-From:\\|^Approved:\\|^Sender:\\|^Newsgroups:\
\\|^.*-.*:\\|^.*-.*-.*:")

(setq gnus-auto-center-summary nil)
;;(setq gnus-subscribe-newsgroup-method 'gnus-subscribe-interactively)
(setq gnus-organization-file (expand-file-name "~/.tin/organization"))
(setq gnus-large-newsgroup 500)
(setq gnus-default-article-saver 'gnus-summary-save-in-mail)

(setq gnus-visible-headers "^From:\\|^Subject:\\|^Date:")
(setq gnus-inhibit-startup-message nil)

;;(add-hook 'nntp-server-opened-hook 'nntp-send-authinfo)

(setq gnus-select-method '(nntp "news.rcn.com"))
(setq gnus-read-active-file 'some)

;;(add-hook 'gnus-post-prepare-hook 'nntp-send-authinfo)

(defun my-nntp-auth-2-hook ()
  "Used for posting news"
  (interactive "*")
  (save-excursion
    (if (equal (message-news-p) nil)
	()
      (nntp-send-authinfo))))

(add-hook 'message-send-hook 'my-nntp-auth-2-hook)

;;(defun my-nntp-auth ()
;;  (nntp-send-command "^.*\r?\n" "AUTHINFO USER" "gross")
;;  (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" 
;;		     (read-string "NNTP password: ")))



(put 'narrow-to-region 'disabled nil)