RTFM
rtfm / Emacs / .emacs
.etla.org
;; this .emacs has been modified to work with emacs21 - it probably still
;; works with emacs20 : the only backwards combatability should be the
;; standard-display-european / set-language-environment stuff, and that's
;; been wrapped:

;;(message "checkpoint 00")

;; PATH
(setq load-path
      (append (list (expand-file-name "~vivek/lib/emacs")) load-path))

(require 'sgml-mode)
;; DEFADVICE

(defadvice execute-extended-command
  (after wtf (&optional command prefix-argument) activate)
  "This advice tells users when they invoke an extended command that has a
key binding in the current key map. (and tells them what it is, of course)\n"
  (if (and command (interactive-p) (sit-for 1)) (where-is command)) )

(defadvice next-line (after tail (arg) activate)
  "This advises a function to revert a read-only buffer if you are at the
end of the buffer after the function call."
  (if (and buffer-read-only (eobp) (not (string= ("Info-mode" major-mode))))
      (progn
	(revert-buffer 'IGNORE-BACKUP, 'NO-CONFIRM, 'PRESERVE-MODE)
	(forward-line)) ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Handle ^L and ^M sequences in make command output:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar dot-comfilt-0d 0)
(defadvice compilation-filter (around ctrl-h activate)
  "strip ^H characters from M-x compile output semi-intelligently"
  (let ((ch-proc (ad-get-arg 0))
	(ch-text (ad-get-arg 1))
	(ch-cbuf            nil)
	(ch-del              "")
	(ch-pos               0))
    (if (setq ch-cbuf (process-buffer ch-proc))
        (save-excursion
          (set-buffer ch-cbuf)
          ;; first character(s) ^H -> zap the preceding output character(s)
          ;; and echo them in the message area:
          (while (eq (elt ch-text 0) ?\b)
            (goto-char    (process-mark   proc))
            (setq ch-text (substring ch-text 1))
            (message "[%c]"       (char-before))
            (delete-backward-char             1))
          ;; render x^Hx^H sequences as spinners in the message area: this
          ;; is arguably too simplistic, but it gets things mostly right:
          (while (string-match "\\(.?\\)\b" ch-text ch-pos)
            (setq ch-del (match-string 1 ch-text))
            (if (< 0 (length ch-del))
                (message "[%s]" ch-del)
              (message "[%c]" (char-before)))
            (setq ch-text (replace-match "" t t ch-text 0)
                  ch-pos  (match-beginning              0)) )
	  ;; flag up any ^M chars.
          (if (string-match "\x0d" ch-text)
              (setq dot-comfilt-0d (+ dot-comfilt-0d 1)) )
	  ;; push the sanitised output back onto the arg list:
          (ad-set-arg 1 ch-text)) )
    
    ;; Are we nearly there yet? ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ad-do-it
    ;; No. Now shut up, you 'orrible kids. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;; if we've seen ^M chars, strip them:
    (if (and ch-cbuf (< 0 dot-comfilt-0d))
        (save-excursion
          (set-buffer ch-cbuf)
          (goto-char (point-min))
          (while (re-search-forward "^\\(.*\x0d\\)." nil t)
            (message "%s" (substring (match-string 1) 0 -1))
            (replace-match "" t t nil 1)
            (setq dot-comfilt-0d (- dot-comfilt-0d 1))) )) ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; continued statements
;;   staircase-effect
;;     indentation
(defun cascade-indent-fn (le)
  ;;(y-or-n-p (prin1-to-string (car le)))
  (save-excursion
    (forward-line -1)
    (let ((ple (c-guess-basic-syntax)))
      (if (string-equal (prin1-to-string (car ple)) "statement-cont")
	  (progn
	    ;;(message (concat "recursing " (prin1-to-string (car ple))))
	    (+ (cascade-indent-fn ple) 2))
	(car (list 2))
	)
      )
    )
  )

(setq c-basic-offset 4)

;; note that this is much more detailed than it needs to be,
;; but it is comprehensive, so it's easier to use as a reference:
(defvar viveks-c-style
  '("bsd"
    (c-comment-only-line-offset . 0)
    (c-basic-offset             . 4)
    (c-offsets-alist .
     ( (string                        . c-lineup-dont-change)
       (c                             . c-lineup-C-comments)
       (defun-open                    . 0)
       (defun-close                   . 0)
       (defun-block-intro             . +)
       (class-open                    . 0)
       (class-close                   . 0)
       (inline-open                   . +)
       (inline-close                  . 0)
       (func-decl-cont                . +)
       (knr-argdecl-intro             . +)
       (knr-argdecl                   . 0)
       (topmost-intro                 . 0)
       (topmost-intro-cont            . 0)
       (member-init-intro             . +)
       (member-init-cont              . 0)
       (inher-intro                   . +)
       (inher-cont                    . c-lineup-multi-inher)
       (block-open                    . 0)
       (block-close                   . 0)
       (brace-list-open               . 0)
       (brace-list-close              . 0)
       (brace-list-intro              . +)
       (brace-list-entry              . 0)
       (brace-entry-open              . 0)
       (statement                     . 0)
       (statement-cont                . cascade-indent-fn)
       (statement-block-intro         . +)
       (statement-case-intro          . *)
       (statement-case-open           . 0)
       (substatement                  . +)
       (substatement-open             . 0)
       (case-label                    . *)
       (access-label                  . -)
       (label                         . 0)
       (do-while-closure              . 0)
       (else-clause                   . 0)
       (catch-clause                  . 0)
       (comment-intro                 . c-lineup-comment)
       (arglist-intro                 . c-lineup-arglist-intro-after-paren)
       (arglist-cont                  . c-lineup-arglist-intro-after-paren)
       (arglist-cont-nonempty         . c-lineup-arglist)
       (arglist-close                 . c-lineup-arglist-close-under-paren)
       (stream-op                     . c-lineup-streamop)
       (inclass                       . +)
       (cpp-macro                     . -1000)
       (cpp-macro-cont                . c-lineup-dont-change)
       (friend                        . 0)
       (objc-method-intro             . -1000)
       (objc-method-args-cont         . c-lineup-ObjC-method-args)
       (objc-method-call-cont         . c-lineup-ObjC-method-call)
       (extern-lang-open              . 0)
       (extern-lang-close             . 0)
       (inextern-lang                 . +)
       (namespace-open                . 0)
       (namespace-close               . 0)
       (innamespace                   . +)
       (template-args-cont            . +)
       (inlambda                      . c-lineup-inexpr-block)
       (lambda-intro-cont             . +)
       (inexpr-statement              . 0)
       (inexpr-class                  . +) ))
    (c-echo-syntactic-information-p . t) ;; helpful when debugging indentation
     )
  "Vivek's C Style"
  )

;; work:
(defvar zeus-c-style
  '("user"
    (c-basic-offset             . 3)
    (c-comment-only-line-offset . 0)
    (c-offsets-alist . ( (statement-cont    . cascade-indent-fn)
			 (substatement-open . 0                ) ))
    (c-echo-syntactic-information-p . t) )
  "Zeus' C Style" )

(if (not (< 21 emacs-major-version))
    (defun hscroll-mode (&optional arg)
      "Toggle HScroll mode in the current buffer.
With ARG, turn HScroll mode on if ARG is positive, off otherwise.
In HScroll mode, truncated lines will automatically scroll left or
right when point gets near either edge of the window."
      (interactive "P")
      (let ((newmode (if (null arg)
			 (not truncate-lines)
		       (> (prefix-numeric-value arg) 0))))
	(setq truncate-lines (if newmode t nil))) ))

;;(defvar auto-indent t
;;  "If true the reindent-then-newline-and-indent when
;;the user presses return")

;;(defvar auto-highlight t
;;  "If true then rehighlight this line when the user presses return.")

;;(setenv "P4CONFIG" ".p4settings")
(setenv "P4PORT"   "2501")
(setenv "P4CLIENT" "nessus")

;;(message "checkpoint 01")

(setq scroll-step 1)

(setq frame-title-format "|emacs| %b")

(setq backup-by-copying-when-linked t)
(setq ispell-highlight-p          nil)

;; DEFUNs:

;; Ok, cperl-mode gets _really_ unhappy if perl mode gets loaded
;; after it, so make sure it doesn't happen...
(defalias 'perl-mode 'cperl-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NWFunctions (legacy functions and so on)
;; by 'Beeblebrox' at warwick uni, apparently. No licence.
(defun query-kill-emacs ()
  "Asks if you want to quit emacs before quiting."
  (interactive)
  (if (nth 1 (frame-list))
      (delete-frame)
    (if (y-or-n-p "Are you sure you want to quit? ")
	(save-buffers-kill-emacs)
      (message "Quit aborted."))))

;; (defun forced-indent-off ()
;;   "Switches off forced indentation upon a newline"
;;   (interactive)
;;   (setq auto-indent nil)
;;   (global-unset-key "\C-m")
;;   (global-set-key "\C-m" 'newline))

;; (defun forced-indent-on()
;;   "Switches on forced indentation upon a newline"
;;   (interactive)
;;   (setq auto-indent t)
;;   (global-unset-key "\C-m")
;;  (global-set-key "\C-m" 'reindent-then-newline-and-indent))

(defun paren-match ()
  "Jumps to the paren matching the one under point,
and does nothing if there isn't one."
  (interactive)
  (cond
   ((looking-at "[({[]") (forward-sexp 1) (backward-char))
   ((looking-at "[]})]") (forward-char) (backward-sexp 1))
   (t           (message "Could not find matching paren."))) )

;; pretty-print hashes:
(if (fboundp 'maphash)
    (defun pp-hash (H)
      (let (s)
	(maphash
	 (lambda (K V)
	   (setq s (concat s (format "%S => \n%s" K (pp V))))) H) s)))


;; End NWFunctions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Author:  	Malcolm Sparks
;;;		Computer Science Dept.
;;;          	University of Warwick.
;;; From: sparks@dcs.warwick.as.uk (Malcolm Sparks)
;;; Everyone is granted permission to copy, modify and redistribute
;;; this file, provided the people they give it to can.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun word-count-buffer ()
  "Count the words in a buffer.
Gives a quick word count for the buffer in the message line. 
This removes the need to use the shell command."
  (interactive)
  (word-count-region (point-min) (point-max) (buffer-name)))

(defun word-count-region (start end &optional description)
  "Count the words in a region.
This counts the number of words within a region including numbers, but
not punctuation. It has no special knowledge of TeX or LaTeX commands
so counts these as well. Uses forward-word as a guide to the next word."
  (interactive "r")             ; gets the region if not already given
  (let ((words 0))              ; local variable counts words-so-far
    (save-excursion             ; don't muck up the pointer and mark
      (goto-char start)         ; go to the beginning of the buffer/region
      (while (< (point) end) (setq words (1+ words)) (forward-word 1))
      (backward-word 1)         ; wally's fix for that one-word-out bug
      (if (> (point) end) (setq words (1- words))))
    (if (eq words 1)            ; let's try to be user-friendly
	(message "There is only 1 word in %s" (or description "the region"))
      (message "There are %d words in %s" words 
	       (or description "the region")))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; elisp helpers:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun elisp-dep-map ()
  (save-excursion
    (goto-char (point-min))
    (let (sym file sym-seen dentry deps)
      (while (search-forward-regexp "([^ ]+" nil t)
	(if (and (setq sym                   (symbol-at-point))
		 (functionp                                sym)
		 (setq file                  (symbol-file sym))
		 (not (member file '("files" "subr" "simple")))
		 (not (string=        (buffer-file-name) file))
		 (not                      (memq sym sym-seen)))
	    (progn
	      (setq sym-seen (cons sym sym-seen))
	      (if (setq dentry (assoc file deps))
		  (setcdr dentry (cons sym (cdr dentry)))
		(setq deps (cons (cons file (list sym)) deps))))))
      (if (interactive-p) (message "%S" deps) deps))) )

(defun elisp-insert-dep-block ()
  "Insert a block of (require \'sym) statements into an elisp file"
  (interactive)
  (let ((deps (elisp-dep-map)))
    (save-excursion
      (goto-char (point-min))
      (if (search-forward-regexp
	   ";; elisp-dep-block >>\n[\x00-\xff]*;; elisp-dep-block <<\n"
	   nil t)
	  (replace-match ""))
      (insert ";; elisp-dep-block >>\n")
      (mapcar
       (lambda (D)
	 (insert (format "(require '%s);%S\n" (car D) (cdr D)))) deps)
      (insert ";; elisp-dep-block <<\n"))) )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; this is for part of the build system for rtfm.etla.org: 
;; it's not really part of htmlfontify-buffer - but it's an example
;; of how to use it:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar rtfm-section nil)
(defvar rtfm-menuinc nil)

(defun rtfm-build-code-header (file style)
  (format "#define  TEMPLATE red+black.html
#define  DEBUG    1
#include <build/menu-dirlist|>\n
html-css-url := /css/red+black.css
title        := rtfm.etla.org ( %s / src/%s )
bodytag      := 
head         <=STYLESHEET;\n
%s
STYLESHEET
main-title   := rtfm / %s / src/%s\n
main-content <=MAIN_CONTENT;\n" rtfm-section file style rtfm-section file))

(defun rtfm-build-page-header (file style)
  (format "#define  TEMPLATE red+black.html
#define  DEBUG    1
#include <include/%s>\n
html-css-url := /css/red+black.css
title        := rtfm.etla.org ( %s )
bodytag      := 
head         <=STYLESHEET;\n
%s
STYLESHEET
main-title   := rtfm / %s\n
main-content <=MAIN_CONTENT;\n" rtfm-menuinc rtfm-section style file))

(defun rtfm-build-page-footer (file) "\nMAIN_CONTENT\n")

(defun rtfm-fontify-buffer (section menu)
  (interactive "s section[eg- emacs / p4-blame]:\ns menu-include-file: ");
  (require 'htmlfontify)
  (let ((hfy-page-header  'rtfm-build-page-header)
	(hfy-page-footer  'rtfm-build-page-footer)
	(rtfm-menuinc                        menu)
	(rtfm-section                     section))
    (htmlfontify-buffer)
    )
  )

(defun rtfm-fontify-file (from dest sect menu)
  (if (not (find-file from))
      nil ; noop
    (switch-to-buffer (rtfm-fontify-buffer sect menu))
    (write-file dest)
    (kill-buffer (current-buffer)) )
  )

(defun rtfm-build-source-docs (section srcdir destdir)
  (interactive
   "s section[eg- emacs / p4-blame]:\nD source-dir: \nD output-dir: ")
  (require 'htmlfontify)
  (hfy-load-tags-cache srcdir)
  (let ((hfy-page-header 'rtfm-build-code-header)
	(hfy-page-footer 'rtfm-build-page-footer)
	(rtfm-section                    section)
	(hfy-index-file                  "index")
	(hfy-instance-file            "instance")
	(auto-mode-alist
	 (append auto-mode-alist
		 '(("dbi\\(shell\\|gtk\\)$" . cperl-mode)
		   ("\\.xpm$"               . c-mode    )))) )
    (htmlfontify-run-etags srcdir)
    (htmlfontify-copy-and-link-dir srcdir destdir ".src" ".html")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun timestamp-string ()
  (interactive)
  (format-time-string "%a %Y-%m-%d %H:%M:%S %z" nil nil))

(defun interactive-set-auto-mode ()
  "wrapper to allow set-auto-mode to be bound to a key"
  (interactive)
  (set-auto-mode))

(defun insert-timestamp ()
  (interactive)
  "Vivek\'s timestamp insertion function"
  (insert "Last modified: " (timestamp-string) "\n"))


(defconst timestamp-regex
  (concat
   "\\(?:Fri\\|Mon\\|Sat\\|Sun\\|Thu\\|Tue\\|Wed\\)"                     " "
   "[12][0-9]\\{3\\}-\\(?:0[1-9]\\|1[012]\\)-\\(?:[012][0-9]\\|3[01]\\)" " "
   "\\(?:[01][0-9]\\|2[0-3]\\)\\(?::[0-5][0-9]\\)\\{2\\}"                " "
   "[-+]\\(?:[01][0-9]\\|2[0-3]\\)\\(?:[0-5][0-9]\\)"                    ) )

(defun replace-timestamp ()
  (interactive)
  "Zap and replace a timestamp string on this line."
  (save-excursion
    (let ((pos (point)) (eol nil) (cur nil) (done nil))
      (end-of-line)
      (setq eol (point))
      (beginning-of-line)
      (while (and (not done)
		  (setq cur (re-search-forward timestamp-regex eol t)))
	(if (<= cur pos) nil
	    (progn
	      (replace-match (timestamp-string) 'fixed-case 'literal nil 0)
	      (setq done t) )
	  )
	)
      )
    )
  )

(defun set-uniquify (ustyle)
  "set buffer uniquification style to STYLE [eg 'forward]
   a style of nil turns off uniquification.
   see also:
             `uniquify-buffer-name-style'
             `uniquify-rationalize-file-buffer-names'\n"
  (require 'uniquify)
  (let ((valid-values (list 'forward
			    'reverse
			    'post-forward'
			    'post-forward-angle-brackets
			    nil))
	(valid-style nil))
    (setq valid-style
	  (if (member ustyle valid-values) ustyle (car valid-values)))
    ;;(message-box "setting u-b-n-s to: %s" valid-style)
    (setq uniquify-buffer-name-style valid-style)) )

(defun query-quit (true)
  (interactive)
  (if true
      (if (< 21 emacs-major-version)
	  (global-set-key "\C-x\C-c"  'query-kill-emacs)
	(setq confirm-kill-emacs 'y-or-n-p))
    (global-set-key "\C-x\C-c" 'save-buffers-kill-emacs)
    (if (< 21 emacs-major-version)
	(setq confirm-kill-emacs nil))))

;	      (global-set-key "\C-x\C-c" 'save-buffers-kill-emacs))
  
(defun save-buffer-kill-buffer ()
  (interactive)
  (save-buffer)
  (kill-buffer nil))

(defun fix-left-margin ()
  "Fixes margin for indenting"
  (interactive)
  (setq left-margin (current-column)))

(defun sjh-mono-setup ()
  "SJH's mono-setup"
  (setq default-frame-alist
	'(
	  (background-color . "black")
	  (foreground-color . "white")
	  ;;(font             . "7x14")
	  (font . "-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1")
	  (mouse-color      . "white")
	  (cursor-color     . "white")
	  (cursor-type      . 'box)
	  (menu-bar-lines   . 1)
	  (tool-bar-lines   . 0))))

(defun sjh-colour-setup ()
  "SJH's orgasmic colour setup" ;; wtf was SJH anyway?
  ;;  Emacs Internal highlighting (not syntax colouring)
  (if t
      (progn
	(set-face-background 'highlight "grey25")
	(set-face-foreground 'highlight "green" )
 	(setq default-frame-alist
 	      '( (background-color . "black")
 		 (foreground-color . "white")
		 (font             . "7x14" )
		 (mouse-color      . "white")
		 (cursor-color     . "red"  )
		 (cursor-type      . 'box   )
		 (menu-bar-lines   . 1      )
		 (tool-bar-lines   . 0      ) ))
	(setq pop-up-frame-alist
 	      '( (background-color . "black")
 		 (foreground-color . "white") )))))

;;(message "checkpoint 03")

;; HOOKS:

;; last hook to run....
(add-hook 'term-setup-hook
	  (lambda () (message "Welcome to emacs, the thermonuclear editor")))

;(add-hook 'sgml-mode-hook (lambda () (setq sgml-indent-step 1)))

(add-hook 'p4-mode-hook
          '(lambda ()
             (custom-set-faces
              '(p4-diff-change-face    ((t (:foreground "palegreen"))) t)
              '(p4-diff-file-face      ((t (:background "gray30"   ))) t)
              '(p4-diff-head-face      ((t (:background "gray35"   ))) t)
              '(p4-diff-ins-face       ((t (:foreground "cyan"     ))) t)
              '(p4-depot-added-face    ((t (:foreground "steelblue"))) t)
              '(p4-depot-unmapped-face ((t (:foreground "grey55"   ))) t))) )

(setq sh-mode-hook
      (lambda ()
	(local-set-key [RET]  'sh-newline-and-indent)
	(local-set-key "\C-j" 'sh-newline-and-indent)
	(local-set-key "\C-m" 'sh-newline-and-indent)) )

;;(setq fundamental-mode-hook (lambda () (forced-indent-off)))
(setq nroff-mode-hook       (lambda () (auto-fill-mode  1)))

(add-hook 'bibtex-mode-hook
	  (lambda () 
	    (local-set-key "\"" 'self-insert-command)
	    (local-set-key "\t" 'self-insert-command)	     
	    ;;(forced-indent-off)
	    )
	  )

(setq makefile-mode-hook
      (lambda ()
	(setq indent-line-function 'tab-to-tab-stop)
	(local-set-key "\C-m" 'newline)) )

;; um. auto-fill bad for admining.
(setq text-mode-hook (lambda () (local-set-key "\C-m" 'newline)))

;;(setq dired-mode-hook
;;      (lambda ()
;;	(local-set-key "q"    'dired-quit)
;;	(local-set-key "\C-m" 'dired-find-file)) )

(setq Man-mode-hook (lambda () (local-set-key [f12] 'man-follow)))

(setq cperl-mode-hook
      (lambda ()
	(progn
	  (local-set-key [f12]   'cperl-perldoc-at-point) 
	  (local-set-key [print] 'cperl-mode))) )

;; BSD is the closest style to what I want...
(setq c-mode-common-hook
      '(lambda ()
	 (setq indent-tabs-mode            nil)
	 (c-add-style "zeus"  zeus-c-style   t)
	 (c-add-style "vivek" viveks-c-style t)))


;;; Perforce integration
(load-library "p4")
;;(setq p4-use-p4config-exclusively t)
;;(message "checkpoint 06")

;; AUTOLOAD
(autoload 'c++-mode  "cc-mode"  "C++ Editing Mode"         t)
(autoload 'c-mode    "cc-mode"  "C Editing Mode"           t)
(autoload 'objc-mode "cc-mode"  "Objective-C Editing Mode" t)
(autoload 'lpc-mode  "lpc-mode" "LPC Editing Mode"         t)

(autoload 'cvs-update       "pcl-cvs"    "CVS Support"                  t)
(autoload 'manual-entry     "man"        "New manual"                   t)
(autoload 'plsql-mode       "plsql"      "PL/SQL mode"                  t)
(autoload 'tar-mode         "tar-mode"   "Tar Mode"                     t)

;; XML/DTD stuff:
(autoload 'dtd-grep  "tdtd"   "grep for PATTERN in files matching FILESPEC." t)
(autoload 'xml-mode  "xml-mode" "XML mode"                                   t)
(autoload 'dtd-mode  "tdtd"     "Major mode for SGML and XML DTDs."          t)
(autoload 'dtd-etags "tdtd"
  "Execute etags on FILESPEC and match on DTD-specific regular expressions." t)

;; Turn on font lock when in DTD mode
;; (add-hook 'dtd-mode-hooks 'turn-on-font-lock) have global font locks

;;(message "checkpoint 07")

;; FILE TYPE/MODE BINDINGS:

;;(message "checkpoint 08")

(setq interpreter-mode-alist
      (append '(("perl"  . cperl-mode)
		("perl5" . cperl-mode)) interpreter-mode-alist))

;; extend/override a few of the default ext/mode mappings
(setq auto-mode-alist
      (append
       '( ("CHANGES"                  . change-log-mode); personal quirk
	  ("\\.1$"                    . nroff-mode)     ; man pages
	  ("\\.2$"                    . nroff-mode)
	  ("\\.3$"                    . nroff-mode)
	  ("\\.4$"                    . nroff-mode)
	  ("\\.5$"                    . nroff-mode)
	  ("\\.6$"                    . nroff-mode)
	  ("\\.7$"                    . nroff-mode)
	  ("\\.8$"                    . nroff-mode)
	  ("\\.man$"                  . nroff-mode)
	  ("\\.me$"                   . nroff-mode)
	  ("\\.mm$"                   . nroff-mode)
	  ("\\.mr$"                   . nroff-mode)
	  ("\\.ms$"                   . nroff-mode)
	  ("\\.[Ss][qQ][lL]$"         . plsql-mode)
	  ("\\.\\([pP][Llm]\\|al\\)$" . cperl-mode)    ; must trigger before
	  ("/?[Mm]akefile"            . makefile-mode) ; makefile-mode
	  ("\\.lpc$"                  . lpc-mode)
	  ("\\.php$"                  . php-mode)      ; we hates it forever...
	  ("\\.pic$"                  . picture-mode)
	  ("\\.pod$"                  . cperl-mode)
	  ("\\.swift$"                . swift-mode)
	  ("\\.tgz$"                  . tar-mode)
	  ("\\.xs$"                   . c-mode)
	  ("\\.xpm$"                  . c-mode)
	 )
       auto-mode-alist)
      )

;; FINISH

;;(message "checkpoint 09")
;;(message "checkpoint 10")

;; ##########################################################################
;; ##########################################################################

(display-time)

;; Set up extra bits for emacs
(set-uniquify    'default)
(query-quit             t)
(global-font-lock-mode  t)
(line-number-mode       t)
(column-number-mode     t)

(if (< 21 emacs-major-version)
    (standard-display-european t)
  (set-language-environment "Latin-1"))

;;(message "checkpoint 11")

(server-start)
;(set-default-file-modes 493) ;; weasels
(resize-minibuffer-mode)

;;(message "checkpoint 12")
;;(message "checkpoint 13")

;; Ickie internal bindings
(define-key text-mode-map "\x7f"   'backward-delete-char-untabify)
(define-key text-mode-map "\e\C-j" 'fix-left-margin)

;;(message "checkpoint 14")

;; global key unbindings:
(global-unset-key "\C-h") 
;; Global key bindings
(global-set-key "\C-c\C-a"  'fill-paragraph)
(global-set-key "\C-c\C-un" 'normal-mode)
(global-set-key "\C-c\C-w"  'word-count-buffer)
(global-set-key "\C-cg"     'goto-line)
(global-set-key "\C-ckill"  'save-buffers-kill-emacs)
(global-set-key "\C-cw"     'what-line)
(global-set-key "\C-h"      'delete-backward-char)
(global-set-key "\C-m"      'reindent-then-newline-and-indent)
(global-set-key "\C-x,"     'paren-match)
(global-set-key "\C-x\C-k"  'save-buffer-kill-buffer)
(global-set-key "\C-xc"     'compile)
(global-set-key [end]       'end-of-buffer)
(global-set-key [f12]       'man)
(global-set-key [home]      'beginning-of-buffer)
(global-set-key [print]     'interactive-set-auto-mode)

;; You can find what keys a function is bound to by doing:
;; M-x where-is <name-of-command>

;;(message "checkpoint 15")

 ;; Setup customisaztion... 
(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.
 '(Info-additional-directory-list (quote ("/home/vivek/p4dev/htmlfontify")))
 '(ange-ftp-gateway-program "/usr/bin/ssh")
 '(ange-ftp-gateway-program-interactive t)
 '(blink-cursor nil)
 '(change-log-default-name "CHANGES")
 '(cperl-continued-brace-offset -2)
 '(cperl-continued-statement-offset 2)
 '(cperl-indent-left-aligned-comments nil)
 '(cperl-indent-level 4)
 '(cperl-indentation-style "BSD")
 '(cperl-syntaxify-by-font-lock t)
 '(diff-switches "-u" t)
 '(display-time-24hr-format t)
 '(fancy-splash-image "/home/vivek/images/scratch/emacs-splash.xpm")
 '(glasses-uncapitalize-p t)
 '(gnus-default-article-saver (quote gnus-summary-save-in-file))
 '(hfy-default-face-def (quote ((t :background "black" :foreground "white" :family "misc-fixed"))))
 '(hfy-display-class (quote ((class . color) (background . dark))))
 '(hfy-fallback-default-face-def (quote ((t :background black :foreground white :family misc-fixed))))
 '(hfy-optimisations (quote (merge-adjacent-tags)))
 '(html-helper-timestamp-hook (quote (insert-timestamp)))
 '(max-lisp-eval-depth 6000)
 '(p4-blame-2ary-disp-method (quote new-frame))
 '(p4-default-diff-options "-dubB")
 '(w3-delay-image-loads t))

(setq last-nonmenu-event nil)

;;(if (yes-or-no-p "do the funky sjh-thing?")
(if window-system (if (x-display-color-p) (sjh-colour-setup) (sjh-mono-setup)))

;;(message "checkpoint 16")

;(yes-or-no-p "custom-faces")

;; this next bit is where emacs stores its customisation settings -
;; which is why it isn't formatted in a human friendly way:

(custom-set-faces
  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(cperl-array-face ((t (:background "navy" :foreground "white"))))
 '(cperl-hash-face ((((class color) (background dark)) (:background "navy" :foreground "palegoldenrod"))))
 '(custom-group-tag-face ((((class color) (background light)) (:underline t :foreground "steelblue"))))
 '(custom-state-face ((((class color) (background light)) (:foreground "palegreen" :background "dimgrey"))))
 '(custom-variable-tag-face ((((class color) (background light)) (:underline t :foreground "lightblue"))))
 '(diff-added-face ((t (:foreground "cornflowerblue" :background "black"))))
 '(diff-changed-face ((t (:foreground "palegreen" :background "black"))))
 '(diff-file-header-face ((t (:foreground "lightsteelblue" :background "grey30"))))
 '(diff-hunk-header-face ((t (:foreground "lightsteelblue" :background "black"))))
 '(diff-index-face ((t (:foreground "wheat"))))
 '(diff-removed-face ((t (:foreground "orangered" :background "black"))))
 '(font-lock-comment-face ((((class color) (background dark)) (:foreground "light grey" :inherit default))))
 '(font-lock-emphasized-face ((t (:background "slategrey"))))
 '(font-lock-function-name-face ((t (:underline t :foreground "#a0c0ff" :inherit default))))
 '(font-lock-keyword-face ((((class color) (background dark)) (:foreground "#70c0ff" :inherit default))))
 '(font-lock-other-emphasized-face ((t (:bold t :foreground "red" :background "navy"))))
 '(font-lock-other-type-face ((((class color) (background dark)) (:foreground "Orchid"))))
 '(font-lock-string-face ((((class color) (background dark)) (:foreground "turquoise" :inherit default :inherit default))))
 '(font-lock-type-face ((((class color) (background dark)) (:foreground "light green" :inherit default))))
 '(font-lock-variable-name-face ((((class color) (background dark)) (:foreground "pale green" :inherit default))))
 '(font-lock-warning-face ((((class color) (background dark)) (:bold t :foreground "red" :background "white" :inherit default))))
 '(gnus-header-content-face ((t (:foreground "lightblue" :slant italic))))
 '(gnus-header-from-face ((((class color) (background dark)) (:foreground "lightblue"))))
 '(gnus-header-name-face ((((class color) (background dark)) (:foreground "white"))))
 '(gnus-header-newsgroups-face ((t (:foreground "palegoldenrod" :slant italic))))
 '(gnus-header-subject-face ((((class color) (background dark)) (:foreground "lightsteelblue"))))
 '(gnus-signature-face ((t (:slant italic))))
 '(lpc-reference-face ((((class color) (background dark)) (:foreground "bisque"))))
 '(menu ((((type x-toolkit)) (:height 110 :family unspecified))))
 '(message-cited-text-face ((((class color) (background dark)) (:foreground "palegreen"))))
 '(message-header-name-face ((((class color) (background dark)) (:foreground "aquamarine"))))
 '(message-header-newsgroups-face ((t (:foreground "palegoldenrod" :slant italic :weight bold))))
 '(message-header-subject-face ((((class color) (background dark)) (:foreground "lightblue"))))
 '(message-header-xheader-face ((((class color) (background dark)) (:foreground "skyblue"))))
 '(message-separator-face ((((class color) (background dark)) (:foreground "steelblue"))))
 '(p4-depot-added-face ((t (:foreground "steelblue"))))
 '(p4-depot-deleted-face ((t (:underline t :foreground "red"))))
 '(p4-depot-unmapped-face ((t (:foreground "grey55"))))
 '(p4-diff-change-face ((t (:foreground "palegreen"))))
 '(p4-diff-file-face ((t (:background "gray30"))))
 '(p4-diff-head-face ((t (:background "gray35"))))
 '(p4-diff-ins-face ((t (:foreground "cyan"))))
 '(purple ((t (:foreground "violet"))))
 '(region ((t (:background "slategray"))))
 '(secondary-selection ((((class color) (background light)) (:foreground "black" :background "paleturquoise"))))
 '(sh-heredoc-face ((t (:foreground "aquamarine" :weight bold))))
 '(widget-documentation-face ((((class color) (background light)) (:foreground "limegreen"))))
 '(widget-field-face ((((class grayscale color) (background light)) (:background "slategrey"))))
 '(widget-inactive-face ((((class grayscale color) (background light)) (:foreground "gray"))))
 '(widget-single-line-field-face ((((class grayscale color) (background light)) (:background "slategrey")))))

;; for testing htmlfontify, leave it off for now:
(if t nil
  (setq hfy-test-dir "/tmp/dbishell")
  (htmlfontify-run-etags hfy-test-dir)
  (htmlfontify-copy-and-link-dir
   hfy-test-dir
   (concat hfy-test-dir
	   (format "%s"
		   (or window-system (if noninteractive "batch" "tty"))))))

;;(if (not (getenv "TEST_LPC_MODE")) nil
;;  (find-file "/home/vivek/tmp/cast.lpc")
;;  (find-file "/home/vivek/src/lpc/sample.lpc")
;;  )

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


Valid HTML 4.01! Valid CSS! Any Browser Debian Pepperfish