mwnnlin's dot emacs

Dot Emacs

;; Author: mwnn (mwnnlin@gmail.com)
;; Last edited: 16-Jan-2011

;; Start the emacs server only if another instance of the server is not running.
(require 'server)
(if (eq (server-running-p server-name) nil)
    (server-start))

;; Miscellaneous features
(setq x-select-enable-clipboard t
      display-time-day-and-date t
      mouse-avoidance-mode 3
      ;blink-cursor-mode nil
      column-number-mode t
      dired-listing-switches "-lh"
      display-time-mode t
      grep-command "grep -RniI "
      list-directory-brief-switches "-CFh"
      list-directory-verbose-switches "-lh"
      scroll-bar-mode nil
      require-final-newline t
      find-name-arg "-iname"
      global-font-lock-mode t
      font-lock-maximum-decoration t)
(blink-cursor-mode t)
(show-paren-mode t)

;; Format string used to construct the WINDOW TITLE string.
(setq frame-title-format "emacs-%b")
(setq scroll-conservatively 2)

(if (eq window-system 'x)
    (progn
      (if (file-exists-p "~/software/emacs_extras/tango-dark-theme.el")
          (progn
            (add-to-list 'load-path "~/software/emacs_extras/")
            (require 'tango-dark-theme)))))

;; C mode customizations
(add-hook 'c-mode-common-hook
          (lambda ()
            (define-key c-mode-base-map
              (kbd "RET") 'c-context-line-break)))

;; Using linux kernel coding style.
(add-hook 'c-mode-common-hook
          (lambda ()
            (c-set-style "linux")))

(add-hook 'c-mode-hook
         '(lambda ()
            (c-toggle-hungry-state)))

;;(setq c-auto-newline t)

(defun mwnn-c-compile (filename)
  (interactive "bFile name: ")
  (setq compile-command
        (message "cc -g -O2 -Wall %s -o%s"
                 filename (substring filename 0 -2)))
  (compile compile-command))
(global-set-key [(f9)] 'mwnn-c-compile)

;; Cscope
(if (file-exists-p "~/software/emacs_extras/xcscope.el")
    (progn
      (add-to-list 'load-path "~/software/emacs_extras/")
      (require 'xcscope)))

(if (file-exists-p "~/software/emacs_extras/rfcview.el")
    (progn
      (add-to-list 'load-path "~/software/emacs_extras/")
      (require 'rfcview)))

;;A trivial yet useful trick: when coding C/C++, you often jump from
;;header file (.h, .hh etc.) to implementation file (.c, .cc
;;etc.). Emacs has built-in support for this, using
;;ff-find-other-file. We can add a key binding to .emacs:
(add-hook 'c-mode-common-hook
          (lambda()
            (local-set-key  (kbd "C-c o") 'ff-find-other-file)))

;; Highlight FIXME, TODO and BUG keywords
(add-hook 'c-mode-common-hook
          (lambda ()
            (font-lock-add-keywords
             nil '(("\\<\\(FIXME\\|TODO\\|BUG\\):" 1 font-lock-warning-face t)))))

;; Show trailing whitespace in a C source file.
(add-hook 'c-mode-hook
          (lambda()
            (setq show-trailing-whitespace t)))

;; Show trailing whitespace in a Makefile.
(add-hook 'makefile-mode-hook
          (lambda()
            (setq show-trailing-whitespace t)))


;; Creates TAGS file
(defun mwnn-create-tags (src-dir)
  (interactive "DSource directory: ")
  (if (file-exists-p src-dir)
      (let (cmd-str)
        (setq cmd-str
              (format
               "rm  %s"
               (concat src-dir "/TAGS")))
        (shell-command cmd-str)
        (setq cmd-str
              (format
               "ctags -R -e %s -o %s"
               src-dir (concat src-dir "/TAGS")))
        (message "Creating %s" cmd-str)
        (shell-command cmd-str)
        (message "TAGS created!"))
    (message "Invalid directory")))

;; Auto complete
(if (file-exists-p "~/software/emacs_extras/auto-complete-1.3")
    (progn
      (add-to-list 'load-path "~/software/emacs_extras/auto-complete-1.3")
      (require 'auto-complete)
      (global-auto-complete-mode t)))

;; Python settings.
;; (require 'pymacs)
;; (pymacs-load "ropemacs" "rope-")

;; LISP settings
(add-hook 'lisp-mode-hook
          '(lambda () (local-set-key (kbd "RET") 'newline-and-indent)))

(add-hook 'emacs-lisp-mode-hook
          '(lambda () (local-set-key (kbd "RET") 'newline-and-indent)))

(define-key global-map (kbd "RET") 'newline-and-indent)

;; Nuke trailing whitespace when saving a file.
(add-hook 'write-file-functions 'delete-trailing-whitespace)

;; Highlight lines longer than 80 columns
(setq whitespace-line-column 80
      whitespace-style '(trailing lines-tail))

(add-hook 'c-mode-hook 'whitespace-mode)
(add-hook 'python-mode 'whitespace-mode)


(setq dired-isearch-filenames t)
(display-time)
(global-set-key [f4] 'rename-buffer)
(global-set-key [f3] 'shell)
(global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word))))

;(tool-bar-mode nil)
;(menu-bar-mode nil)
(mouse-avoidance-mode 'animate)
(fset 'yes-or-no-p 'y-or-n-p)

;; Org-mode configuration. (Taken from the info file for org-mode)
;; We do not associate *.txt files with org-mode. Instead we write the org file
;; first and later export it into an ascii(*.txt) file.
(add-to-list 'load-path "~/software/emacs_extras/org-7.3/lisp/")
(add-to-list 'load-path "~/software/emacs_extras/org-7.3/contrib/lisp/")
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
;; Disable subscripting when two words are separated using underscores.
(setq org-export-with-sub-superscripts nil)
(setq org-hide-leading-stars t)
(setq org-clock-persist t)
(setq org-startup-align-all-tables t)
(setq org-enforce-todo-dependencies t)
(setq org-agenda-dim-blocked-tasks t)
(setq org-hierarchical-todo-statistics nil)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)

(setq org-directory "~/.gtd")
(setq org-mobile-directory "~/Dropbox/MobileOrg")
(setq org-mobile-inbox-for-pull "~/.gtd/basket.org")

;; Open gtd file
(defun gtd()
  (interactive)
  (let ((gtd-file "/home/mwnn/.gtd/gtd.org"))
    (if (file-exists-p gtd-file)
        (find-file gtd-file)
      (message "%s: Does not exist" gtd-file))))
(setq org-agenda-files (list "/home/mwnn/.gtd/gtd.org"))

;; Open command.org file
(defun command()
  (interactive)
  (let ((command-file "/media/FreeAgent Drive/document/blog_posts/commands.org"))
    (if (file-exists-p command-file)
        (find-file command-file)
      (message "%s: Does not exist" command-file))))

;; emms configuration
(if (file-exists-p "~/software/emacs_extras/emms-3.0/")
    (progn
      (add-to-list 'load-path "~/software/emacs_extras/emms-3.0/")
      (require 'emms-setup)
      (require 'emms-mode-line)
      (emms-mode-line 1)
      (require 'emms-playing-time)
      (emms-playing-time nil)
      (emms-standard)
      (emms-default-players)
      ;; Show the current track each time EMMS
      ;; starts to play a track with "NP : "
      (add-hook 'emms-player-started-hook 'emms-show)
      (setq emms-show-format "NP: %s")
      (setq emms-player-mpg321-command-name "mplayer")
      (setq emms-player-mpg321-parameters (quote ("-quiet" "-really-quiet" "-slave")))
      (setq emms-player-mplayer-parameters (quote ("-slave" "-quiet" "-really-quiet")))
      (setq emms-player-ogg123-command-name "mplayer")
      (setq emms-player-ogg123-parameters (quote ("-quiet" "-really-quiet" "-slave")))
      ;; When asked for emms-play-directory,
      ;; always start from this one
      ;;(setq emms-source-file-default-directory "~/music/")
      (global-set-key (kbd "C-c e p") 'emms-pause)
      (global-set-key (kbd "C-c e <up>") 'emms-start)
      (global-set-key (kbd "C-c e <down>") 'emms-stop)
      (global-set-key (kbd "C-c e <left>") 'emms-previous)
      (global-set-key (kbd "C-c e <right>") 'emms-next)
      (global-set-key (kbd "C-c e a") 'emms-add-dired)
      (global-set-key (kbd "C-c e <RET>") 'emms-play-dired)
      (global-set-key (kbd "C-c e r") 'emms-toggle-repeat-playlist)
      (global-set-key (kbd "C-c e t") 'emms-toggle-repeat-track)
      (global-set-key (kbd "C-c e t") 'emms-playlist-clear)
      (global-set-key [f5] 'emms)))

;; Configuration for editing text files.
(add-hook 'text-mode-hook
  (lambda()
    (set-fill-column 78)   ; buffer-local variable; wrap at col 78
    (auto-fill-mode t)))   ; wrap around automagically

;; Gtalk configuration
(if (file-exists-p "~/software/emacs_extras/emacs-jabber-0.8.0")
    (progn
      (add-to-list `load-path "~/software/emacs_extras/emacs-jabber-0.8.0")
      (require 'jabber)
      (setq jabber-connection-type (quote ssl))
      (setq jabber-network-server "talk.google.com")
      (setq jabber-nickname "chandanlinster")
      (setq jabber-port 5223)
      (setq jabber-resource "HOME")
      (setq jabber-server "gmail.com")
      (setq jabber-username "chandanlinster")
      (jabber-mode-line-mode)
      (setq jabber-default-status "Gifted; But flawed!")
      (custom-set-variables
       ;; custom-set-variables was added by Custom.
       ;; If you edit it by hand, you could mess it up, so be careful.
       ;; Your init file should contain only one such instance.
       ;; If there is more than one, they won't work right.
       '(jabber-account-list (quote (("chandanlinster@gmail.com" (:network-server . "talk.google.com") (:port . 5223) (:connection-type . ssl))))))))

;; Switch to jabber buffer.
(defun jabber()
  (interactive)
  (switch-to-buffer "*-jabber-roster-*"))

;; Switch to a particular buddy's buffer
(defun jabber-buddy (buddy)
  (interactive "sEnter buddy name: ")
  (let ((buffer-names (mapcar 'buffer-name (buffer-list)))
        (tmp-buffer-name nil))
    (while (not (eq buffer-names ()))
      (setq tmp-buffer-name (car buffer-names))
      (if (eq (string-match buddy tmp-buffer-name) nil)
          (setq buffer-names (cdr buffer-names))
        (progn
          (setq buffer-names nil)
          (switch-to-buffer tmp-buffer-name))))))
(global-set-key [f12] 'jabber-buddy)

;; Use SSH as the default method for remote access
(setq tramp-default-method "ssh")

;; Enable iswitch-mode
(iswitchb-mode t)
;; Make ibuffer the default
(global-set-key (kbd "C-x C-b") 'ibuffer)

;; Convert CR-LF to LF
(defun mwnn-dos-to-unix (file-path)
  (interactive "fFile name: ")
  (save-excursion
    (let (dos-buffer)
      (setq dos-buffer (find-file file-path))
      (set-buffer-file-coding-system 'unix)
      (save-buffer)
      (kill-buffer dos-buffer))))

;; Convert LF to CR-LF
(defun mwnn-unix-to-dos (file-path)
  (interactive "fFile name: ")
  (save-excursion
    (let (unix-buffer)
      (setq unix-buffer (find-file file-path))
      (set-buffer-file-coding-system 'dos)
      (save-buffer)
      (kill-buffer unix-buffer))))

;; VC backend
(setq vc-git-diff-switches "-b")
(setq vc-diff-switches "-b")

;; Disable the scroll bar
(menu-bar-no-scroll-bar)

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

(set-default 'truncate-lines t)

(setq backup-directory-alist '((".*" . "/home/mwnn/.emacs.d/")))

;; Use opera as the browser of choice.
(setq browse-url-firefox-program "opera")

;; Get back your delicately configured emacs windows
(winner-mode 1)

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

;; Interpret backspace character correctly
(if (not (eq window-system 'x))
    (global-set-key "\C-h" 'backward-delete-char))

;; (setq flymake-buildfile-dirs "/home/mwnn/projects/eDVA/src/prov/prov_db")
(setq flymake-buildfile-dirs (list "./" "../"))

(setq org-export-htmlize-output-type 'css)

(setq initial-major-mode 'org-mode)

;; file-paragraph (bound to M-q)
;; To get info on a particular mode use the command C-h m


;;Emacs recognizes many files already, but sometimes, you need to tell
;;it to use some specific mode for a file. To do this, there is
;;auto-mode-alist. Suppose, we want to use text-mode for all files with
;;extension .foo or .bar; we add to our .emacs:
;;(add-to-list 'auto-mode-alist
;;        '("\\.foo$\\|.bar$" . text-mode))

;; To display line number use "M-x linum"

;; To learn about key bindings or existing key bindings use the
;; following: C-h b (describe-bindings) and C-h k (describe-key)

;; To change the color of a particular token (e.g string, comments, ...)
;; 1. Place the point over the token.
;; 2. Use the command M-x customize-face to change the color value assigned.

;;To display colors execute the following command.
;;list-colors-display

;Use M-x send-invisible to enter passwords.

;; Highlight the current line.
;; (global-hl-line-mode t)

;; To edit a file in hexadecimal mode use the following command.
;; M-x hexl-mode

;; To check out the cvs status use the following command.
;; M-x cvs-status

;; Align variable and symbolic constant definitions
;; Select the list of variables (or symoblic constants)
;; and execute the command align-regexp on the selected
;; region

;; Save minibuffer history
;;(savehist-mode)

;; Easy buffer switching by holding down shift and press any arrow key.
;; (windmove-default-keybindings 'shift)


;; Use control-arrow keys for window resizing
(global-set-key (kbd "<C-right>") 'enlarge-window-horizontally)
(global-set-key (kbd "<C-left>") 'shrink-window-horizontally)


;; Show a marker in the left fringe for lines not in the buffer
;; (setq default-indicate-empty-lines t)


;; Use system trash (for emacs 23)
;; (setq delete-by-moving-to-trash nil)

;; M-i inserts a new tab.

;; proced is a new process editor mode.

;; To convert spaces to tabs use M-x tabify.
;; To convert tabs to spaces use M-x untabify.

;; The emacs interface commands for find and grep utilities are
;; find-name-dired and find-grep-dired.

;; Replace spaces with tabs using M-x tabify.
;; Replace tabs with spaces using M-x untabify.


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

(setq browse-url-browser-function 'browse-url-default-browser)
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(diff-added ((t (:foreground "#73d216"))) t)
 '(diff-removed ((t (:foreground "salmon"))) t)
 '(jabber-chat-prompt-foreign ((t (:foreground "#8cc4ff" :weight bold))))
 '(jabber-chat-prompt-local ((t (:foreground "#e9b96e" :weight bold))))
 '(jabber-roster-user-away ((t (:foreground "light green" :slant italic :weight normal))))
 '(jabber-roster-user-dnd ((t (:foreground "salmon" :slant italic :weight normal))))
 '(jabber-roster-user-online ((t (:foreground "#8cc4ff" :slant normal :weight bold)))))

HTML generated by org-mode 7.3 in emacs 23