;; .emacs

(setq load-path (append (list (expand-file-name "~/emacs")) load-path))    
(load "htmlize")

;;; uncomment this line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)

;; turn on font-lock mode
(global-font-lock-mode t)

;; enable visual feedback on selections
;(setq transient-mark-mode t)


;; Added by me
(global-set-key "\C-c\C-c" 'comment-region)
(global-set-key "\C-t" 'insert-dts)
(global-set-key [home] 'beginning-of-buffer)
(global-set-key [end] 'end-of-buffer)
(global-set-key [f6] 'goto-line)

; Some nice things
(setq transient-mark-mode t)
(show-paren-mode)
(tool-bar-mode -1)

(menu-bar-mode nil)
(scroll-bar-mode nil)

(mouse-wheel-mode t)
(auto-image-file-mode 1)
(setq make-backup-files t)
(column-number-mode t)
(line-number-mode t)

(global-font-lock-mode t)

(defvar tl_dts-format-string "%e %b %Y %H:%M:%S"
  "A string specifying the format of the date-time stamp.
Refer to the documentation for format-time-string for an explanation of the
meta characters available for use in this string.  Non-meta characters will
be inserted into the buffer without interpretation.")

;; Function: insert-dts
;;   Insert the date and time into the current buffer at the current location.
;;
;; Psuedo code:
;;  insert the date and time into the current buffer at the current location
;;
(defun insert-dts ()
  "Insert the date and time into the current buffer at the current location.
See the documentation for tl_dts-format-string to change the format of the
date-time stamp."
  (interactive)
  (insert (format-time-string tl_dts-format-string (current-time))))

;; String Swap
(defun string-swap (from-string to-string &optional start-at-point)
  "Swap FROM-STRING with TO-STRING until end of buffer. If optional
            argument START-AT-POINT (prefix argument if interactive) is non-nil
,             swap from point. Otherwise do the whole buffer."
  (interactive (query-replace-read-args "Swap string" nil))
  (save-excursion
    (unless start-at-point (goto-char (point-min)))
    (while (re-search-forward (concat from-string
                                      "\\|"
                                      to-string) nil t)
      (replace-match (if (string-equal (match-string 0) from-string)
                         to-string
                       from-string)))))

;; Swap colors
(defun swap-colors()
  (interactive)
  (set-foreground-color "black")
  (set-background-color "white")
)
(put 'downcase-region 'disabled nil)

;; Set colors
(set-foreground-color "white")
(set-background-color "black")


; toggle between .cpp and .h-file

(global-set-key [f8] '(lambda () (interactive)
                        (setq file-to-visit
                              (cond
                               ((string-match "\\(.cpp$\\)" buffer-file-name)
                                (replace-match ".h" t t buffer-file-name))
                               ((string-match "\\(.h$\\)" buffer-file-name)
                                (replace-match ".cpp" t t buffer-file-name))
                               (t (error "don't know which file to go get")
                                  nil)))
                        (if (file-exists-p file-to-visit)
                            (find-file file-to-visit)
                          (error "the alternate file doesn't exist"))))

; fast switching to cvs buffer

(defun abrakadabra () 
  (setq tmp (current-buffer))
  (setq b (get-buffer "*cvs*"))
  (if b
      (switch-to-buffer "*cvs*")
    (call-interactively 'cvs-examine))
  )

(global-set-key [f9] '(lambda () (interactive)
                        (if (buffer-file-name)
                            (abrakadabra)
                          (switch-to-buffer tmp)        
                          )))


; hide-show mode

(add-hook 'c++-mode-hook               ; other modes similarly
          '(lambda () (hs-minor-mode 1)))


(defvar my-hs-hide nil "Current state of hideshow for toggling all.")
(defun my-toggle-hideshow-all () "Toggle hideshow all."
  (interactive)
  (setq my-hs-hide (not my-hs-hide))
  (if my-hs-hide
      (hs-hide-all)
    (hs-show-all)))

(global-set-key [f7] 'my-toggle-hideshow-all)

;;;
;; 
; custom variables
;;
;;;
(custom-set-variables
  '(c++-font-lock-extra-types (quote ("Capo[^ :<]*" "Q[^ :<]*"))))