Tuesday, April 20, 2010

My .emacs file (dot emacs) - Emacs Configuration File

;;; Wrapper to make .emacs self-compiling.
(defvar init-top-level t)
(if init-top-level

;; ============================
;; Setup syntax, background, and foreground coloring
;; ============================

(set-background-color "Black")
(set-foreground-color "White")
(set-cursor-color "LightSkyBlue")
(set-mouse-color "LightSkyBlue")
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)

;; User Information
(setq user-full-name "Karthikeyan Periasamy")
(setq user-mail-address "karthikeyan.periasamy@adckrone.com")

;; Tab using spaces
(setq-default indent-tabs-mode nil)

;; ============================
;; Key mappings
;; ============================
(global-set-key [delete] 'delete-char)
(global-set-key [backspace] 'delete-backward-char)

;;; Key binding for sqitching to next and previous buffer
(global-set-key '[C-tab] 'bs-cycle-next) 

;; use F1 key to go to a man page
(global-set-key [f1] 'man)
;; use F2 to save current buffer
(global-set-key [f2] 'save-buffer)
;; use shift+F2 to save current buffer to other file - "Save As"
(global-set-key [(shift f2)] 'write-file)
;; use F3 to check spelling
(global-set-key [f3] 'ispell-word)
;; use F4 key to kill current buffer
(global-set-key [f4] 'kill-this-buffer)
;; use F5 to compile
(global-set-key [f5] 'compile)
;; use F6 to change file mode to hexl
(global-set-key [f6] 'hexl-mode)
;; use F7 to open files in hex mode
(global-set-key [f7] 'hexl-mode-exit)
;; Now bind the delete line function to the F8 key
(global-set-key [f8] 'nuke-line)
;; use F9 to open files in hex mode
(global-set-key [f9] 'hexl-find-file)
;; use F10 to get help (apropos)
(global-set-key [f10] 'apropos)

;; goto line function C-c C-g
(global-set-key [ (control c) (control g) ] 'goto-line)

;; undo and redo functionality with special module
(require 'redo)
(global-set-key (kbd "C-+") 'redo)

;; keys for buffer creation and navigation
(global-set-key [(control x) (control b)] 'iswitchb-buffer)

;; Backup directory to store all files which end with "~"
;; Enable backup files.
(setq make-backup-files t)

;; Enable versioning with default values (keep five last versions, I think!)
(setq version-control t)

;; Save all backup file in this directory.
(setq backup-directory-alist (quote ((".*" . "~/.emacs.d/backups/"))))

;; Set standard indent to 2
(setq standard-indent 2)

;; ============================
;; Mouse Settings
;; ============================

;; mouse button one drags the scroll bar
(global-set-key [vertical-scroll-bar down-mouse-1] 'scroll-bar-drag)

;; setup scroll mouse settings
(defun up-slightly () (interactive) (scroll-up 5))
(defun down-slightly () (interactive) (scroll-down 5))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)

(defun up-one () (interactive) (scroll-up 1))
(defun down-one () (interactive) (scroll-down 1))
(global-set-key [S-mouse-4] 'down-one)
(global-set-key [S-mouse-5] 'up-one)

(defun up-a-lot () (interactive) (scroll-up))
(defun down-a-lot () (interactive) (scroll-down))
(global-set-key [C-mouse-4] 'down-a-lot)
(global-set-key [C-mouse-5] 'up-a-lot)

;; setup font

;; No startup screen, if called with file name
;;(setq inhibit-startup-message t)

;; display the current time
(setq display-time-day-and-date t)

;; Show column number at bottom of screen
(setq column-number-mode 1)

;; show a menu only when running within X (save real estate when
;; in console)
;;(menu-bar-mode (if window-system 1 -1))
(menu-bar-mode nil)

;; alias y to yes and n to no
(defalias 'yes-or-no-p 'y-or-n-p)

;; Set the file end-of-line conversion type of the current buffer to Unix
;;(setq buffer-file-coding-system (coding-system-change-eol-conversion
;;                                 buffer-file-coding-system 'unix))

(set-buffer-modified-p t)

;; ===========================
;; Behaviour
;; ===========================

;; Pgup/dn will return exactly to the starting point.
(setq scroll-preserve-screen-position 1)

;; don't automatically add new lines when scrolling down at
;; the bottom of a buffer
(setq next-line-add-newlines nil)

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

;; format the title-bar to always include the buffer name
;;(setq frame-title-format "emacs : %b : "(replace-regexp-in-string "\\([\.]\\)" "_" buffer-file-nam)"")
;;(setq frame-title-format "emacs : %b : %f")
;;(setq frame-title-format '(buffer-file-name "%f" ("%b")))
(setq frame-title-format
   '("Emacs : " (buffer-file-name "%f" (dired-directory dired-directory "%b"))))

;; hide the scroll bar
(scroll-bar-mode nil)

;; turn off the toolbar
(if (>= emacs-major-version 21)
    (tool-bar-mode -1))

;; turn on word wrapping in text mode
;;(add-hook 'text-mode-hook 'turn-on-auto-fill)

;; replace highlighted text with what I type rather than just
;; inserting at a point
(delete-selection-mode t)

;; resize the mini-buffer when necessary
(setq resize-minibuffer-mode t)

;; highlight during searching
(setq query-replace-highlight t)

;; highlight incremental search
(setq search-highlight t)

;; Enable uppercase or lowercase conversions
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)

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

;; ===========================
;; Buffer Navigation
;; ============================

;; Iswitchb is much nicer for inter-buffer navigation.
(cond ((fboundp 'iswitchb-mode)                ; GNU Emacs 21
       (iswitchb-mode 1))
      ((fboundp 'iswitchb-default-keybindings) ; Old-style activation
      (t nil))                                 ; Oh well.

(require 'cmssw-mode)

;; ======
;; C/C++ 
;; ======
(defun my-c-mode-common-hook ()
  (c-set-offset 'substatement-open 0)
  (c-set-offset 'case-label '+)
;;  (c-set-offset 'arglist-cont-nonempty c-lineup-arglist)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

;; ============================
;; Set up which modes to use for which file extensions
;; ============================
(setq auto-mode-alist
         ("\\.h$"             . c++-mode)
         ("\\.dps$"           . pascal-mode)
         ("\\.py$"            . python-mode)
         ("\\.Xdefaults$"     . xrdb-mode)
         ("\\.Xenvironment$"  . xrdb-mode)
         ("\\.Xresources$"    . xrdb-mode)
         ("\\.tei$"           . xml-mode)
         ("\\.php$"           . php-mode)
         ) auto-mode-alist))

;; delete a line
;; First define a variable which will store the previous column position
(defvar previous-column nil "Save the column position")

;; 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.
(defun nuke-line()
  "Kill an entire line, including the trailing newline character"

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

  ;; 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.
      (delete-char 1)
      (move-to-column previous-column))))

;; Diasble \C-t
(global-unset-key "\C-t")
(global-set-key "\C-t\C-a" 'c-indent-buffer)

;; indent the entire buffer
(defun c-indent-buffer ()
  "Indent entire buffer of C source code."
    (goto-char (point-min))
    (while (< (point) (point-max))
      (forward-char 1))))

;; set up the compiling options
(setq compile-command "make"
      compilation-ask-about-save nil
      compilation-window-height 10)

You have to install some el files.

No comments :

Post a Comment