Sridhar.el

From Rohidekar

Jump to: navigation, search

Deprecated

;-------------------------------------------------------------------------------
;
; DESCRIPTION
;   My personalized .emacs file
;
; AUTHOR
;   Sridhar Sarnobat - ss401533[AT]gmail.com
;
;-------------------------------------------------------------------------------

;
; SSARNOBA: find out about key bindings for folding-mode
;

;===============================================================================
; Written by others
;===============================================================================

;-------------------------------------------------------------------------------
;
; NAME
;   Highlight cursor movement
;
; DESCRIPTION
;   Emacs "shift-mark" functionality. Allows you to mark a region by holding 
;   down the Shift modifier key and moving the cursor.
;
; LINK
;   http://www.cs.ucsb.edu/~matz/study/EmacsShiftMark.html
;
; AUTHOR
;   Written by matz"a"cs.ucsb.edu, March 10th, 1998
;
;-------------------------------------------------------------------------------

(defun shift-mark (cmd)
  "Expands marked region to the point (position of cursor) after executing
command 'cmd'. If no region is marked, we mark one first."
  (interactive "_a")
  (if (not (region-active-p))
      (progn (set-mark-command nil)
	     (command-execute cmd))
  (command-execute cmd)
))

(defun shift-mark-forward-char ()
  (interactive)
  (shift-mark 'forward-char)
)

(defun shift-mark-backward-char ()
  (interactive)
  (shift-mark 'backward-char)
)

(defun shift-mark-forward-word ()
  (interactive)
  (shift-mark 'forward-word)
)

(defun shift-mark-backward-word ()
  (interactive)
  (shift-mark 'backward-word)
)

(defun shift-mark-forward-paragraph ()
  (interactive)
  (shift-mark 'forward-paragraph)
)

(defun shift-mark-backward-paragraph ()
  (interactive)
  (shift-mark 'backward-paragraph)
)

(defun shift-mark-previous-line ()
  (interactive)
  (shift-mark 'previous-line)
)

(defun shift-mark-next-line ()
  (interactive)
  (shift-mark 'next-line)
)

(defun backspace-delete-marked-region ()
  (interactive)
  ;  (zmacs-region-stays t)
  (if (region-active-p)
      (kill-region (mark) (point))
    (delete-backward-char 1)
    )
)

;-------------------------------------------------------------------------------
; NAME
;   Convert ^M newlines
;
; DESCRIPTION
;   In this case the easiest way I've seen for converting DOS-format 
;   line-endings to unix-format is a handy pair of Lisp function which Earl 
;   Stutes wrote about in LG #10; I'll repeat them here:
;
; URL
;   http://linuxgazette.net/issue39/ayers1.html
;
; AUTHOR
;   Earl Stutes
;
;-------------------------------------------------------------------------------

(defun dos-unix ()
  (interactive)
  (goto-char (point-min))
  (while (search-forward "\r" nil t) (replace-match "")))

(defun unix-dos ()
  (interactive)
  (goto-char (point-min))
  (while (search-forward "\n" nil t) (replace-match "\r\n")))

;-------------------------------------------------------------------------------
;
; NAME
;   Right align C-comments
;
; AUTHOR
;   William Waddington (Oracle)
;
;-------------------------------------------------------------------------------

;;
;; Right justify a C style comment
;;

(defun bill-right-justify-c-comment () 
  "*Right justify a C comment.  If there is no comment starter on the line, 
it will justify the entire line"
  (interactive)
  (save-excursion
    (save-restriction
      (save-match-data
	(bill-go-begin-comment)
	(if (and (not (looking-at "/\\*_"))
		 (looking-at "/\\*"))
	    (progn
	      (end-of-line)
	      (delete-horizontal-space)
	      (forward-char -2)
	      (if (looking-at "\*/")
		  (progn
		    (delete-horizontal-space)
		    (insert ? )))
	      (bill-go-begin-comment)
	      (delete-horizontal-space)
	      (if (looking-at "/\\*")
		  (progn
		    (forward-char 2)
		    (delete-horizontal-space)
		    (insert ? )))
	      (end-of-line)
	      (if (< (current-column) 79)
		  (let ((addn (- 79 (current-column))))
		    (bill-go-begin-comment)
		    (indent-to (+ (current-column) addn) 1)))
	      (end-of-line)))))))

(defun bill-go-begin-comment () 
  "*Go the the beginning of a comment which begins on the current line,
Or the beginning of the current line"
  (interactive)
  (let ((cur-pt (point)) 
	(beg-line))
    (beginning-of-line)
    (setq beg-line (point))
    (end-of-line)
    (if (not (search-backward "/*" beg-line t))
	(goto-char cur-pt))))

;-------------------------------------------------------------------------------
; Jim Terry: Backspace
;-------------------------------------------------------------------------------

(defun windows-backspace ()
  "Acts as Windows backspace: delete region if one exists; else delete previous character."
  (interactive)2
  (if (region-active-p) 
   (delete-region (point) (mark))
   (delete-backward-char))
)

;-------------------------------------------------------------------------------
;
; NAME
;   Delete line - including newline
; 
; DESCRIPTION
;   Define the nuke-line function. The line is killed, then the newline
;   character is deleted. The column which the cursor was positioned at is then
;   restored. Because the kill-line function is used, the contents deleted can
;   be later restored by usibackward-delete-char-untabifyng the yank commands.
;
; SOURCE
;   http://homepages.inf.ed.ac.uk/s0243221/emacs/
;
;-------------------------------------------------------------------------------

(defun nuke-line()
  "Kill an entire line, including the trailing newline character"
  (interactive)

  ;; Store the current column position, so it can later be restored for a more
  ;; natural feel to the deletion
  (setq previous-column (current-column))

  ;; Now move to the end of the current line
  (end-of-line)

  ;; Test the length of the line. If it is 0, there is no need for a
  ;; kill-line. All that happens in this case is that the new-line character
  ;; is deleted.
  (if (= (current-column) 0)
    (delete-char 1)

    ;; This is the 'else' clause. The current line being deleted is not zero
    ;; in length. First remove the line by moving to its start and then
    ;; killing, followed by deletion of the newline character, and then
    ;; finally restoration of the column position.
    (progn
      (beginning-of-line)
      (delete-line)
      (delete-char 1)
      (move-to-column previous-column))))

;-------------------------------------------------------------------------------
;
; NAME
;   Kill buffer without confirmation
;
; SOURCE
;   http://eden.rutgers.edu/~mangesh/emacs.html
;
;-------------------------------------------------------------------------------

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

;===============================================================================
; ssarnoba Mode hook functions
;===============================================================================

(defun ssarnoba-find-file-hook ()
  "Hooks for find file"
  (interactive)
  (dirs)
;  (message "this doesn't work")
  )

;-------------------------------------------------------------------------------
; Java mode
;-------------------------------------------------------------------------------

(defun ssarnoba-java-hook ()
  "Hooks for java mode"
  (interactive)
  (
   if (eq major-mode 'java-mode) 
   (progn 
     (dos-unix)
     ; http://cow.physics.wisc.edu/~craigm/idl/archive/msg04692.html
     (setq font-lock-maximum-size nil)
     ; This is what they use for c mode in dwalt
     ; use c-show-syntactic-information to get the style of the 
     ; current line
     (setq c-basic-offset 2)
     (setq c-recognize-knr-p t)
     (setq c-tab-always-indent t)
;     (setq indent-tabs-mode nil)
     (setq c-strict-syntax-p t)
     (setq c-auto-newline t)
     (set-fill-column 79)
;     (toggle-truncate-lines)                                 ; Don't wrap Lines
     (local-set-key (kbd "BS") 'windows-backspace)
;     (setq-default line-number-mode 1)
;     (setq-default column-number-mode 1)
     ; fume-mode allows you to: 
     ; - list functions in a src file
     ; - show the current function
     (turn-on-fume-mode)
   )
  )
)

;-------------------------------------------------------------------------------
; TWiki erin mode
;-------------------------------------------------------------------------------

(defun ssarnoba-erin-hook ()
  "Hooks for sql mode"
  (interactive)
  (
   if (eq major-mode 'erin-mode) 
   (progn 
;     (turn-on-font-lock)
;     (toggle-truncate-lines)                                 ; Don't wrap Lines
;     (setq-default line-number-mode 1)
;     (setq-default column-number-mode 1)
;     (setq-default tab-width 40)
;     (setq indent-tabs-mode nil)
      (local-set-key (kbd "TAB") 'ssarnoba-tab-3)
     )
   )
  )
;-------------------------------------------------------------------------------
; SH Mode
;-------------------------------------------------------------------------------

(defun ssarnoba-sh-hook ()
  "Hooks for sh mode"
  (interactive)
  (
   if (eq major-mode 'sh-mode) 
   (progn 
      (local-set-key (kbd "TAB") 'ssarnoba-tab-2)
     )
   )
  )

;-------------------------------------------------------------------------------
; SQL mode hook
;-------------------------------------------------------------------------------

(defun rotate-yank-pointer (arg)
  "Rotate the yanking point in the kill ring."
  (interactive "p")
  (let ((length (length kill-ring)))

    (if (zerop length)

        ;; then-part
        (error "Kill ring is empty")

      ;; else-part
      (setq kill-ring-yank-pointer
            (nthcdr (% (+ arg
                          (- length
                             (length
                              kill-ring-yank-pointer)))
                       length)
                    kill-ring)))))

(defun unset-mark-command ()
  "Remove current mark." 
  (interactive) 
  (setq mark-ring nil) 
  (set-mark nil) 
  (message "Mark unset.")
) 


;(defun ssarnoba-delete-line ()
;  (interactive)
;  (progn 
;    (set-mark-command nil)
;    (end-of-line)
;    (delete-region (point) (mark))
;)
  
(defun ssarnoba-delete-line ()
  (interactive)
  (progn 
  (delete-region (point) (progn (end-of-line) (point)))
  )
)

;    (save-excursion

;    (set-mark-command nil)
;    (end-of-line)
;    (delete-region (point) (mark))


;    (unset-mark-command) 
;  (setq mark-ring nil) 
;  (deactivate-mark) 
;(setq deactivate-mark t) 
;  (keyboard-quit) ; SSARNOBA TODO - really all we want to do is reset the mark, but nothing seems to do that
;    (set-mark-command nil)
;    (quit)
;   )

;(defun ec-delete-to-end-of-line ()
 ; (delete-char (- (line-end-position) (point))))

(defun ssarnoba-sql-hook ()
  "Hooks for sql mode"
  (interactive)
  (
   if (eq major-mode 'sql-mode) 
   (progn 
     (turn-on-font-lock)
     (sql-highlight-oracle-keywords)
;     (toggle-truncate-lines)                                ; Don't wrap Lines
     (setq-default line-number-mode 1)
     (setq-default column-number-mode 1)
;     (setq indent-tabs-mode nil)
;     (local-set-key (kbd "M-k") 'ssarnoba-delete-line)
     )
   )
  )

;-------------------------------------------------------------------------------
; Shell mode hook
;-------------------------------------------------------------------------------

(defun ssarnoba-shell-hook ()
  "Hooks for shell mode"
  (interactive)
  (
   if (eq major-mode 'shell-mode) 
   (progn 
     ; These doesn't work
     (setq  shell-dirtrackp t) 
     (setq  shell-cd-regexp "cd")
     ;(shell-dirtrack-toggle)

     ; get rid of scrollbar at bottom of shell window
     ;(transpose-line-up '0)
     ; For SQL Plus, you need to put 'set TABS off' in your login.sql
;     (setq indent-tabs-mode nil)
     (setq           comint-input-ring-size 2000)
     (local-set-key (kbd "C-a")           'mark-whole-buffer) ; CAN'T USE GLOBAL_SET_KEY here
     (local-set-key (kbd "M-s")           'other-window)
     (turn-on-font-lock)
;     (setq-default line-number-mode 1)
;     (setq-default column-number-mode 1)
     (rename-uniquely)
;     (toggle-truncate-lines)                                ; Don't wrap Lines

     ; Fix junk characters in shell mode
     ; Loading the default .bashrc file in Debian turns on terminal 
     ; coloring. 
     ; Unfortunately, if you ever use the the shell buffer in Emacs, 
     ; this has the 
     ; unfortunately concequence of outputting garbage characters any 
     ; time you try 
     ; to run ls.
     (ansi-color-for-comint-mode-on)

     ; Move to beginning of line, after prompt
     (local-set-key [home]   'comint-bol)
     )
   )
  )

;===============================================================================
; ssarnoba Mode hooks
;===============================================================================

;-------------------------------------------------------------------------------
; Sync shell working directory before find-file
;-------------------------------------------------------------------------------

; I DON'T THINK THIS WILL WORK
(add-hook 'shell-set-directory-error-hook 'ssarnoba-test)
; These is not what you want - it resyncs after every keypress
;(add-hook 'pre-command-hook 'dirs)
;(add-hook 'post-command-hook 'dirs)

;-------------------------------------------------------------------------------
; NAME
;   Remove ^M
;
; DESCRIPTION
;   Removes ^M from the end of lines
;
; NOTES
;   If one's shell is tcsh when emacs is invoked, there is one bizarre 
;   thing that happens when one goes to the interactive shell in Emacs. 
;   Every line of output from a command invoked from the interactive 
;   shell has ^M appended to it. However, not to worry, Emacs has a 
;   solution. It is the line:
;-------------------------------------------------------------------------------

(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m)

(add-hook 'erin-mode-hook  'ssarnoba-erin-hook)
(add-hook 'sql-mode-hook   'ssarnoba-sql-hook)
(add-hook 'shell-mode-hook 'ssarnoba-shell-hook)
(add-hook 'java-mode-hook  'ssarnoba-java-hook)
(add-hook 'find-file-hook  'ssarnoba-find-file-hook)
(add-hook 'sh-mode-hook    'ssarnoba-sh-hook)

;===============================================================================
; ssarnoba Key Bindings
;===============================================================================

;===============================================================================
; ssarnoba Functions
;===============================================================================

;-------------------------------------------------------------------------------
; Launch Shell buffer
;-------------------------------------------------------------------------------

(defun ssarnoba-launch-shell ()
  "Launches a new shell in the same window as currently focussed"
  (interactive)
  (progn 
;   (other-window 1)
   (shell)
;   (delete-other-windows)
  )
)

;-------------------------------------------------------------------------------
; Firefox-like tab manipulation
;-------------------------------------------------------------------------------

(defun ssarnoba-delete-tab ()
  "Launches a new shell in the same window as currently focussed"
  (interactive)
  (progn 
   (kill-current-buffer)
   (delete-window)
  )
)

(defun ssarnoba-delete-other-tab ()
  "Launches a new shell in the same window as currently focussed"
  (interactive)
  (progn 
   (other-window 1)
   (kill-current-buffer)
   (other-window 1)
   (delete-other-windows)
  )
)

;-------------------------------------------------------------------------------
;
; NAME
;   Right align comments
;
; DESCRIPTION
;   In similar spirit to William Waddington's right justification of C-comments
;   right justify comments in other languages
;
;-------------------------------------------------------------------------------

; SSARNOBA: Get this to work in perl mode too

(defun ssarnoba-right-justify-any-comment ()
  (interactive)
  (
   if (eq major-mode 'sql-mode)
   (progn 
    (ssarnoba-right-justify-sql-comment)
   )
   (
    if (eq major-mode 'java-mode)
    (progn
     (ssarnoba-right-justify-cpp-comment)
    )
    (
     if (eq major-mode 'perl-mode)
     (progn
      (ssarnoba-right-justify-perl-comment)
     )
     (
      if (eq major-mode 'emacs-lisp-mode)
      (progn
       (ssarnoba-right-justify-lisp-comment)
      )
      (
       if (eq major-mode 'sh-mode)
       (progn
        (ssarnoba-right-justify-perl-comment)
       )
      )
     )
    )
   )
  )
)

;;
;; Right justify a Lisp comment
;;

(defun ssarnoba-right-justify-lisp-comment () 
  "*Right justify a Lisp comment.  If there is no comment starter on the line, 
it will justify the entire line"
  (interactive)
  (save-excursion
    (save-restriction
      (save-match-data
	(ssarnoba-go-begin-lisp-comment)
	(if (looking-at ";")
	    (progn
	      (end-of-line)
	      (delete-horizontal-space)	      
	      (ssarnoba-go-begin-lisp-comment)    
	      (delete-horizontal-space)
	      (if (looking-at ";")
		  (progn
		    (forward-char 1)
		    (delete-horizontal-space)
		    (insert ? ))) ; '? ' means <SPACE>
	      (end-of-line)
	      (if (< (current-column) 80)
		  (let ((addn (- 80 (current-column))))
		    (ssarnoba-go-begin-lisp-comment)
		    (indent-to (+ (current-column) addn) 1)))
	      (end-of-line)))))))

(defun ssarnoba-go-begin-lisp-comment () 
  "*Go the the beginning of a comment which begins on the current line,
Or the beginning of the current line"
  (interactive)
  (let ((cur-pt (point)) 
	(beg-line))
    (beginning-of-line)
    (setq beg-line (point))
    (end-of-line)
    (if (not (search-backward ";" beg-line t))
	(goto-char cur-pt))))

;;
;; Right justify a SQL one line comment
;;

(defun ssarnoba-right-justify-sql-comment () 
  "*Right justify a SQL comment.  If there is no comment starter on the line, 
it will justify the entire line"
  (interactive)
  (save-excursion
    (save-restriction
      (save-match-data
	(ssarnoba-go-begin-sql-comment)
	(if (looking-at "--")
	    (progn
	      (end-of-line)
	      (delete-horizontal-space)	      
	      (ssarnoba-go-begin-sql-comment)    
	      (delete-horizontal-space)
	      (if (looking-at "--")
		  (progn
		    (forward-char 2)
		    (delete-horizontal-space)
		    (insert ? ))) ; '? ' means <SPACE>
	      (end-of-line)
	      (if (< (current-column) 79)
		  (let ((addn (- 79 (current-column))))
		    (ssarnoba-go-begin-sql-comment)
		    (indent-to (+ (current-column) addn) 1)))
	      (end-of-line)))))))

(defun ssarnoba-go-begin-sql-comment () 
  "*Go the the beginning of a comment which begins on the current line,
Or the beginning of the current line"
  (interactive)
  (let ((cur-pt (point)) 
	(beg-line))
    (beginning-of-line)
    (setq beg-line (point))
    (end-of-line)
    (if (not (search-backward "--" beg-line t))
	(goto-char cur-pt))))

;;
;; Right justify a Perl one line comment
;;

(defun ssarnoba-right-justify-perl-comment () 
  "*Right justify a Perl comment.  If there is no comment starter on the line, 
it will justify the entire line"
  (interactive)
  (save-excursion
    (save-restriction
      (save-match-data
	(ssarnoba-go-begin-perl-comment)
	(if (looking-at "#")
	    (progn
	      (end-of-line)
	      (delete-horizontal-space)	      
	      (ssarnoba-go-begin-perl-comment)    
	      (delete-horizontal-space)
	      (if (looking-at "#")
		  (progn
		    (forward-char 1)
		    (delete-horizontal-space)
		    (insert ? ))) ; '? ' means <SPACE>
	      (end-of-line)
	      (if (< (current-column) 80)
		  (let ((addn (- 80 (current-column))))
		    (ssarnoba-go-begin-perl-comment)
		    (indent-to (+ (current-column) addn) 1)))
	      (end-of-line)))))))

(defun ssarnoba-go-begin-perl-comment () 
  "*Go the the beginning of a comment which begins on the current line,
Or the beginning of the current line"
  (interactive)
  (let ((cur-pt (point)) 
	(beg-line))
    (beginning-of-line)
    (setq beg-line (point))
    (end-of-line)
    (if (not (search-backward "#" beg-line t))
	(goto-char cur-pt))))

;;
;; Right justify a C++ one line comment
;;

(defun ssarnoba-right-justify-cpp-comment () 
  "*Right justify a C++ comment.  If there is no comment starter on the line, 
it will justify the entire line"
  (interactive)
  (save-excursion
    (save-restriction
      (save-match-data
	(ssarnoba-go-begin-cpp-comment)
	(if (looking-at "//")
	    (progn
	      (end-of-line)
	      (delete-horizontal-space)	      
	      (ssarnoba-go-begin-cpp-comment)    
	      (delete-horizontal-space)
	      (if (looking-at "//")
		  (progn
		    (forward-char 2)
		    (delete-horizontal-space)
		    (insert ? )))                          ; '? ' means <SPACE>
	      (end-of-line)
	      (if (< (current-column) 79)
		  (let ((addn (- 79 (current-column))))
		    (ssarnoba-go-begin-cpp-comment)
		    (indent-to (+ (current-column) addn) 1)))
	      (end-of-line)))))))

(defun ssarnoba-go-begin-cpp-comment () 
  "*Go the the beginning of a comment which begins on the current line,
Or the beginning of the current line"
  (interactive)
  (let ((cur-pt (point)) 
	(beg-line))
    (beginning-of-line)
    (setq beg-line (point))
    (end-of-line)
    (if (not (search-backward "//" beg-line t))
	(goto-char cur-pt))))

;-------------------------------------------------------------------------------
; NAME
;   Tab region
;
; DESCRIPTION
;   Indent and Unindent highlighted regions using the tab key
;
; AUTHOR
;   ?
;-------------------------------------------------------------------------------

(defun windows-tab (arg)
  "Prepend arg spaces to each line in the highlighted region."
  (interactive "n")arg
  (if (region-active-p)
   (progn
    (indent-rigidly (mark) (point) arg)
    (exchange-point-and-mark)
    (indent-rigidly (mark) (point) arg)
    (exchange-point-and-mark)
    (activate-region)
   )
   (progn
    (while (> arg 0)                                        ; true-or-false-test
     (insert " ")
     (setq arg (1- arg)))                                          ; decrementer
   )
  )
)

;
; Tab size
;

(defun ssarnoba-tab-2 ()
  "Prepend 2 spaces to each line in the highlighted region."
  (interactive)2
  (windows-tab '2)
)

(defun ssarnoba-untab-2 ()
  "Remove 2 spaces to each line in the highlighted region."
  (interactive)2
  (windows-tab '-2)
)


(defun ssarnoba-tab-3 ()
  "Prepend 2 spaces to each line in the highlighted region."
  (interactive)3
  (windows-tab '3)
)

(defun ssarnoba-untab-3 ()
  "Remove 2 spaces to each line in the highlighted region."
  (interactive)3
  (windows-tab '-3)
)

;===============================================================================
; ssarnoba : key bindings
;===============================================================================

(global-set-key (kbd "C-i")    'indent-rigidly)
(global-set-key (kbd "<Sh-TAB>") 'ssarnoba-untab-2)
(global-set-key (kbd "TAB")    'ssarnoba-tab-2)

;-------------------------------------------------------------------------------
; TEXT
;-------------------------------------------------------------------------------

(global-set-key (kbd "C-z")   'undo)                                      ; Undo
(global-set-key (kbd "C-v")   'yank)                                     ; Paste
(global-set-key (kbd "C-b")   'copy-primary-selection)                    ; Copy
(global-set-key (kbd "C-e")   'kill-primary-selection)                     ; Cut
(global-set-key (kbd "C-DEL") 'backward-or-forward-kill-word) ; Delete Next Word
(global-set-key (kbd "<C-BS>")  'backward-delete-word)      ; Delete Previous Word

; Delete entire line without copying to clipboard
; Can't use nuke line because this deletes everything before the cursor too
;(global-set-key (kbd "M-k") 'nuke-line)
(global-set-key (kbd "C-h")   'query-replace-regexp)
;(global-set-key (kbd "M-s") 'sort-lines) ; Not frequent enough to use such an ergonomic binding
(global-set-key (kbd "M-k")   'ssarnoba-delete-line)

;-------------------------------------------------------------------------------
; TEXT SEARCHING
;-------------------------------------------------------------------------------

;(global-set-key (kbd "C-f") 'isearch-forward)                        ; Find text
;(global-set-key (kbd "C-F") 'isearch-forward-regexp)
;(global-set-key (kbd "C-R") 'isearch-backward-regexp)
;(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)

(global-set-key (kbd "C-f") 'isearch-forward-regexp)
(global-set-key (kbd "C-r") 'isearch-backward-regexp)
(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)

; When in isearch-mode, type C-w to yank word from buffer onto end 
; of search string and search for it.

;-------------------------------------------------------------------------------
; FILES
;-------------------------------------------------------------------------------

(global-set-key (kbd "C-s") 'save-buffer)                            ; Save file
(global-set-key (kbd "C-S") 'save-buffer)                            ; Save file
(global-set-key (kbd "C-k") 'kill-buffer)                           ; Close file
(global-set-key [f2]        'find-file-at-point)                     ; Open file

;-------------------------------------------------------------------------------
; CURSOR
;-------------------------------------------------------------------------------

; up/down block cursor movement
(global-set-key (kbd "<C-down>") 'forward-block-of-lines)
(global-set-key (kbd "<C-up>")   'backward-block-of-lines)
; up/down paragraph cursor movement
(global-set-key (kbd "<M-up>")   'backward-paragraph)
(global-set-key (kbd "<M-down>") 'forward-paragraph)

;-------------------------------------------------------------------------------
; HIGHLIGHTING
;-------------------------------------------------------------------------------

;(global-unset-key ("C-Sh-right") 
(global-set-key (kbd "<Sh-C-right>")    'shift-mark-forward-word)     ; Select All
(global-set-key (kbd "C-a")           'mark-whole-buffer)
;(global-set-key (kbd "C-u") 'kill-region)

;-------------------------------------------------------------------------------
; FORMATTING
;-------------------------------------------------------------------------------
(global-set-key (kbd "C-F")    'sql-to-select)
(global-set-key (kbd "M-m")    'center-line)

;-------------------------------------------------------------------------------
; COMMENTING
;-------------------------------------------------------------------------------

;(global-set-key (kbd "M-C-c") 'comment-region)
(global-set-key (kbd "C-/") 'comment-line-or-region)
(global-set-key (kbd "C-?") 'uncomment-line-or-region)
;(global-set-key (kbd "M-C-u") 'uncomment-region)
; Bill's right justify comment
(global-set-key (kbd "M-a")   'ssarnoba-right-justify-any-comment)

;-------------------------------------------------------------------------------
; SHELL
;-------------------------------------------------------------------------------
(global-set-key (kbd "C-u")    'rename-uniquely)
(global-set-key [f9]           'ssarnoba-launch-shell)

;-------------------------------------------------------------------------------
; WINDOW
;-------------------------------------------------------------------------------
(global-set-key [(f6)]                  'delete-other-windows)
(global-set-key (kbd "<C-M-Sh-TAB>")      'delete-other-windows)

(global-set-key [(f7)]                  'split-window-horizontally)
(global-set-key (kbd "C-=")             'enlarge-window)
(global-set-key (kbd "C--")             'shrink-window)
(global-set-key (kbd "C-0")             'balance-windows)

;-------------------------------------------------------------------------------
; DISPLAY
;-------------------------------------------------------------------------------
(global-set-key (kbd "M-t")             'toggle-truncate-lines)

;-------------------------------------------------------------------------------
; Firefox-like tab manipulation
;-------------------------------------------------------------------------------

(global-set-key (kbd "C-w")    'ssarnoba-delete-tab)  ; Close tab (like Firefox)
(global-set-key (kbd "C-t")    'split-window-vertically); New tab (like Firefox)
(global-set-key (kbd "C-W")    'ssarnoba-delete-other-tab)    ; Close other tabs

; Close tab (like Firefox, and some Microsoft Windows windows)
;(global-set-key (kbd "C-w")             'delete-window)
;(global-set-key (kbd "C-W")             'delete-other-windows)

;-------------------------------------------------------------------------------
; Kill buffer without confirmation
;-------------------------------------------------------------------------------

; ADD THESE (problem - switch window is currently used by C-TAB and I 
; don't want to change it)
;(global-set-key (kbd "C-tab")             'cycle-buffer)         ; Like Firefox
;(global-set-key (kbd "C-w")             'delete-window)          ; Like Firefox
(global-set-key [f11]     'kill-current-buffer)

;(global-set-key "%" 'match-paren)
;(global-set-key (kbd "C-S")      'kill-other-buffer)
(global-set-key (kbd "<C-f12>")    'cycle-buffer-backward-permissive)

; page up key
(global-set-key (kbd "C-<prior>") 'cycle-buffer-backward-permissive)
(global-set-key (kbd "<C-f8>")     'unfix-shell)
(global-set-key (kbd "<C-tab>")    'cycle-buffer-permissive)
(global-set-key (kbd "M-S")      'kill-other-buffer)
(global-set-key (kbd "M-s")      'other-window)
(global-set-key (kbd "<Sh-C-tab>") 'cycle-buffer-backward-permissive)
(global-set-key [(f10)]          'other-window)
(global-set-key [(f12)]          'cycle-buffer-permissive)
(global-set-key (kbd "C-<next>") 'cycle-buffer-permissive)       ; page down key
(global-set-key [(f3)]           'clear-shell-buffer)
(global-set-key [(f8)]           'fix-shell)
;(global-set-key [(f10)]       'cycle-buffer)
;(global-set-key [(f9)]        'cycle-buffer-backward)

(global-set-key (kbd "M-d")         'ssarnoba-dirs)
(global-set-key (kbd "<M-return>")    'ssarnoba-dirs)

(global-set-key (kbd "M-g") 'ssarnoba-goto-line )

;-------------------------------------------------------------------------------
;
;-------------------------------------------------------------------------------
(global-set-key (kbd "M-r") 'cscope-find-this-symbol)
(global-set-key (kbd "M-d") 'cscope-find-global-definition-no-prompting)


;-------------------------------------------------------------------------------
;
; NAME
;   find-file-at-point
;
; DESCRIPTION
;   Open the file whose path is printed on the current line
;
;-------------------------------------------------------------------------------

(global-set-key (kbd "M-f") 'find-file-at-point)

;-------------------------------------------------------------------------------
;   Emacs Shift Mark
;-------------------------------------------------------------------------------

(global-set-key '(shift right)                'shift-mark-forward-char)
(global-set-key '(shift left)                 'shift-mark-backward-char)
(global-set-key '(shift up)                   'shift-mark-previous-line)
(global-set-key '(shift down)                 'shift-mark-next-line)
(global-set-key '(shift control right)        'shift-mark-forward-word)
(global-set-key '(shift control left)         'shift-mark-backward-word)
(global-set-key '(shift control up)           'shift-mark-backward-paragraph)
(global-set-key '(shift control down)         'shift-mark-forward-paragraph)
(global-set-key '(shift backspace)            'backspace-delete-marked-region)
;(global-set-key '(control backspace)          'backspace-delete-marked-region)
(global-set-key '(shift control backspace)    'backspace-delete-marked-region)
(global-set-key '(del)                        'backspace-delete-marked-region)
(global-set-key '(control left)               'backward-word)
(global-set-key '(control right)              'forward-word)
;(global-set-key '(control up)                 'backward-paragraph)
;(global-set-key '(control down)               'forward-paragraph)
(global-set-key '(f27)                        'beginning-of-line)         ; Home
(global-set-key '(f33)                        'end-of-line)                ; End
(global-set-key  (kbd "BS")                   'windows-backspace)

;===============================================================================
; Other Preferences
;===============================================================================

;-------------------------------------------------------------------------------
; Syntax highlighting
;-------------------------------------------------------------------------------

;(turn-on-font-lock)

; Turn on font-lock in all modes that support it
;(global-font-lock-mode t) File isn't successfully imported

(add-to-list 'auto-mode-alist '(".cfg"             . cperl-mode))
(add-to-list 'auto-mode-alist '(".pls"             . sql-mode))
(add-to-list 'auto-mode-alist '(".jpr"             . xml-mode))
(add-to-list 'auto-mode-alist '(".xcfg"            . xml-mode))
(add-to-list 'auto-mode-alist '(".jpx"             . xml-mode))
(add-to-list 'auto-mode-alist '(".xdf"             . xml-mode))
(add-to-list 'auto-mode-alist '(".table"           . xml-mode))
(add-to-list 'auto-mode-alist '(".view"            . xml-mode))
(add-to-list 'auto-mode-alist '(".twk"             . erin-mode))
(add-to-list 'auto-mode-alist '(".mwk"             . wikipedia-mode))
(add-to-list 'auto-mode-alist '(".aliases"         . shell-script-mode))
(add-to-list 'auto-mode-alist '(".aliases_public"  . shell-script-mode))
(add-to-list 'auto-mode-alist '(".aliases_oracle"  . shell-script-mode))
(add-to-list 'auto-mode-alist '(".cshrc"           . shell-script-mode))
(add-to-list 'auto-mode-alist '(".cshrc_oracle"    . shell-script-mode))
(add-to-list 'auto-mode-alist '(".cshrc_public"    . shell-script-mode))

;-------------------------------------------------------------------------------
; Use spaces instead of tabs
;-------------------------------------------------------------------------------
(setq-default indent-tabs-mode nil);   

;-------------------------------------------------------------------------------
; Calendar/Diary (from Bill's .emacs file)
;-------------------------------------------------------------------------------
(autoload 'display-time "time" nil t)
(display-time)

;-------------------------------------------------------------------------------
; Show line numbers and column numbers
;-------------------------------------------------------------------------------

(setq-default line-number-mode 1)
(setq-default column-number-mode 1)

;-------------------------------------------------------------------------------
; Highlight matching parenthesis () [] {} <> (depending on the mode)
;-------------------------------------------------------------------------------

(paren-activate)

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

(custom-set-variables
 '(truncate-lines t))

;-------------------------------------------------------------------------------
;; 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))

; use shell-script-mode for shell scripts

;-------------------------------------------------------------------------------
; Paste at text cursor, not where mouse pointer is.
;-------------------------------------------------------------------------------
(setq mouse-yank-at-point t)

;-------------------------------------------------------------------------------
;
; DESCRIPTION
;   Make the % key jump to the matching {}[]() if on another, like VI
;
; SOURCE
;   http://www.crsr.net/Notes/Emacs.html
;
;-------------------------------------------------------------------------------

; NOT USED

(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)))))

;-------------------------------------------------------------------------------
; NAME
;   Uncomment Region
;
; SOURCE
;   http://www.xemacs.org/Links/tutorials_2.html
;-------------------------------------------------------------------------------

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


;-------------------------------------------------------------------------------
; NAME
;   Comment Line
;
; SOURCE
;   http://icl.cs.utk.edu/~buttari/stuff/dotemacs.html
;
; DESCRIPTION
;   Comment line below the cursor
;-------------------------------------------------------------------------------

;; comment line below the cursos
(defun comment-line ()
    (interactive)
    (beginning-of-line)
    (setq st (point))
    (end-of-line)
    (setq en (point))
    (if (> en st)
       (comment-region st en))
    (next-line 1)
    )
;; uncomment line below the cursos
(defun uncomment-line ()
    (interactive)
    (beginning-of-line)
    (setq st (point))
    (end-of-line)
    (setq en (point))
    (if (> en st)
       (uncomment-region st en))
     (next-line 1)
    )

;-------------------------------------------------------------------------------
;
; NAME
;   Prepend string 
;
; DESCRIPTION
;   Add/remove a string in front of all lines in the region
;
; AUTHOR
;   Elijah Daniel
;
; SOURCE
;   http://www.dotemacs.de/dotfiles/ElijahDaniel.emacs.html
;-------------------------------------------------------------------------------

; UNUSED
; THIS CAN BE USED FOR C++ STYLE COMMENTS

; Add
(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
(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)))))

;-------------------------------------------------------------------------------
;
; NAME
;  Clear shell buffer
;
; AUTHOR
;   Sridhar Sarnobat
;
;-------------------------------------------------------------------------------

(defun clear-shell-buffer ()
  "Clears shell buffer"
  (interactive)
  (
   if (eq major-mode 'shell-mode) 
   (progn (beginning-of-buffer)        
          (set-mark-command nil)
          (end-of-buffer) 
          (delete-region (point) (mark))
   )
  )
)

;-------------------------------------------------------------------------------
;
; NAME
;   Kill other buffer
;
; AUTHOR
;   Sridhar Sarnobat
;
;-------------------------------------------------------------------------------

; This is particularly useful after a tab completion buffer which 
; doesn't close automatically

(defun kill-other-buffer (arg &optional all-frames)
 (interactive "p\nP")
 (save-excursion
   (other-window arg all-frames)
   (kill-this-buffer)
   (other-window arg all-frames))) 

;-------------------------------------------------------------------------------
; Buffer Toggling
;-------------------------------------------------------------------------------

; Quickly move through all buffers by pressing F12 (once per buffer 
; switch). To go backwards, press C-F12.

(autoload 'cycle-buffer "cycle-buffer" "Cycle forward." t)
(autoload 'cycle-buffer-backward "cycle-buffer" "Cycle backward." t)
(autoload 'cycle-buffer-permissive "cycle-buffer" 
  "Cycle forward allowing *buffers*." t)
(autoload 'cycle-buffer-backward-permissive "cycle-buffer" 
  "Cycle backward allowing *buffers*." t)
(autoload 'cycle-buffer-toggle-interesting "cycle-buffer" 
  "Toggle if this buffer will be considered." t)

;-------------------------------------------------------------------------------
;
; NAME
;   Remove shell double line spacing
;
; DESCRIPTION
;   Fix a shell where there is too much line spacing
;
; AUTHOR
;   Sridhar Sarnobat
;
;-------------------------------------------------------------------------------

; SSARNOBA: to automate this, it should be CALLED ONLY WHEN YOU 
; DO A TELNET OR A CHENV

; M-x customize-group comint ; gives more information
; f1-m - mode information (e.g. key bindings)
; set-variable comint-process-echoes t   
                            ; true. This eliminates the extra return
; set-variable comint-process-echoes nil 
                            ; This puts the extra carriage return in.

(defun unfix-shell ()
  "Clears shell buffer"
  (interactive)
  (
   if (eq major-mode 'shell-mode) 
   (progn 
     ( set-variable  'comint-process-echoes nil)
   )
  )
)

(defun fix-shell ()
  "Clears shell buffer"
  (interactive)
  (
   if (eq major-mode 'shell-mode) 
   (progn 
     ( set-variable  'comint-process-echoes t)
   )
  )
)

;-------------------------------------------------------------------------------
; In minibuffer, show remaining completions inline
;-------------------------------------------------------------------------------

(icomplete-mode)

;-------------------------------------------------------------------------------
; Don't wrap lines (this doesn't apply for java mode etc.)
;-------------------------------------------------------------------------------

(setq truncate-lines t)

;-------------------------------------------------------------------------------
; Replace yes-or-no question responses with y-or-n responses
;-------------------------------------------------------------------------------

(fset 'yes-or-no-p 'y-or-n-p)

;-------------------------------------------------------------------------------
; Command history size for shell
;-------------------------------------------------------------------------------

; Default "history" length is just 32, apparently! Jeez.
(setq comint-input-ring-size 2000)

;-------------------------------------------------------------------------------
; Indentation
;-------------------------------------------------------------------------------

(c-set-offset 'statement-block-intro 2)

;(setq standard-indent 2)

;-------------------------------------------------------------------------------
;  Line by line scrolling 
;-------------------------------------------------------------------------------

; This makes the buffer scroll by only a single line when the up or
; down cursor keys push the cursor (tool-bar-mode) outside the
; buffer. The standard emacs behaviour is to reposition the cursor in
; the center of the screen, but this can make the scrolling confusing

(setq scroll-step 1)

;-------------------------------------------------------------------------------
; Backup Files in Specific Directory
;-------------------------------------------------------------------------------
; THIS DOESN'T WORK

; Enable backup files.
;(setq make-backup-files t)

; Disable versioning with default values (when enabled, keeps five
; last versions, apparently)
;(setq version-control nil)

; Save all backup file in this directory.
(setq backup-directory-alist 
 (quote ((".*" . "/home/ssarnoba/trash/emacs_backups/"))))

;-------------------------------------------------------------------------------
; Before pasting, kill the currently highlighted selection
;-------------------------------------------------------------------------------

(delete-selection-mode)

;-------------------------------------------------------------------------------
; Emacs Startup
;-------------------------------------------------------------------------------

; Initial shells
;(shell)
;(rename-buffer "shell-buffer")
;(delete-other-windows)
;(rename-buffer "env-buffer")
;(shell)
;(rename-buffer "home-buffer")

(defun ssarnoba-dirs ()
  "Resync dirs, and move the cursor to the end of the partially typed command"
  (interactive)
  (dirs)
  (end-of-line)
  )

;-------------------------------------------------------------------------------
;
; NAME
;   Delete line
;
; DESCRIPTION
;   For some reason Emacs lacks delete-line, implementing it with the
;   source from kill-line is, however, trivial

; SORUCE
;   http://www.koders.com/lisp/
;   fid26FD7A9C679CB6829FF4DF7536F03121A3257D3C.aspx?s=Raman
;
;-------------------------------------------------------------------------------

(defun delete-line (&optional arg)
  "Delete the rest of the current line; if no nonblanks there, delete
thru newline. With prefix argument, delete that many lines from point.
Negative arguments delete lines backward.

When calling from a program, nil means \"no arg\", a number counts as
a prefix arg.

To delete a whole line, when point is not at the beginning, type \
\\[beginning-of-line] \\[delete-line] \\[delete-line].

If `kill-whole-line' is non-nil, then this command deletes the whole line
including its terminating newline, when used at the beginning of a line
with no argument.  As a consequence, you can always delete a whole line
by typing \\[beginning-of-line] \\[delete-line]."
  (interactive "P")
  (delete-region (point)
	       ;; It is better to move point to the other end of the
	       ;; delete before deleting. That way, in a read-only
	       ;; buffer, point moves across the text that is to be
	       ;; delete. The choice has no effect on undo now that
	       ;; undo records the value of point from before the
	       ;; command was run.
	       (progn
		 (if arg
		     (forward-visible-line (prefix-numeric-value arg))
		   (if (eobp)
		       (signal 'end-of-buffer nil))
		   (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
		       (forward-visible-line 1)
		     (end-of-visible-line)))
		 (point)
                 (delete-char)
)
))

(defun end-of-visible-line ()
  "Move to end of current visible line."
  (end-of-line)
  ;; If the following character is currently invisible,
  ;; skip all characters with that same `invisible' property value,
  ;; then find the next newline.
  (while (and (not (eobp))
	      (save-excursion
		(skip-chars-forward "^\n")
		(let ((prop
		       (get-char-property (point) 'invisible)))
		  (if (eq buffer-invisibility-spec t)
		      prop
		    (or (memq prop buffer-invisibility-spec)
			(assq prop buffer-invisibility-spec))))))
    (skip-chars-forward "^\n")
    (if (get-text-property (point) 'invisible)
	(goto-char (next-single-property-change (point) 'invisible))
      (goto-char (next-overlay-change (point))))
    (end-of-line)))

;-------------------------------------------------------------------------------
;
; NAME
;   PL/SQL Goto line
;
; AUTHOR
;   Aaditya Sood
;
; SOURCE
;   http://www.emacswiki.org/cgi-bin/emacs-zh/AadityaSood
;
;-------------------------------------------------------------------------------

(defun plsql-goto-line (arg)
  "Goto line ARG, after adding the pl/sql offset to it
   Check on which line the create or replace package starts (the offset) and 
   jump to line number ARG + offset"
  (interactive "NGoto PL/SQL line: ")
  (push-mark)
  (goto-line (+ (- arg 1) 
		(save-excursion
		  (goto-char (point-min))
		  (search-forward-regexp "create *or *replace" (point-max) t)
		  (count-lines (point) (point-min))))))

(defun ssarnoba-goto-line (num)
 (interactive "NGoto line: ")
  (
   if (eq major-mode 'sql-mode)
   (progn 
    (plsql-goto-line num)
   )
   (progn 
    (goto-line num)
   )
  )
)

(defun ssarnoba-test () "insert \"Yay!\" at point." (interactive) (message "Yay!"))

;-------------------------------------------------------------------------------
;
; NAME
;   Delete Word
;
; DESCRIPTION
;   Delete words without copying them to the clipboard
;
; AUTHOR
;   Rob Walker
;
; SOURCE
;   http://www.tenfoot.org.uk/emacs/snippets.html
;
;-------------------------------------------------------------------------------

(defun delete-word (arg)
  "Kill characters forward until encountering the end of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-region (point) (progn (forward-word arg) (point))))

(defun backward-delete-word (arg)
  "Kill characters backward until encountering the beginning of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-word (- arg)))

;-------------------------------------------------------------------------------
;
; NAME
;   Align equals
;
; SOURCE
;   http://www.dotemacs.de/dotfiles/JavierOviedo.emacs.html
;
;-------------------------------------------------------------------------------

;; The following little lump of lisp will ensure the first assignment operators
;; on each of the lines line up. This is part of our local formatting style
;; 'cos it looks nice ;-)
;; The style of the lisp however, is atrocious. All the problems come from ==,
;; which looks too much like 'op='.
;; Paul Hudson

(defun align-equals (start end)
  "Make the first assignment operator on each line line up vertically"
  (interactive "*r")
  (save-excursion
    (let ((indent 0))
      (narrow-to-region start end)
      (beginning-of-buffer)
      (while (not (eobp))
        (if (find-assignment)
            (progn
              (exchange-point-and-mark)
              (setq indent (max indent (current-column)))
              (delete-horizontal-space)
              (insert " ")))
        (forward-line 1))
      (beginning-of-buffer)
      (while (not (eobp))
        (if (find-assignment)
            (indent-to-column (1+ (- indent  (- (mark) (point))))))
        (forward-line 1)))
   (widen)))

;;
;; Find an assignment statement
;;
(defun find-assignment ()
  (if (re-search-forward
	     "[^<>=!]=\\|\\+=\\|-=\\|\\*=\\|/=\\|&=\\||=\\|\\^=\\|<<=\\|>>="
	     (save-excursion (end-of-line) (point)) t)
      (progn
	(goto-char (match-beginning 0))
	(if (looking-at ".==")
	    nil
	  (if (looking-at "\\+=\\|:=\\|-=\\|\\*=\\|/=\\|&=\\||=\\|\\^=\\|<<=\\|>>=")
	      (set-mark (match-end 0))
	    (forward-char 1)
	    (set-mark (1+ (point))))
	  (delete-horizontal-space)
	  t))
    nil))

;-------------------------------------------------------------------------------
; SOURCE
;   http://www.emacswiki.org/cgi-bin/wiki/EmacsNiftyTricks
;-------------------------------------------------------------------------------

(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
  "Prevent annoying \"Active processes exist\" query when you quit Emacs."
  (flet ((process-list ())) ad-do-it))

;-------------------------------------------------------------------------------
; DESCRIPTION
;   Fontifying foo.cc... buffer too big aborted
;
; SOURCE
;   http://calypso.tux.org/pipermail/xemacs-beta/2008-July/014672.html
;-------------------------------------------------------------------------------

(setq font-lock-maximum-size 2000000)

;===============================================================================
; Written by Sridhar Sarnobat
;===============================================================================

(defun comment-line-or-region ()
  "Acts as Windows backspace: delete region if one exists; else delete previous character."
  (interactive)2
  (if (region-active-p) 
   (comment-region (point) (mark))
   (comment-line))
)


(defun uncomment-line-or-region ()
  "Acts as Windows backspace: delete region if one exists; else delete previous character."
  (interactive)2
  (if (region-active-p) 
   (uncomment-region (point) (mark))
   (uncomment-line))
)
Personal tools