;; ***************************************************
;; *                 Info Manuals                    *
;; ***************************************************
;; Include misc info directories in the info path
;; :--> Cygnus win32 port of gnu utilities
;(setq Info-default-directory-list
;        '("e:/usr/local/cygnus/info/"))
;; :--> Emacs lisp info pages
;(setq Info-default-directory-list
;        (append Info-default-directory-list
;           '("e:/usr/local/emacs-19.34/lisp/info/")))
;; :--> Emacs info pages
;(setq Info-default-directory-list
;        (append Info-default-directory-list
;           '("e:/usr/local/emacs-19.34/info/")))
;(setq Info-directory-list
;        Info-default-directory-list)

;; ***************************************************
;; *              Set Default Edit Mode              *
;; ***************************************************
;; :--> Use text-mode
(setq default-major-mode 'text-mode)

;; ***************************************************
;; *               Emacs beep sound                  *
;; ***************************************************
;; 'asterisk, 'exclamation, 'hand, 'question, or 'ok
;; None of these seem to change the beep
(set-message-beep 'ok)

;; ***************************************************
;; *                Mode Line Format                 *
;; ***************************************************
;; :--> Adjust what appears in the mode line at bottom of screen
(setq column-number-mode t)    ; add column numbers
;; :--> Show current date and time
(setq display-time-day-and-date t)
;(display-time)
;; :--> Change modeline background color
(set-face-background 'modeline "turquoise")

;; ***************************************************
;; *              Automatic Line Wrap                *
;; ***************************************************
;; :--> Turn on auto-fill-mode
(add-hook 'text-mode-hook
          '(lambda () (auto-fill-mode 1)))
(setq fill-column '80)

;; ***************************************************
;; *            Highlight matching parens            *
;; ***************************************************
(load "paren")                    ; apply paren.elc
(setq show-paren-mode t)          ;   highlight matches
(setq show-paren-delay 0.25)      ;   set delay in secs
;; :--> move cursor to opening paren: seems to work only
;;      when paren.el is not loaded! (TRUE FOR REST'O'SXN)
(setq blink-matching-paren t)
(setq blink-matching-paren-delay 0.2)
;; :--> define an interactive cursor jump to opening paren
(defun interactive-blink-matching-open ()
         "Indicate momentarily the start of sexp before point."
         (interactive)
         (let ((blink-matching-paren-distance
                  (buffer-size))
                 (blink-matching-paren t))
                (blink-matching-open)))
;; :--> define a key mapping for
;;      interactive-blink-matching-open
(define-key global-map "\C-cm" 'interactive-blink-matching-open)

;; ***************************************************
;; *         Highlight between point & mark          *
;; ***************************************************
(transient-mark-mode t)

;; ***************************************************
;; *           Enable syntax highlighting            *
;; ***************************************************
;; :--> Turn on font-lock in all modes that support it
(if (fboundp 'global-font-lock-mode)
             (global-font-lock-mode t))

;; :--> Maximum colors
(setq font-lock-maximum-decoration t)

;; :--> Turn on highlighting for search string
(setq search-highlight t)

;; ***************************************************
;; *                Calendar Options                 *
;; ***************************************************
;; :--> Set calendar highlighting colors
;; NOTE: Please rebind the key below to a function that
;;       is defined to start calendar in its own frame
;;       with miscellaneous options (highlighted holidays,...)
(setq calendar-load-hook
        '(lambda ()
            (set-face-foreground 'diary-face      "skyblue")
            (set-face-background 'holiday-face    "slate blue")
            (set-face-foreground 'holiday-face    "red")))

(setq view-calendar-holidays-initially t)
(setq mark-holidays-in-calendar t)

;; :--> Define a calendar function sequence that starts
;;      calendar in its own frame, highlights holidays,
;;      prints out holiday list, and highlights paydays.
;;   :--> Define function to make frame named calendar
;;   NOTE: use let to prevent new frame sizes from being
;;         sized as below!
(defun make-calendar-frame ()
          "Makes a frame named calendar."
          (interactive)
          (make-frame '((name . "calendar")
                        (height . 30)
                        (width . 81)
                        (minibuffer . t)))
)
(defun highlighted-calendar ()
         "Start calendar in its own frame with holidays & paydays displayed."
         (interactive)
         (list (select-frame (make-calendar-frame))
               (calendar)))

;; ***************************************************
;; *             Defs for Key Bindings               *
;; ***************************************************

;(defun copy-rect ()
;         "copy-rectangle-to-register R."
;	 (interactive (list (point) (mark)))
;	 (apply 'copy-rectangle-to-register
; 	         (list "R" 'from 'to)))

;; ***************************************************
;; *                Set Key Bindings                 *
;; ***************************************************
;(global-set-key [f2]  'copy-rect)
(global-set-key [f3]  'kill-rectangle)
(global-set-key [f4]  'yank-rectangle)
(global-set-key [f5]  'recenter)
(global-set-key [f6]  'downcase-word)
(global-set-key [f7]  'upcase-word)
(global-set-key [f8]  'undo)
;(global-set-key [f9]  'insert-register)
;; :--> For the bindings below: check current bindings before activation
;(global-set-key [f9]  'copy-to-register)
;(global-set-key [f10] 'copy-to-buffer)
;(global-set-key [f11] 'copy-region-as-kill)

(global-set-key "\C-cc"    'highlighted-calendar)
(global-set-key "\C-cg"    'goto-line)
(global-set-key "\C-co"    'occur)
(global-set-key "\C-cw"    'compare-windows)
(global-set-key "\C-x?"    'what-line)

;; ***************************************************
;; *                  Setup Printing                 *
;; ***************************************************
;; :--> Use ps-print.el and define print (function and) variables
(require 'ps-print)
(setq ps-paper-type 'ps-letter)
(setq ps-lpr-command "lpr")                      ; NT version of lpr
(setq col-lpr-switches '("-S softstone -P tek")) ; COLOR Printer
(setq col-ps-lpr-switches (append col-lpr-switches '(" -o l")))
(setq lpr-switches '("-S softstone -P hp5"))     ; B&W Printer
(setq ps-lpr-switches (append lpr-switches '(" -o l")))
(setq ps-lpr-buffer "c:\\tmp\\psspool.ps")       ; a tmp spool file

;; :--> Define color buffer printing variable
(defun nt-ps-print-buffer-with-faces ()
  (interactive)
  (ps-print-buffer-with-faces ps-lpr-buffer)
  (shell-command
   (apply 'concat (append (list ps-lpr-command " ")
                          col-ps-lpr-switches
                          (list " " ps-lpr-buffer))))
)
;; :--> Define color region printing variable
(defun nt-ps-print-region-with-faces (from to)
  (interactive (list (point) (mark)))
  (ps-print-region-with-faces from to ps-lpr-buffer)
  (shell-command
   (apply 'concat (append (list ps-lpr-command " ")
                          col-ps-lpr-switches
                          (list " " ps-lpr-buffer))))
)
;; :--> Define b&w buffer printing variable
(defun nt-ps-print-buffer ()
  (interactive)
  (ps-print-buffer ps-lpr-buffer)
  (shell-command
   (apply 'concat (append (list ps-lpr-command " ")
                          ps-lpr-switches
                          (list " " ps-lpr-buffer))))
)
;; :--> Define b&w region printing variable
(defun nt-ps-print-region (from to)
  (interactive (list (point) (mark)))
  (ps-print-region from to ps-lpr-buffer)
  (shell-command
   (apply 'concat (append (list ps-lpr-command " ")
                          ps-lpr-switches
                          (list " " ps-lpr-buffer))))
)

;; :--> Define tools menu print options
;; :--> Define keybindings for print options
(define-key global-map "\C-cp" 'nt-ps-print-buffer-with-faces)
(global-set-key [menu-bar tools ps-print-buffer]
                '("Color PS Print Buffer" . nt-ps-print-buffer-with-faces))
(define-key global-map "\C-cr" 'nt-ps-print-region-with-faces)
(global-set-key [menu-bar tools ps-print-region]
                '("Color PS Print Region" . nt-ps-print-region-with-faces))

(define-key global-map "\C-cP" 'nt-ps-print-buffer)
(global-set-key [menu-bar tools print-buffer]
                '("PS Print Buffer" . nt-ps-print-buffer))
(define-key global-map "\C-cR" 'nt-ps-print-region)
(global-set-key [menu-bar tools print-region]
                '("PS Print Region" . nt-ps-print-region))

;; ***************************************************
;; *                    ispell                       *
;; ***************************************************
(autoload 'ispell-word
          "ispell4" 
          "Check spelling of word at or before point" t)
(autoload 'ispell-complete-word
          "ispell4" 
          "Complete word at or before point" t)
(autoload 'ispell-region
          "ispell4" 
          "Check spelling of every word in the region" t)
(autoload 'ispell-buffer
          "ispell4" 
          "Check spelling of every word in the buffer" t)
(setq ispell-command
             "c:/emacs-19.34/ispell/ispell.exe"
      ispell-look-dictionary
             "c:/emacs-19.34/ispell/ispell.words"
      ispell-look-command
             "c:/emacs-19.34/ispell/look.exe"
      ispell-command-options
             (list "-d" "c:/emacs-19.34/ispell/ispell.dict")
)

;; :--> Tex-Mode hooks
(add-hook 'text-mode-hook
      '(lambda ()
               (local-set-key "\M-\t" 'ispell-complete-word)))
(setq tex-mode-hook
      '(lambda ()
               (local-set-key "\M-\t" 'ispell-complete-word)))
(setq latex-mode-hook
      '(lambda ()
               (local-set-key "\M-\t" 'ispell-complete-word)))

;; :--> Enable-Tex mode parser
;; :---> NOTE: This will only work in tex-mode and related modes
(setq ispell-enable-tex-parser t)

;; ***************************************************
;; *               Visual C++ style                  *
;; ***************************************************
;; Here's a sample .emacs file that might help you along the way.  Just
;; copy this region and paste it into your .emacs file.  You may want to
;; change some of the actual values.

(defconst my-c-style
  '((c-tab-always-indent           . t)
    (c-comment-only-line-offset    . 2)
    (c-hanging-braces-alist        . ((substatement-open after)
                                      (brace-list-open)))
    (c-hanging-colons-alist        . ((member-init-intro before)
                                      (inher-intro)
                                      (case-label after)
                                      (label after)
                                      (access-label after)))
    (c-cleanup-list                . (scope-operator
                                      empty-defun-braces
                                      defun-close-semi))
    (c-offsets-alist               . ((arglist-close     . c-lineup-arglist)
                                      (substatement-open . 0)
                                      (case-label        . 2)
                                      (block-open        . 0)
                                      (knr-argdecl-intro . -)))
    (c-echo-syntactic-information-p . t)
    )
  "My C Programming Style")

;; Customizations for all of c-mode, c++-mode, and objc-mode
(defun my-c-mode-common-hook ()
  ;; add my personal style and set it for the current buffer
  (c-add-style "PERSONAL" my-c-style t)
  ;; offset customizations not in my-c-style
  (c-set-offset 'member-init-intro '++)
  ;; other customizations
  (setq tab-width 4
        ;; this will make sure tabs are used instead of spaces 
        indent-tabs-mode t)
  ;; we like auto-newline and hungry-delete
  (c-toggle-auto-hungry-state 1)
  ;; keybindings for C, C++, and Objective-C.  We can put these in
  ;; c-mode-map because c++-mode-map and objc-mode-map inherit it
  (define-key c-mode-map "\C-m" 'newline-and-indent)
  )

;; the following only works in Emacs 19
;; Emacs 18ers can use (setq c-mode-common-hook 'my-c-mode-common-hook)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
