;; Chris Millward's .emacs
;; last revised
;; 2005-03-05-10:40

; mouse scrolling (works on XEmacs as well)
(autoload 'mwheel-install "mwheel" "Enable wheely mouse")
(mwheel-install)


;; slime Lisp editing mode
(add-to-list 'load-path "~/lib/slime-1.0")
(require 'slime)
(slime-autodoc-mode)
(slime-setup)
(setq inferior-lisp-program "lisp")
 (add-hook 'lisp-mode-hook (lambda () (slime-mode t)
                            (local-set-key "\r" 'newline-and-indent)
                            (setq lisp-indent-function 'common-lisp-indent-function)
                            (setq indent-tabs-mode nil)))
(setq auto-mode-alist (cons '("\\.lp$" . lisp-mode)       
                            auto-mode-alist))

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

(setq load-path (cons "~/lib/emacs" load-path))

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

;; Color theme
;(require 'color-theme)
;(color-theme-gnome2)

;; For GNU Emacs

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

;; --- Begin Perl editing section:
(autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
;; End Perl editing section.

;; --- Begin HTML editing section: 
;; I require html helper mode because the hhm-config.el code seems to 
;; cause an error if I have both autoloaded.
(require 'html-helper-mode "html-helper-mode.el")
;;(autoload 'html-helper-mode "hhm-config.el")
(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode)       auto-mode-alist))
(setq auto-mode-alist (cons '("\\.asp$" . html-helper-mode)        auto-mode-alist))
(setq auto-mode-alist (cons '("\\.phtml$" . html-helper-mode)      auto-mode-alist))
;; --- End HTML editing section.

;; using Tidy in Emacs
(global-set-key "\C-xt" 'tidy-region)
(setq shell-command-default-error-buffer "tidy-errors") ; define error buffer
(defun tidy-region ()
  "Run Tidy HTML parser on current region."
  (interactive)
  (let ((start (mark))
        (end (point))
        (command "/usr/local/bin/tidy -config /home/cmillward/lib/tidyconfig.txt -asxhtml"))
        (shell-command-on-region start end command t t
             shell-command-default-error-buffer)))

(global-set-key "\M-g" 'goto-line)
(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(load-home-init-file t t)
 '(tex-dvi-view-command "dvi"))


;; set time to show in corner
(setq display-time-day-and-date t)
(display-time)

;; =====================================================================
;; =====================================================================

;; When I yank a piece of code ( known as paste in Windows lingo )
;; into an existing function, I like to have it indent itself to the
;; proper level automatically. This simple macro runs yank ( C-y )
;; followed by an indent current function. ( C-c C-q )
(global-set-key "\C-cy" 'do-smart-yank)

(fset 'do-smart-yank
   "\C-y\C-c\C-q")

;; Put the following forms in your .emacs to enable autoloading of JavaScript
;; mode, and auto-recognition of ".js" files.

  (autoload 'javascript-mode "javascript-mode" "JavaScript mode" t)
  (setq auto-mode-alist (append '(("\\.js$" . javascript-mode))
                                   auto-mode-alist))

  (autoload 'python-mode "python-mode" "Python mode" t)
  (setq auto-mode-alist (append '(("\\.py$" . python-mode))
                                   auto-mode-alist))

;; Copy Line Command

(defun copy-line (n)
    "Copy N lines at point to the kill-ring."
    (interactive "p")
    (kill-ring-save (line-beginning-position) (line-beginning-position (1+ n))))

;; (global-set-key "\C-ck" 'copy-line)


;; Copies line and appends buffer name to the front of it
;; used in checking the Charniak/Gomez parsers

(defun copy-line-with-filename (n)
    "Copy N lines at point to the kill-ring."
    (interactive "p")
    (kill-ring-save (line-beginning-position) (line-beginning-position (1+ n)))
    (kill-append (concat (buffer-name) ": ") '1)
)

(defun cmillward-add-perl-string (n)
  "Put stuff around string"
  (interactive "p")
  (concat "my $input<<END;\n" (car kill-ring))
  (kill-append "\nEND" '1)
)

 (global-set-key "\C-cc" 'cmillward-add-perl-string)

 (global-set-key "\C-ck" 'copy-line-with-filename)

(require 'line-num "line-num.el")

;; from Ftrain http://www.ftrain.com/util_emacs_hints.html
(defun insert-time ()
  (interactive)
  (insert (format-time-string "%Y-%m-%d-%R")))

;; enable yank to work between programs in linux
(defun cmillward-paste-toggle-x ()
  (interactive)
  (setq x-select-enable-clipboard t)
  (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
)

;; session management code
;; http://www.emacswiki.org/cgi-bin/wiki/DeskTop
;; Emacs desktop
(require 'desktop)
(desktop-load-default)
(setq desktop-globals-to-save (append '(minibuffer-history command-history file-name-history extended-command-history)
                                            desktop-globals-to-save))
(setq history-length 250)
(desktop-read)
(setq desktop-enable t)

;; planner.el setup
;; opg1.ucsd.edu/~jklymak/PlannerMode.html

(add-to-list 'load-path "/home/cmillward/lib/emacs/emacs-wiki")
(add-to-list 'load-path "/home/cmillward/lib/emacs/planner")
(add-to-list 'load-path "/home/cmillward/lib/emacs/remember")
(require 'planner)

(setq planner-carry-tasks-forward t)

(require 'planner-id)
(define-key global-map [?\C-x ?\C-t] 'planner-create-task-from-buffer)
(define-key global-map [?\C-x ?\C-n] 'remember)

(require 'remember);
;; remember-planner - a must have...
(require 'remember-planner)
(setq remember-handler-functions '(remember-planner-append))
(setq remember-annotation-functions planner-annotation-functions)

;(require 'planner-gnus)
;(planner-gnus-insinuate)
;(require 'planner-bbdb);

;;setting up diary mode with planner
  (defun planner-diary-add-entry (date time text)
    "Prompt for a diary entry to add to `diary-file'.  Will run
    planner-annotations to make hyper links"
    (interactive (list (planner-read-date)
                            (read-string "Time: ")
                     (read-string "Diary entry: ")))
    (save-excursion
      (save-window-excursion
        (make-diary-entry
         (concat
          (let ((cal-date (planner-filename-to-calendar-date date)))
            (if european-calendar-style
                (format "%d/%d/%d"
                        (elt cal-date 1)
                        (elt cal-date 0)
                        (elt cal-date 2))
              (format "%d/%d/%d"
                      (elt cal-date 0)
                      (elt cal-date 1)
                      (elt cal-date 2))))
          " " time " " text " "
          (run-hook-with-args-until-success
           'planner-annotation-functions))))))

   (define-key global-map [?\C-x ?\C-d] 'planner-diary-add-entry)

(require 'planner-diary)
(setq planner-diary-use-diary t)
(planner-insinuate-diary)
(planner-insinuate-calendar)
(setq planner-diary-number-of-days 7)
(setq planner-diary-number-of-diary-entries 7)
(setq planner-diary-file diary-file)

(add-to-list 'load-path "/home/cmillward/lib/emacs/flymake")
(require 'flymake)


(require 'perldoc)
(require 'htmlize)