My Emacs Page

Here is a list of emacs resources
Here is my .emacs file. I learned most of the stuff from the dot emacs site. Most of the code here has also been cut pasted from a lot of sources from the dotemacs site. Have a look at the dot emacs site. Loads of info available there.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Filename : .emacs
;; User     : Mangesh Gupte
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Emacs auto customize section. Emacs will add to this section when
;; you use the customize tool available on the help menu
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(custom-set-variables
 '(show-paren-mode t nil (paren))
 '(inhibit-startup-message t)
 '(transient-mark-mode t)
 '(global-font-lock-mode t nil (font-lock))
 '(global-auto-revert-mode t nil (autorevert))
 '(c-font-lock-extra-types
     (quote ("FILE" "\\sw+_t" "LPCTSTR" "WORD" "DWORD" "BYTE" "FIXME")))
 '(c++-font-lock-extra-types
     (quote ("\\sw+_t" "\\([iof]\\|str\\)+stream\\(buf\\)?" "ios" "string" "rope"
      "list" "slist" "deque" "vector" "bit_vector" "set" "multiset" "map" "multimap"
      "hash\\(_\\(m\\(ap\\|ulti\\(map\\|set\\)\\)\\|set\\)\\)?" "stack" "queue"
      "priority_queue" "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
      "reference" "const_reference" "LPCTSTR" "BYTE" "WORD" "DWORD" "FIXME" "true" "false"
      "private" "protected" "public" "__forceinline"))))
 (custom-set-faces)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Set the path in which i have kept my .el/.elc files
(setq load-path (append load-path (list "/auto/home/u25/mangesh/emacs/lisp")))

;; Common Settings
(setq user-full-name "Mangesh Gupte")

;; Replace "yes or no" with y or n
(defun yes-or-no-p (arg)
  "An alias for y-or-n-p, because I hate having to type 'yes' or 'no'."
  (y-or-n-p arg))

;; Put as much syntax highlighting into documents as possible
(setq font-lock-maximum-decoration t)

;; Scroll just one line when hitting the bottom of the window
(setq scroll-step 1)

;; do NOT add newlines if I cursor past last line in file
(setq next-line-add-newlines nil)


;; Shut off annoying beep. Keep it on only for special situations
;; (setq visible-bell t)

;; Frame title bar formatting to show full path of file
(setq-default
 frame-title-format
 (list '((buffer-file-name " %f" (dired-directory 
	 			  dired-directory
				  (revert-buffer-function " %b"
				  ("%b - Dir:  " default-directory)))))))

(setq-default
 icon-title-format
 (list '((buffer-file-name " %f" (dired-directory
                                  dired-directory
                                  (revert-buffer-function " %b"
                                  ("%b - Dir:  " default-directory)))))))

;; Change the font used by emacs
(setq default-frame-alist
      '((font . "-Adobe-Courier-Medium-R-Normal--14-140-75-75-M-90-ISO8859-1")))

;; Stop ^M's from displaying in system shell window
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)

;; Tell emacs where my diary file is
(setq diary-file "~.diary")

;; Don't wrap long lines when viewing
(hscroll-global-mode t)

;; To obtain new font string, place this string:
;; (insert(prin1-to-string(w32-select-font))) in the scratch buffer
;; and hit M-x eval-buffer This will give you the font string you
;; need.

;; This requires GhostScript which is available at this URL:
;; http://www.cs.wisc.edu/~ghost/aladdin To print, just hit C-cp. This
;; produces a file called printme.ps in the print directory. Open this
;; in GhostView and print from there. This works even on
;; non-postscript printers.
(setq ps-printer-name "~/print/printme.ps")
(define-key global-map "\C-cp" 'ps-print-buffer)

;; Hit f9 to force a re-fontify
(global-set-key (quote [f9]) (quote font-lock-fontify-buffer))

;; Go into proper mode according to file extension
(setq auto-mode-alist
      (append '(("\\.C$"    . c++-mode)
        ("\\.cc$"   . c++-mode)
        ("\\.cpp$"  . c++-mode)
        ("\\.cxx$"  . c++-mode)
        ("\\.hxx$"  . c++-mode)
        ("\\.h$"    . c++-mode)
        ("\\.hh$"   . c++-mode)
        ("\\.idl$"  . c++-mode)
        ("\\.ipp$"  . c++-mode)
        ("\\.c$"    . c-mode)
	("\\.ma?k\\'" . makefile-mode)
        ("\\(M\\|m\\|GNUm\\)akefile\\(\\.in\\)?" . makefile-mode)
        ("\\.pl$"   . perl-mode)
        ("\\.pm$"   . perl-mode)
        ("\\.java$" . java-mode)
        ("\\.txt$"  . text-mode)
	("\\.tex$" . latex-mode)
	("\\.sty$" . latex-mode)
        ("\\.bbl$" . latex-mode)
	("\\.html$" . html-helper-mode)
	("\\.el\\'" . emacs-lisp-mode)
	("\\.texinfo\\'" . texinfo-mode)
        ("\\.texi\\'" . texinfo-mode)
	("\\.s\\'" . asm-mode)
        ("\\.S\\'" . asm-mode)
        ("\\.asm\\'" . asm-mode)
        ("ChangeLog\\'" . change-log-mode)
        ("change\\.log\\'" . change-log-mode)
        ("changelo\\'" . change-log-mode)
        ("ChangeLog\\.[0-9]+\\'" . change-log-mode)
        ("changelog\\'" . change-log-mode)
        ("changelog\\.[0-9]+\\'" . change-log-mode)
        ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode)
	("\\.tar\\'" . tar-mode)
	("\\.\\(arc\\|zip\\|lzh\\|zoo\\|jar\\)\\'" . archive-mode)
        ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\|JAR\\)\\'" . archive-mode)
	("[]>:/\\]\\..*emacs\\'" . emacs-lisp-mode)
        ("\\`\\..*emacs\\'" . emacs-lisp-mode)
        ("[:/]_emacs\\'" . emacs-lisp-mode)
	("\\.gp$" . gnuplot-mode)
	)
	      auto-mode-alist))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MODE LINE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; I like to know what time it is. These lines show the clock in the
;; status bar. Comment out first line if you prefer to show time in 12
;; hour formatx
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)

;; show column number in status bar
(setq column-number-mode t)

;; Cannot modify text when in hide ifdef mode
(setq hide-ifdef-read-only t)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SEARCHING
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; make searches case-INsensitive
(set-default 'case-fold-search t)

; highlight incremental search
(setq search-highlight t)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C Programming
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; These setting are written in the order as described in the Emacs
;; info pages. ( Hit C-hi, then go to Emacs | Programs | Program
;; Indent | Custom C Indent | Syntactic Symbols for a description of
;; each. I found it easier to open one of my own source files, and hit
;; tab on a particular line to find the name of the syntactic
;; symbol. This assumes that the setting for
;; c-echo-syntactic-information-p is not nil. )

(defconst my-c-style
  '(
    (c-echo-syntactic-information-p . t)
    (c-basic-offset                 . 4)
    (c-toggle-auto-state            . t)
    (c-offsets-alist .
             ((string                . +)
              (c                     . 0)
              (defun-open            . 0)
              (defun-close           . 0)
              (defun-block-intro     . +)
              (class-open            . 0)
              (class-close           . 0)
              (inline-open           . 0)
              (inline-close          . 0)
              (extern-lang-open      . 0)
              (extern-lang-close     . 0)
              (func-decl-cont        . +)
              (knr-argdecl-intro     . +)
              (knr-argdecl           . +)
              (topmost-intro         . 0)
              (topmost-intro-cont    . +)
              (member-init-intro     . +)
              (member-init-cont      . +)
              (inher-intro           . +)
              (inher-cont            . +)
              (block-open            . 0)
              (block-close           . 0)
              (brace-list-open       . 0)
              (brace-list-close      . 0)
              (brace-list-intro      . +)
              (brace-list-entry      . 0)
              (statement             . 0)
              (statement-cont        . +)
              (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         . 0)
              (arglist-intro         . c-lineup-arglist-intro-after-paren)
              (arglist-cont          . c-lineup-arglist)
;;              (arglist-cont-nonempty . +)
              (arglist-cont-nonempty . c-lineup-arglist-intro-after-paren)
              (arglist-close         . c-lineup-arglist)
              (stream-op             . +)
              (inclass               . +)
              (inextern-lang         . +)
              (cpp-macro             . 0)
              (friend                . 0)
              (objc-method-intro     . +)
              (objc-method-args-cont . +)
              (objc-method-call-cont . +)
              ))

    (c-comment-only-line-offset . (0 . -1000))
    (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)))
    )
  "Gallucci C++ Programming Style")

(defun my-c-mode-common-hook ()
  (c-add-style "gallucci" my-c-style t)
  (c-set-offset 'member-init-intro '+)
  (setq tab-width 4
	indent-tabs-mode nil)
  (c-toggle-auto-hungry-state t)
  (define-key c-mode-base-map "\C-m" 'newline-and-indent)
  (modify-syntax-entry ?_ "w" c++-mode-syntax-table)
  (modify-syntax-entry ?_ "w" c-mode-syntax-table)
  )

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(setq speedbar-frame-parameters (quote
                 ((minibuffer)
                  (width          . 45)
                  (border-width   . 0)
                  (menu-bar-lines . 0)
                  (unsplittable   . t))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Cut and Paster
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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")




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Key Bindings / Key Map
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(global-set-key [C-M-tab] 'other-window)

;; go to specific line in current buffer
(global-unset-key "\M-g")
(global-set-key "\M-g" 'goto-line)

;; Eat space at point up to non-space
(global-set-key "\C-ce" 'fixup-whitespace)

;; Remap Home and End keys to move within current line, and C-Home and
;; C-End keys to beginning and end of buffer
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key [\C-home] 'beginning-of-buffer)
(global-set-key [\C-end] 'end-of-buffer)
;; Make DEL delete the current character not the last character
;; (behave like delete not like backspace)
(global-set-key [delete] 'delete-char)

;; Rebind C-z to start a shell (use .emacs_shellname for the shells rc file)
(global-set-key "\C-z" 'shell)

;; Maps F1 to give the manual entry for the current word
(global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Recreating killed buffers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; If the *scratch* buffer is killed, recreate it automatically
(save-excursion
  (set-buffer (get-buffer-create "*scratch*"))
  (lisp-interaction-mode)
  (make-local-variable 'kill-buffer-query-functions)
  (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer))

(defun kill-scratch-buffer ()
  ;; Kill the current (*scratch*) buffer
  (remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
  (kill-buffer (current-buffer))

  ;; Make a brand new *scratch* buffer
  (set-buffer (get-buffer-create "*scratch*"))
  (lisp-interaction-mode)
  (make-local-variable 'kill-buffer-query-functions)
  (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)

  ;; Since we killed it, don't let caller do that.
  nil)

;; If the *Messages* buffer is killed, recreate it automatically
(save-excursion
  (set-buffer (get-buffer-create "*Messages*"))
  (lisp-interaction-mode)
  (make-local-variable 'kill-buffer-query-functions)
  (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer))

(defun kill-scratch-buffer ()
  ;; Kill the current (*Messages*) buffer
  (remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
  (kill-buffer (current-buffer))

  ;; Make a brand new *Messages* buffer
  (set-buffer (get-buffer-create "*Messages*"))
  (lisp-interaction-mode)
  (make-local-variable 'kill-buffer-query-functions)
  (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)

  ;; Since we killed it, don't let caller do that.
  nil)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; E-Mail
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Assign a prefix for each quoted line in email replies and forwards
(setq mail-yank-prefix ">")

;; Save every outgoing message to a file
(setq mail-archive-file-name "~/mail/sent-items")

;; My Address Book
;; You can put your addresses here. They will be expanded as you type in in
;; the mail mode
(define-mail-abbrev "mangesh" "mangesh[at]csa.iisc.ernet.in")

;; Expand mail addresses as abbreviation 
(add-hook 'mail-mode-hook 'mail-abbrevs-setup)

;; Use signature file. Defaults to ~/.signature
(setq mail-signature t)

;; Home settings
(setq user-mail-address "mangesh@csa.iisc.ernet.in")
(setq smtpmail-default-smtp-server "csa.iisc.ernet.in")
(setq mail-host-address "csa.iisc.ernet.in")
(setq smtpmail-local-domain nil)


;; C-k kills whole line and newline if at beginning of line
(setq kill-whole-line t)

;; load auto-show (shows lines when cursor moves to right of long line)
;(require 'auto-show)
;(auto-show-mode 1)
;(setq-default auto-show-mode t)

;; position cursor to end of output in shell mode
;; (auto-show-make-point-visible)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MOUSE SIMPLE SET UP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Paste at point NOT at cursor
;;(setq mouse-yank-at-point t)

;; Scroll Bar gets dragged by mouse butn 1
;;(global-set-key [vertical-scroll-bar down-mouse-1] 'scroll-bar-drag)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Security Settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Dont echo the password when logging in form the emacs shell
(add-hook 'comint-output-filter-functions
	  'comint-watch-for-password-prompt)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Backups
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Tell emacs to save backups in the global backups directory...
(defun make-backup-file-name(file)
  (concat "~/emacs/emacsAutosave/" (file-name-nondirectory file) "~"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom Built Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Make the % key jump to the matching {}[]() if on another, like VI
(global-set-key "%" 'match-paren)

(defun match-paren (arg)
  "Go to the matching parenthesis if on parenthesis otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))


;; kill current buffer without confirmation
(global-set-key "\C-xk" 'kill-current-buffer)

(defun kill-current-buffer ()
  "Kill the current buffer, without confirmation."
  (interactive)
  (kill-buffer (current-buffer)))


;; Uncomment Region
(defun uncomment-region (beg end)
  "Like `comment-region' invoked with a C-u prefix arg."
  (interactive "r")
  (comment-region beg end -1))

(global-set-key "\C-c\C-c" 'comment-region)
(global-set-key "\C-c\C-u" 'comment-region)

;; Add a rectangular area containing numbers
(defun rectangle-add (start end)
  "Add all the lines in the region-rectangle and put the result in the kill ring."
  (interactive "r")
  (let ((sum 0))
    (mapc (lambda (line)
	    (string-match "[0-9.]+" line)
	    (setq sum (+ sum (string-to-number (match-string 0 line)))))
	  (extract-rectangle start end))
    (kill-new (number-to-string sum))
    (message "%s" sum)))

;; Select a region which is numbered and then renumber it 
(defun renumber-list (start end &optional num)
  "Renumber the list items in the current START..END region.
    If optional prefix arg NUM is given, start numbering from that number
    instead of 1."
  (interactive "*r\np")
  (save-excursion
    (goto-char start)
    (setq num (or num 1))
    (save-match-data
      (while (re-search-forward "^[0-9]+" end t)
	(replace-match (number-to-string num))
	(setq num (1+ num))))))

;; Prints the ascii table
(setq ascii-unprint-chars-low ["NUL " "SOH " "STX " "ETX " "EOT "
			       "ENQ " "ACK " "BEL " "BS  " "HT  "
			       "LF  " "VT  " "FF  " "CR  " "SO  "
			       "SI  " "DLE " "DC1 " "DC2 " "DC3 "
			       "DC4 " "NAK " "SYN " "ETB " "CAN "
			       "EM  " "SUB " "ESC " "FS  " "GS  "
			       "RS  " "US  "])
(defun ascii-table ()
  "Prints a formatted ASCII table.  With control characters symbolically shown"
  (interactive)
  (switch-to-buffer "*ASCII*")
  (erase-buffer)
  (insert "ASCII Table:\n\n")
  (let ((i 0))
    (let ((j 0))
      ; Start of table.  Print header.
      (insert "    0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F")
      (while (< i 16)
	(setq j 0)
	; Add in "Not Ascii after this point seperator" if i = 8
	(if (= i 8)
	    (insert "\n\nCharacters after 127 aren't defined in the ASCII spec\n 
                         but are defined on this computer's locale as\n")
	  )
	; start of new line, insert table index
	(insert (format "\n %X  " i))
	(while (< j 16)
	  (let ((char-num (+ (* i 16) j)))
	    (if (or (< char-num 32))
		(insert (aref ascii-unprint-chars-low char-num))
	      (if (= char-num 127)
		  (insert "DEL ")
		(if (or (< char-num 127) (> char-num 159))
		    (insert (format "%c   " char-num))
		  (insert "    ")
		  )
		)
	      )
	    )
	  (setq j (+ j 1))
	  )
	(setq i (+ i 1))
	)
      )
    )
  (beginning-of-buffer)
  )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load Files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
(autoload 'longlines-mode "longlines" "Chop long lines" t)
(autoload 'calculator "calculator" "A simple pocket calculator for Emacs." t)
(autoload 'folding-mode "folding" "Folding mode" t) 
(autoload 'woman "woman" "Read man pages without external programs" t)

(add-hook 'html-helper-load-hook '(lambda () (require 'html-font)))
(add-hook 'html-helper-mode-hook '(lambda () (font-lock-mode 1)))

(setq html-helper-do-write-file-hooks t)
(setq html-helper-build-new-buffer t)
(setq html-helper-address-string 
 "Mangesh Gupte <
   ;mangesh[at]csa.iisc.ernet.in>")
;;(setq html-helper-basic-offset 4)
;;(setq html-helper-item-continue-indent 8)
;;(setq html-helper-never-indent nil)

(folding-mode)
(folding-mode-add-find-file-hook)

;; these lines enable the use of gnuplot mode
(autoload 'gnuplot-mode "gnuplot" "gnuplot major mode" t)
(autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot mode" t) 

(require 'session)
(add-hook 'after-init-hook 'session-initialize)

(require 'winring)
(winring-initialize)

;;(require 'color-theme)
;;(color-theme-matrix)

(require 'setnu)
(require 'tex-site)

;; ctypes
(defun my-activate-ctypes () (require 'ctypes))
(add-hook 'c-mode-hook 'my-activate-ctypes)
(add-hook 'c++-mode-hook 'my-activate-ctypes)

;; Use lazy lock for syntax coloring, otherwise large files will not
;; be colored. Also allows large files to load faster. 
(setq font-lock-support-mode 'lazy-lock-mode)
(setq lazy-lock-defer-on-scrolling nil)
(setq lazy-lock-defer-time 1)
(setq lazy-lock-defer-on-the-fly nil)
(setq lazy-lock-stealth-time 20)
(setq lazy-lock-stealth-lines 25)
(setq lazy-lock-stealth-verbose nil)
(require 'font-lock)
(require 'lazy-lock)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Some New stuff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This makes emacs execute in the shell specified not the default shell that you are using
; (setq explicit-shell-file-name "/bin/sh")

;; This keeps the buffer in sync with the one that is on disk
(global-auto-revert-mode 1)


(require 'info)
(setq Info-directory-list
      (cons (expand-file-name "~/info")
            Info-directory-list))

;; Set the calendar style to european ( DD/MM/YY)
;;(setq european-calendar-style 't)

;; Show the (marked) calender when emacs starts
;;(calender)



;; iswitch mode initialization
(autoload 'iswitchb "iswitchb" "Run iswitchb" t)
(setq read-buffer-function 'iswitchb-read-buffer)
(setq iswitchb-default-method 'samewindow)
(add-hook 'iswitchb-make-buflist-hook 'iswitchb-summaries-to-end)
(iswitchb-default-keybindings)

; (prefer-coding-system 'utf-8)
; (autoload 'devanagari-compose-region "devan-util" "shape a devanagari utf region." t)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;; personnal functions ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun nu-source () 
  "Reread ~/.emacs."
  (interactive) 
  (load-file "~/.emacs"))


;; buffer functions
(defun my-previous-buffer ()
  "Cycle to the previous buffer with keyboard."
  (interactive)
  (bury-buffer))

(defun my-next-buffer ()
  "Cycle to the next buffer with keyboard."
  (interactive)
  (let* ((bufs (buffer-list))
	 (entry (1- (length bufs)))
	 val)
    (while (not (setq val (nth entry bufs)
                      val (and (/= (aref (buffer-name val) 0)
                                   ? )
                               val)))
      (setq entry (1- entry)))
    (switch-to-buffer val)))

(global-set-key '[\C-\M-right] 'my-next-buffer) ;; buffer switch with M right 
(global-set-key '[\C-\M-left]  'my-previous-buffer) 


;; print X font name for Windows font
(if (eq window-system 'w32)
    (defun ewd-get-x-font-name ()
      "Select font from dialog box, then print X font name in current buffer."
      (interactive)
      (insert (prin1-to-string (w32-select-font)))))

;; add a string in front of all lines in the region
(defun ewd-prepend (start end s)
  "Add a string in front of all lines in the region."
  (interactive "*r\nMEnter a string: ")
  (save-excursion
    (save-restriction
      (narrow-to-region
       (progn (goto-char start) (beginning-of-line) (point))
       (progn (goto-char end) (end-of-line) (point)))
      (goto-char (point-min))
      (beginning-of-line)
      (while (not (eobp))
        (insert s)
        (forward-line 1)))))
                                               
;; remove a string from the beginning of all lines in the region
(defun ewd-unprepend (start end s)    
  "Remove a string from the front of all lines in the region."
  (interactive "*r\nMEnter a string: ")
 (save-excursion
    (save-restriction
      (narrow-to-region
       (progn (goto-char start) (beginning-of-line) (point))
       (progn (goto-char end) (end-of-line) (point)))
      (goto-char (point-min))         
      (while (not (eobp))
        (if (looking-at (regexp-quote s))
            (delete-region (match-beginning 0) (match-end 0)))
        (forward-line 1)))))

;; ignored extentsions 
(setq completion-ignored-extensions
        (append '(".bci" ".bin" ".binf" ".com" ".ext" ".free" 
                  ".o") completion-ignored-extensions))
(delete ".log" completion-ignored-extensions)

(setq delete-auto-save-files t) ;; delete unnecessary autosave files

;;{{{ unfill-paragraph
(defun unfill-paragraph (arg)
  "Pull this whole paragraph up onto one line."
  (interactive "*p")
  (let ((fill-column 10000))
    (fill-paragraph arg))
  )
;;}}}

;;{{{ pilot-mark

(defvar pilot-mark "?"
  "*String to mark paragraphs for AportisDocs.")

(defun pilot-mark (arg)
  "Mark this spot (with ARG, this line) for AportisDoc bookmark."
  (interactive "*P")
  (unless arg
    (beginning-of-line 1))
  (insert pilot-mark " ")
  (save-restriction
    (save-excursion
      (goto-char (point-max))
      (skip-chars-backward (concat pilot-mark "<>\n"))
      (unless (looking-at (concat "\n<" pilot-mark ">\n"))
        (goto-char (point-max))
        (insert "\n<" pilot-mark ">\n")))))

;;}}}
;;{{{ quote-paragraph

(defvar quote-fill-prefix "\t"
  "*Fill prefix to use in quoted material.")

(defun quote-paragraph (arg)
  "Fill (with ARG, justify) the current paragraph as a quote (using quote-fill-prefix)."
  (interactive "*P")
  (save-restriction
    (mark-paragraph)
    (narrow-to-region (if (looking-at "\n") (1+ (point)) (point)) (mark))
    (let ((fill-prefix quote-fill-prefix)
          (case-replace nil)
          (case-fold-search nil))
      (replace-regexp "^" fill-prefix nil)
      (fill-paragraph arg))))

;;}}}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Tweak built in functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; make cursor stay in the same column when scrolling
(defadvice scroll-up (around ewd-scroll-up first act)
  "Keep cursor in the same column."
  (let ((col (current-column)))
    ad-do-it
    (move-to-column col)))
                                
(defadvice scroll-down (around ewd-scroll-down first act)
  "Keep cursor in the same column."
  (let ((col (current-column)))
    ad-do-it                          
    (move-to-column col))) 

;; Change the values of the default TAB stops ,so that now it stops
;; after 4 characters and not after 8
;;(let ((i 4))
;;  (while (< i 124)
;;    (insert (number-to-string i) " ")
;;    (setq i (+ 4 i))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Enable some functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Add some hooks
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; This automatically fills in comments but not code.
(add-hook 'c-mode-common-hook
	  (lambda ()
	    (auto-fill-mode 1)
	    (set (make-local-variable 'fill-nobreak-predicate)
		 (lambda ()
		   (not (eq (get-text-property (point) 'face)
			    'font-lock-comment-face))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Experimental Stuff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(add-hook 'gud-mode-hook 
  '(lambda ()
     (local-set-key [home]        ; move to beginning of line, after prompt
		    'comint-bol)
     (local-set-key [up]          ; cycle backward through command history
		    '(lambda () (interactive)
		       (if (comint-after-pmark-p)
			   (comint-previous-input 1)
			 (previous-line 1))))
     (local-set-key [down]        ; cycle forward through command history
		    '(lambda () (interactive)
		       (if (comint-after-pmark-p)
			   (comint-next-input 1)
			 (forward-line 1))))
     ))

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

;; To copy to named register: C-x r s a - Where a is the name of the
;; register ( a - z ) to save the text to.

;; To paste from named register: C-x r i a - Where a is the name of
;; the register ( a - z ) to paste the saved text from.

;; To remember current point: C-x r spc a - Where a is the name of the
;; register to save point to.

;; To jump to named point: C-x r j a - Where a is the name of the
;; register holding desired point to jump to



Mangesh Gupte <mangesh[at]csa.iisc.ernet.in>
Last modified: Fri Apr 8 13:35:10 2005