;; -*- emacs-lisp -*-
;; This is Glyn's file for Emacs   resurrected for his 40th birthday in 1997.

;;;;;;;;;;;;;
;;PATHS ETC.
;; Setting  the load-path

(setq load-path (cons "~/elisp" load-path))
(add-to-list 'load-path "/home/glyn/elisp/roman-calendar")
(add-to-list 'load-path "~/elisp/bbdb-2.35/lisp")
(add-to-list 'load-path "~/elisp/bbdb-2.35/texinfo")
(setq load-path (cons "~/elisp/org/lisp" load-path))
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/muse")
(add-to-list 'load-path
              "~/.emacs.d/plugins/yasnippet")
 (require 'yasnippet)
 (yas/initialize)
     (yas/load-directory "~/.emacs.d/plugins//yasnippet/snippets")

;; Info-path stuff
(require 'info)
(add-to-list 'Info-default-directory-list "/usr/local/texlive/2009/texmf/doc/info")
(setq Info-directory-list (cons "~/info" Info-default-directory-list))

;; and for bitmaps
(setq x-bitmap-file-path "~/bitmaps")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ESSENTIAL PRELIMINARY STUFF - makng it usable.

(require 'cl)           ; common lisp support
(setq warning-suppress-types nil) ;; to enable byte-compilation of code
(setq line-move-visual nil)  ;; Corrects a blunder made in emacs 23
(windmove-default-keybindings) ;; window hopping with Shift arrow keys
(setq gnus-agent nil)
(setq inhibit-startup-message t) ; tidy up the screen
(if (fboundp 'tool-bar-mode) 
    (tool-bar-mode -1))
(scroll-bar-mode -1)
(display-time) ;tell me the time
(setq debug-on-error t) ;; useful when testing,
(put 'downcase-region 'disabled nil)
(setq minibuffer-max-depth nil)
(setq default-frame-plist '(width 104 height 46)) ;; make new frames nice and wide
(setq visible-bell t) ;; get rid of annoying bleeps
(require 'smooth-scrolling)
(require 'font-lock)

;;; Don't quit unless you mean it!
(defun maybe-save-buffers-kill-emacs (really) 
  "If REALLY is 'yes', call save-buffers-kill-emacs." 
  (interactive "sAre you sure about this? ")
  (if (equal really "yes") 
      (save-buffers-kill-emacs)))
(global-set-key [(control x)(control c)] 'maybe-save-buffers-kill-emacs)

;;; Place my domain name in the title bar!
(setq frame-title-format `("@" ,(system-name) ": " (buffer-file-name
                                                    "%f"
                                                    (dired-directory
                                                     dired-directory))))

;; Preserve the owner and group of the file you’re editing (this is
;; especially important if you edit files as root).

(setq backup-by-copying-when-mismatch t)

;; Get rid of that awful spraying of backup files!

(setq backup-by-copying t               ; don't clobber symlinks
      backup-directory-alist '(("." . "~/.saves")) ; don't litter my fs tree
      delete-old-versions t kept-new-versions 6 kept-old-versions 2
      version-control t)                ; use versioned backups

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Modeline stuff

(setq display-time-day-and-date t ; Display the day and date in the mode line
      display-time-form-list '(date time-text load)
      display-time-interval     30    ; Redisplay every thirty seconds
      display-time-24hr-format  t     ; Use 24hr format
      display-time-use-mail-icon t)   ; tell me if mail is waiting.
(when (fboundp size-indication-mode)
  (size-indication-mode t))
(line-number-mode t)                     ; show line numbers
(column-number-mode t) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set up my own menu!

(easy-menu-define gtb-menu global-map "GlynMenu"
  '("GlynMenu"
     ("Templates" ;; submenu
       ["Sermon"  (insert-file-contents "/home/glyn/templates/sermon.tex")]
       ["Org-article" (insert-file-contents "/home/glyn/templates/article.org")]
       ["Beamer Slide"    (insert-file-contents "/home/glyn/templates/slideshow.tex")]
       ["Org-slides" (insert-file-contents "/home/glyn/templates/beamer.org")]
       ["Glyn Letter" (insert-file-contents "/home/glyn/templates/glynletter.tex")]
       ["Church Letter" (insert-file-contents "/home/glyn/templates/churchletter.tex")]
       ["Ars-Classica" (insert-file-contents "/home/glyn/templates/arsclassica.tex")]
       ["Handout-Tufte" (insert-file-contents "/home/glyn/templates/tufte.tex")])
       ("Services" 
       ["Morning Worship" (insert-file-contents "/home/glyn/templates/morningworship.txt")]
       ["Evening Worship" (insert-file-contents "/home/glyn/templates/eveningworship.txt")]
       ["Morning Communion" (insert-file-contents "/home/glyn/templates/morningcommunion.txt")]
       ["Evening Communion" (insert-file-contents "/home/glyn/templates/eveningcommunion.txt")]
       ["Funeral" (insert-file-contents "/home/glyn/templates/funeral.tex")])))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; KEYS ETC 
;;  Glyn's Keybinding Table - for function keys.  NB the "C-function"
;;  keys are used by the window manager.

;;  One can use the left hand windows key like this - 
;;;;;   (global-set-key (kbd "s-a") 'org-agenda-list That opens up all
;;;;;   sortf of possibilities.

(global-set-key (kbd "TAB") 'smart-tab)

(global-set-key [f1] 'undo)
(global-set-key [f2] 'kill-region)

;; ;;; does commenting for various languages
(autoload 'comment-out-region "comment" nil t)
(global-set-key [f3] 'comment-dwim)

(global-set-key [f4] 'gnus)



(require 'boxquote)
(global-set-key (kbd "C-c b y")   'boxquote-yank)
(global-set-key (kbd "C-c b r")   'boxquote-region)
(global-set-key (kbd "C-c b u")   'boxquote-unbox-region)
(global-set-key (kbd "C-c b t")   'boxquote-title)
(global-set-key (kbd "C-c b i")   'boxquote-insert-file)
(global-set-key (kbd "C-c b k")   'boxquote-kill)
(global-set-key (kbd "C-c b s")   'boxquote-shell-command)

(global-set-key (kbd "C-c b b")   'boxquote-buffer)
(global-set-key (kbd "C-c b p")   'boxquote-paragraph)
(global-set-key (kbd "C-c b n")   'boxquote-narrow-to-boxquote)


;;NOTE THE FORMAT HERE!!
(require 'scissors)
;; just an example (global-set-key  [(control f11)] 'scissors)  ;for snipping!
(global-set-key [f8] 'scissors)
;; Fire up org's table mode
(global-set-key [f9] 'orgtbl-mode)

;;; Handy  macro keys
(global-set-key [f10] 'start-kbd-macro)
(global-set-key [f11] 'end-kbd-macro)
(global-set-key [f12] 'call-last-kbd-macro)

;; Fantastically useful function with an awful default binding
(global-set-key [(meta f2)] 'query-replace-regexp)

;; Useful - kill entire line wherever you are on it!
;; ;;; kill entire line.
(defun Init-kill-entire-line (&optional arg) 
  "Kill the entire line.
 With prefix argument, kill that many lines from point.  Negative
 arguments kill lines backward.
 When calling from a program, nil means \"no arg\",
 a number counts as a prefix arg." 
  (interactive "*P")
  (let ((kill-whole-line t)) 
    (beginning-of-line)
    (call-interactively 'kill-line)))

;; ;;:* bind key to Init-kill-
(global-set-key (quote [67108925]) 
                (quote Init-kill-entire-line))


;;; Why this doesn;'t work out of the box I don't know - but lets see
;;; if setting it here works any better
(global-set-key (kbd "C-p") 'previous-line)

;;;;;;;;;;;;
;;  Bookmarks 
;;
 
(setq 
  bookmark-default-file "~/.emacs.d/bookmarks" ;; keep my ~/ clean
  bookmark-save-flag 1)                        ;; autosave each change)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; stark-frame
;; http://www.emacswiki.org/cgi-bin/wiki/Rick_Bielawski
;; This toggles on/off the menu and tool bars for more editing space.

(defvar stark-frame ())
(defun stark-frame () 
  "Toggle toobar & menu bar on/off." 
  (interactive)
  (setq stark-frame (not stark-frame))
  (tool-bar-mode 
   (if stark-frame 
       0
     1))
  (menu-bar-mode 
   (if stark-frame 
       0
     1)) 
  (if stark-frame 
      (set-frame-size (selected-frame)
                      (frame-width)
                      (+ (frame-height) 1))
    (set-frame-size (selected-frame)
                    (frame-width)
                    (- (frame-height) 1))))
(global-set-key (kbd "<S-f10>") 'stark-frame)


;; List recent files edited.
;;recentf
 (require 'recentf)
 (recentf-mode 1)
(setq recentf-max-saved-items 30)
(setq recentf-max-menu-items 30)

;;; save place in files being edited.
(setq save-place-file "~/.emacs.d/saveplace") ;; keep my ~/ clean
(setq-default save-place t)                   ;; activate it for all buffers
(require 'saveplace)                          ;; get the package


;;; WINDOW SPLITTING
(global-set-key (kbd "M-2") 'split-window-horizontally)
(global-set-key (kbd "M-1") 'delete-other-windows)
(global-set-key (kbd "M-0") 'delete-window)
(global-set-key (kbd "M-o") 'other-window)

;; Dedicated windows in Emacs
(defun toggle-window-dedicated-p () 
  (interactive)
  (let ((s (selected-window))) 
    (set-window-dedicated-p s (not (window-dedicated-p s)))))
(global-set-key (kbd "C-c d") 'toggle-window-dedicated-p)


;; Swap windows - 

(defun swap-windows ()
  "If you have 2 windows, it swaps them."
  (interactive)
  (cond ((/= (count-windows) 2)
         (message "You need exactly 2 windows to do this."))
        (t
         (let* ((w1 (first (window-list)))
                (w2 (second (window-list)))
                (b1 (window-buffer w1))
                (b2 (window-buffer w2))
                (s1 (window-start w1))
                (s2 (window-start w2)))
           (set-window-buffer w1 b2)
           (set-window-buffer w2 b1)
           (set-window-start w1 s2)
           (set-window-start w2 s1))))
  (other-window 1))

(global-set-key (kbd "C-c s") 'swap-windows)


;; cua-mode
(setq cua-enable-cua-keys nil) ;; only for rectangles
(cua-mode t)


;; buffer management

(require 'ibuffer) 
(setq ibuffer-saved-filter-groups
  (quote (("default"      
            ("Org" ;; all org-related buffers
              (mode . org-mode))  
            ("Mail"
              (or  ;; mail-related buffers
               (mode . message-mode)
               (mode . mail-mode)
               ;; etc.; all your mail related modes
               ))
            ("LaTeX" 
             (or (mode . latex-mode)
                      (mode . LaTeX-mode)
                      (mode . bibtex-mode)
                      (mode . reftex-mode)))
            ;; ("MyProject1"
            ;;   (filename . "src/myproject1/"))
            ;; ("MyProject2"
            ;;   (filename . "src/myproject2/"))
            ("Programming" ;; prog stuff not already in MyProjectX
              (or
                (mode . c-mode)
                (mode . perl-mode)
                (mode . python-mode)
                (mode . emacs-lisp-mode)
                ;; etc
                ))))))

(add-hook 'ibuffer-mode-hook
  (lambda ()
    (ibuffer-switch-to-saved-filter-groups "default")))

(global-set-key (kbd "C-x C-b") 'ibuffer)


(when (fboundp 'show-paren-mode)
  (show-paren-mode t)
  (setq show-paren-style 'parenthesis))

;; (require 'uniquify)
;; (setq uniquify-buffer-name-style 'forward)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MESSAGING


;; Gnus 

(setq mail-user-agent 'gnus-user-agent)
(setq message-mail-user-agent t)

(autoload 'footnote-mode "footnote" nil t)
 ;; Example for Gnus.
 (add-hook 'message-mode-hook 'footnote-mode)



;; If you would like to attach all marked files from dired to a new
;; Gnus message then put the following in your .emacs:

(require 'gnus-dired)
(add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)

;; Then, from dired, you can mark files as normal and then hit C-c
;; C-m C-a to attach the files (as attachments, not inline) to a
;; message. If you would like to have an easier to get to binding I
;; would suggest the following:

(define-key dired-mode-map "a" 'gnus-dired-attach)

(put 'rmail 'disabled t) ; avoid mbox destruction - make certain rmail
;; doesn't start by mistake!

;; run Gnus in another frame

(defun gmgnus ()
"run Gnus in another frame without too much typing"
(interactive)
(gnus-other-frame))




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TEXT STUFF 

;;;this line sets word-wrap right
(add-hook 'text-mode-hook 
          (lambda 
            () 
            (setq fill-column 73)))
(add-hook 'latex-mode-hook 
          (lambda 
            () 
            (setq fill-column 73)))
(add-hook 'text-mode-hook  'turn-on-auto-fill)
(add-hook 'latex-mode-hook  'turn-on-auto-fill)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LOAD UP PACKAGES 
;; ; General Emacs UI improvements.
;; ;(require 'uniquify)
;; ;(require 'icomplete)
(require 'uptimes)
;; ;; (require 'links)

;; ;;; Funky citation package for Gnus
(autoload 'trivial-cite "tc" t t)


;;;;;;;;;;;;;;;;; Remote editing with tramp
;; C-x C-f /remotehost:filename  RET (or /method:user@remotehost:filename)
;;
;; Using su to edit stuff as root
;;
;; C-x C-f /su::/etc/hosts RET
(require 'tramp)
(setq tramp-default-method "ssh")


;;;;;;  Python-mode. This is a major mode for editing Python programs.

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

;;;;; Extra poke for dired with dired-ex
(setq dired-recursive-deletes 'top)
(add-hook 'dired-load-hook 
          (lambda 
            ()
            (load "dired-x")
            ;; Set dired-x global variables here.  For example:
            ;; (setq dired-guess-shell-gnutar "gtar")
            ;; (setq dired-x-hands-off-my-keys nil)
            )) 
(add-hook 'dired-mode-hook 
          (lambda 
            ()
            ;; Set dired-x buffer-local variables here.  For example:
            ;; (dired-omit-mode 1)
            ))

;;; Even more poke for dired with dired+.el

(require 'dired+)

;;; AUCTEX STUFF.
 ;; (require 'tex-site)

(load "auctex.el" nil t t)
     (load "preview-latex.el" nil t t)

 (setq TeX-auto-save t)
  (setq TeX-parse-self t)
  (setq-default TeX-master nil)
 (setq reftex-plug-into-AUCTeX t)

;; ;;; set up ASPELL
;; (setq ispell-process-directory (expand-file-name "~/"))
;; (setq-default ispell-program-name "/usr/local/bin/aspell")
;; (setq ispell-really-aspell t)

;;;;;;;;;;;   MUSE Mode - funky authoring

(require 'outline)
(require 'muse)
(require 'muse-mode)                  ; load authoring mode
(require 'muse-colors)                ; load coloring/font-lock module
(require 'muse-project)
(require 'muse-html)                    ; load publishing styles I use
(require 'muse-journal)
(require 'muse-latex)

;; ;; ;; My own styles for various publications.
(setq muse-html-style-sheet
      "<link rel=\"stylesheet\" type=\"text/css\"  media=\"all\" href=\"/home/glyn/templates/muse/mystyle.css\" />")
(setq muse-latex-header "/home/glyn/templates/muse/ltxheader.tex")
(setq muse-latex-footer "/home/glyn/templates/muse/ltxfooter.tex")
(setq muse-latex-slides-header "/home/glyn/templates/muse/ltxslideheader.tex")
(setq muse-latex-slides-footer "/home/glyn/templates/muse/ltxslidefooter.tex")


;;; How to set up different cascading style sheets for different
;;; projects - REALLY hard to track this down in the docs etc because
;;; it isn't there The technique is to derive a new style from "html"
;;; and use that instead, using muse-derive-style

(muse-derive-style "glynweb-html" "html" :style-sheet
                   "<link rel=\"stylesheet\" type=\"text/css\"  media=\"all\" href=\"../css/mystyle.css\" />")
(muse-derive-style "central-html" "html" :style-sheet
                   "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"../css/centralmain.css\" />")

;; note the use of base:    to set the per-project style-sheet  :-)

(setq muse-project-alist '(("glynweb" ("~/html/glynweb/glyn" :default
                                       "index" ) 
                            (:base "glynweb-html" :path
                                   "~/html/glynweb/glyn")) 
                           ("central" ("~/html/glynweb/central"
                                       :default "index") 
                            (:base "central-html" :path
                                   "~/html/glynweb/central"))))

;;; If these fail then Muse will use the default stylesheet

;; CSS-mode

(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode)) 
(autoload 'css-mode "css-mode" nil t)


;; ;;  FVWM mode
;; Mode for editing config files for the wonderful Fvwm window manager

(require 'fvwm-mode)
(setq auto-mode-alist (cons '("config" . fvwm-mode) 
                      (cons '("FvwmApplet-" . fvwm-mode) 
                      (cons '("FvwmScript-" . fvwm-mode)
                      auto-mode-alist))))
;; this one from  Dave Pearson
(require 'thinks)


;; ;;;;;;; liturgical calendar stuff
(require 'cal-catholic)

;; ;;;;;;;;;; Diary adjustments for liturgy
(add-hook 'diary-display-hook 'fancy-diary-display)


;; ;   ;;fire up bbdb put this last
(require 'bbdb)
(bbdb-initialize 'gnus 'message) 
(setq bbdb-sounds-directory nil)

;; ;;; next line vital to make bbdb work with aliases
(add-hook 'message-setup-hook 'bbdb-define-all-aliases)


;; ;;; ;;; filladapt
(require 'filladapt)
(setq-default filladapt-mode t)
(add-hook 'text-mode-hook 'turn-on-filladapt-mode)


;; ;;;;;; LILYPOND THE MUSIC TYPESETTER!!!! ;;;;;;
(autoload 'LilyPond-mode "lilypond-mode") 
(setq auto-mode-alist (cons '("\\.ly$" . LilyPond-mode)
                            auto-mode-alist))
(add-hook 'LilyPond-mode-hook 
          (lambda 
            ()
            (turn-on-font-lock)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Diary stuff

(setq diary-file "~/.emacs.d/diary")
(setq  cal-tex-diary t calendar-date-display-form '
       ((if 
            dayname
            (concat dayname ", ")) day " " monthname " " year)
       calendar-time-display-form '(24-hours ":" minutes 
     (if time-zone 
         " (")
     time-zone 
    (if time-zone 
                 ")")) calendar-week-start-day
     1 diary-mail-addr
      "glyn" diary-mail-days
      7
      european-calendar-style t ;; I live there!!
      mark-diary-entries-in-calendar  t
      number-of-diary-entries  7
      view-diary-entries-initially t)

;;; Shakespeare!!
(autoload 'shq-insert-quote "shakespeare-quote" "" t)
(autoload 'shakespeare-signature "shakespeare-quote" "" t)


;; all.el -!! Edit all lines matching a given regexp. Priceless!

(require 'all)

;;;  Htmlize - convert elisp buffers into html code.

(require 'htmlize)
(setq htmlize-output-type 'font)

;;;;;;;; Org Mode
(require 'org-install)

(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) 
(global-set-key "\C-cl" 'org-store-link) 
(global-set-key "\C-ca" 'org-agenda)
(add-hook 'org-mode-hook 'turn-on-font-lock)

;; helps with timings
(setq org-log-done t)


;; The agenda view is nifty!
;; (setq org-agenda-files (list "~/org/"))

(setq org-agenda-files (quote ("~/org/glyn.org"
                               "~/org/notes.org"
                               "~/org/tech.org"
                               "~/org/god.org"
                               "~/org/politics.org"
                               "~/org/journal.org" 
                               )))

;; lets include diary entries
(setq org-agenda-include-diary t)
(setq org-todo-keywords '("TODO" "NEXT" "STARTED" "WAITING" "DONE"))

; hopefully cures clash between org and yasnippet
(add-hook 'org-mode-hook
                    (lambda ()
                      (org-set-local 'yas/trigger-key [tab])
                      (define-key yas/keymap [tab] 'yas/next-field-group)))

;; useful function for rapid access to main org file M-x gorg brings
;; it up immediately

(defun gorg () 
  (interactive)
  (find-file "/home/glyn/org/glyn.org"))

;;; Org-capture and file - fantastic note-making kit!!
 (setq org-default-notes-file  "~/org/notes.org")
     (define-key global-map "\C-cc" 'org-capture)

 (setq org-capture-templates
      '(("t" "Todo" entry (file+headline "~/org/glyn.org" "Tasks")
             "* TODO %?\n  %i\n  %a")
        ("j" "Journal" entry (file+datetree "~/org/journal.org" "Journal")
             "* %?\nEntered on %U\n  %i\n  %a")
        ("n" "Notes" entry (file+headline "~/org/notes.org" "Notes")
              "* %?\n%^T\n%i\n  %a")
        ("c" "Technical" entry (file+headline "~/org/tech.org" "Technical")
              "* %?\n%^T\n%i\n  %a")))

; refile setup.

; Use IDO for target completion
(setq org-completion-use-ido t)

; Targets include this file and any file contributing to the agenda -
; up to 5 levels deep.
(setq org-refile-targets (quote 
     ((org-agenda-files :maxlevel . 5) 
     ("/home/glyn/org/god.org" :maxlevel . 5) 
     ("/home/glyn/org/tech.org" :maxlevel . 5) 
     ("/home/glyn/org/journal.org" :maxlevel . 5))))

; Targets start with the file name - allows creating level 1 tasks
(setq org-refile-use-outline-path (quote file))

; Targets complete in steps so we start with filename, TAB shows the next level of targets etc
(setq org-outline-path-complete-in-steps t)

; Allow refile to create parent tasks with confirmation
(setq org-refile-allow-creating-parent-nodes (quote confirm))

; Use IDO only for buffers
; set ido-mode to buffer and ido-everywhere to t via the customize interface
; '(ido-mode (quote both) nil (ido))
; '(ido-everywhere t)



;;;;;;;;;;;;; Flyspell mode

;; Flyspell enables on-the-fly spell checking in Emacs by the means
;; of a minor mode.

(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(autoload 'flyspell-delay-command "flyspell" "Delay on command." t)
(autoload 'tex-mode-flyspell-verify "flyspell" "" t)

                                        ; (setq ispell-parser 'tex)
                                        ; (add-hook 'LaTeX-mode-hook 'flyspell-mode)

;;;; LaTeX hooks
(add-hook 'LaTeX-mode-hook 
          (lambda 
            () 
            (require 'reftex)
            (turn-on-reftex) 
            (setq reftex-plug-into-AUCTeX t)
            (outline-minor-mode 1)
            (turn-on-auto-fill) 
            (setq ispell-parser 'tex)
            (flyspell-mode 1) 
            (setq TeX-auto-save t)
            (setq TeX-parse-self t)
            (setq-default TeX-master nil)))

;; Tags file creation
(defun create-tags (dir-name) 
  "Create tags file." 
  (interactive "DDirectory: ")
  (eshell-command (format "find %s -type f -name \"*el\" | etags -"
                          dir-name)))

;;;;;;;;;;;;;;  HTML-helper mode


;; (autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
;; (setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))


;; clean out buffers except scratch,and maybe  agenda and org
 (defun restart ()
 "This one kills of all buffers except scratch and the others named"
 (interactive)
 (let ((list (buffer-list)))
 (while list
 (let* ((buffer (car list))
 (name (buffer-name buffer)))
 (and (not (string-equal name "*scratch*"))
;; ;(not (string-equal name "*Org Agenda*"))
;; ;(not (string-equal name "greg.org"))
 (kill-buffer buffer)))
 (setq list (cdr list)))))

;;; anything.el
;; While normal Emacs way is specifying action then selecting
;; candidates, the anything way is narrowing and selecting candidates
;; then executing action for selected candidates. It is something like
;; “QuickSilver? for emacs”.

(require 'anything-config)
 (defun my-anything ()
   (interactive)
    (anything-other-buffer
      '(anything-c-source-buffers
        anything-c-source-buffer-not-found
        anything-c-source-file-name-history
        anything-c-source-files-in-current-dir
        anything-c-source-occur
        anything-c-source-bookmarks
        anything-c-source-info-pages
        anything-c-source-info-elisp
        anything-c-source-man-pages
        anything-c-source-locate
        anything-c-source-emacs-commands
        anything-c-source-emacs-functions
        anything-c-source-kill-ring)
        " *my-anything*"))

(global-set-key [f7] 'my-anything)

;; deeply nifty!!

(require 'winring)
(winring-initialize)


;; (add-to-list 'load-path "~/elisp/slime/")  
;;     (setq inferior-lisp-program "/usr/bin/clisp") ; your Lisp system
;;     (require 'slime)
;; ;    (slime-setup)
;; (slime-setup '(slime-repl))

;; Change cursor color according to mode; inspired by
;; http://www.emacswiki.org/emacs/ChangingCursorDynamically
(setq djcb-read-only-color       "pink")
;; valid values are t, nil, box, hollow, bar, (bar . WIDTH), hbar,
;; (hbar. HEIGHT); see the docs for set-cursor-type

(setq djcb-read-only-cursor-type 'box)
(setq djcb-overwrite-color       "yellow")
(setq djcb-overwrite-cursor-type 'box)
(setq djcb-normal-color          "red")
(setq djcb-normal-cursor-type    'bar)

(defun djcb-set-cursor-according-to-mode ()
  "change cursor color and type according to some minor modes."

  (cond
    (buffer-read-only
      (set-cursor-color djcb-read-only-color)
      (setq cursor-type djcb-read-only-cursor-type))
    (overwrite-mode
      (set-cursor-color djcb-overwrite-color)
      (setq cursor-type djcb-overwrite-cursor-type))
    (t 
      (set-cursor-color djcb-normal-color)
      (setq cursor-type djcb-normal-cursor-type))))

(add-hook 'post-command-hook 'djcb-set-cursor-according-to-mode)

;;;;;;;;;;  TRANSIT CAMP  try out new stuff 

;; This browse-kill-ring thing could be fantastically useful!!
(require 'browse-kill-ring)
(browse-kill-ring-default-keybindings)


;; transit camp ends here.

;; detach custom file
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)


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


;; The Big Emacs Welcome.
(let ((string
       "Welcome aboard - hang on to your hat.")) 
  (message  string)
  (sit-for 2))