;; ---------------------------------------- ;; General Emacs preferences ;; ---------------------------------------- ;;(setq load-path (nconc (list "/job/SWDEVL/3PS/img/linux.odd/emacs-21.4/site-lisp") load-path )) ;;(setq load-path (cons (concat (getenv "JOBDRIVE") "/job/HOME/nzafar/lib/cedet-1.0pre2/") load-path)) (setq default-major-mode 'indented-text-mode) (setq inhibit-startup-message t) (setq display-time-day-and-date t) (setq vc-make-backup-files t) (setq read-file-name-completion-ignore-case t) (show-paren-mode t) (setq scroll-preserve-screen-position t) (setq scroll-step 1) (setq scroll-conservatively 5) ;; Always display the name of my current file (setq frame-title-format "%b") ;; ---------------------------------------- ;; -- KEY BINDINGS ;; ---------------------------------------- ;; Set up the keyboard so the delete key on both the regular keyboard ;; and the keypad delete the character under the cursor and to the right ;; under X, instead of the default, backspace behavior. (global-set-key [?\C-h] 'delete-backward-char) (global-set-key [delete] 'delete-char) (global-set-key [kp-delete] 'delete-char) ;; Switch keybinding for C-h to C-x h (global-set-key "\C-xh" 'help-command) (global-set-key [down-S-mouse-1] 'mouse-buffer-menu) (global-set-key [f5] 'grep) (global-set-key [C-return] 'complete ) (global-set-key [M-return] 'complete ) (global-set-key "\M-g" 'goto-line) (global-set-key "\M-:" 'goto-line) (global-set-key "\M-o" 'other-window) (global-set-key [f12] 'switch-to-buffer) ;; ---------------------------------------- ;; -- Bookmark navigation ;; ---------------------------------------- ;; taken from: http://anthonyf.wordpress.com/2007/01/16/easy-bookmarks-in-emacs/ (require 'cl) (require 'bookmark) (defvar af-current-bookmark nil) (defvar nb-bm-hopdir 1) (defun af-bookmark-make-name () "makes a bookmark name from the buffer name and cursor position" (concat (buffer-file-name) " - " (number-to-string (point)) ) ) (defun af-bookmark-toggle () "remove a bookmark if it exists, create one if it doesnt exist" (interactive) (let ((bm-name (af-bookmark-make-name))) (if (bookmark-get-bookmark bm-name) (progn (bookmark-delete bm-name) (message "bookmark removed")) (progn (bookmark-set bm-name) (setf af-current-bookmark bm-name) (setq nb-bm-hopdir 1) (message "bookmark set"))))) (defun af-bookmark-cycle (i) "Cycle through bookmarks by i. 'i' should be 1 or -1" (if bookmark-alist (progn (unless af-current-bookmark (setf af-current-bookmark (first (first bookmark-alist)))) (let ((cur-bm (assoc af-current-bookmark bookmark-alist))) (setf af-current-bookmark (if cur-bm (first (nth (mod (+ i (position cur-bm bookmark-alist)) (length bookmark-alist)) bookmark-alist)) (first (first bookmark-alist)))) (bookmark-jump af-current-bookmark) ;; Update the position and name of the bookmark. We ;; only need to do this when the bookmark has changed ;; position, but lets go ahead and do it all the time ;; anyway. (bookmark-set-position af-current-bookmark (point)) (let ((new-name (af-bookmark-make-name))) (bookmark-set-name af-current-bookmark new-name) (setf af-current-bookmark new-name)))) (message "There are no bookmarks set!"))) (defun af-bookmark-cycle-forward () "find the next bookmark in the bookmark-alist" (interactive) (af-bookmark-cycle 1)) (defun af-bookmark-cycle-reverse () "find the next bookmark in the bookmark-alist" (interactive) (af-bookmark-cycle -1)) (defun af-bookmark-clear-all() "clears all bookmarks" (interactive) (setf bookmark-alist nil)) (defun nb-bm-hopmark() (interactive) (af-bookmark-cycle nb-bm-hopdir) (setq nb-bm-hopdir (* nb-bm-hopdir -1)) ) (fset 'last-bookmark [?\C-x ?r ?b return]) (global-set-key [f7] 'af-bookmark-toggle) ;; toggles a bookmark ;(global-set-key [f8] 'nb-bm-hopmark) ;(global-set-key [f8] 'af-bookmark-cycle-forward) (global-set-key [f8] 'last-bookmark) (global-set-key [(control f7)] 'af-bookmark-cycle-reverse) (global-set-key [(control f8)] 'af-bookmark-cycle-forward) (setq bookmark-save-flag nil) ;; ---------------------------------------- ;; ---------------------------------------- ;(load-library "z:/job/HOME/nzafar/elisp/psvn.elc") ;(load-library "//dd/home/nzafar/elisp/psvn.elc") (if (eq (getenv "JS_VERSION") nil) nil (load-library (concat (getenv "JOBDRIVE") "/job/HOME/nafees/lib/elisp/psvn-v33557.el") ) ) ;; automatically indent after a return (defun autoindent () (global-set-key "\C-m" 'newline-and-indent)) ;; emacs on PowerBooks has trouble with return key. (if (eq system-type 'darwin) (cons (define-key function-key-map [return] [13]) (tool-bar-mode nil) ) (tool-bar-mode nil) ) ;; ---------------------------------------- ;; -- File Type Environment Settings ;; ---------------------------------------- ;; Personal options for text mode (add-hook 'text-mode-hook 'text-file-handle) (defun text-file-handle () (turn-on-auto-fill) (set-fill-column 80)) ;; Load the appropriate interaction-mode for given source file extensions (setq auto-mode-alist (append '(("\\.pl$" . perl-mode) ("\\.perl$" . perl-mode) ("\\.txt$" . text-mode) ("\\.doc$" . text-mode) ("\\.html$" . html-mode) ("\\.java$" . java-mode) ("\\.nqc$" . c++-mode) ("\\.C$" . c++-mode) ("\\.cpp$" . c++-mode) ("\\.H$" . c++-mode) ("\\.h$" . c++-mode) ("\\.hpp$" . c++-mode) ("\\.cfx$" . c++-mode) ("\\.cfi$" . c++-mode) ("\\.cg$" . c++-mode) ("\\.cgfx$" . c++-mode) ("\\.vp$" . c++-mode) ; vertex shader ("\\.fp$" . c++-mode) ; fragment shader ("\\.env$" . shell-script-mode) ) auto-mode-alist)) (global-font-lock-mode 1) (transient-mark-mode 1) (font-lock-mode 1) (column-number-mode 1) (makunbound 'c++-mode) (makunbound 'c++-mode-map) (makunbound 'c-style-alist) (fset 'grep-in-code [escape ?w f5 ?" ?\C-y ?" ? ?* ?. ?h ? ?* ?. ?H ? ?* ?. ?c ? ?* ?. ?C ? ?* ?. ?c?p?p ? ?* ?. ?c?c ? ?* ?. ?h?p?p return]) ;; ;; Use C-c C-v in c-mode to do a compile (setq compile-command "make ") (defun my-save-and-compile () (interactive "") (save-buffer 0) (compile "make ")) (global-set-key "\C-c\C-v" 'my-save-and-compile) (global-set-key [f9] 'compile) ;; ;; Set an an explicit tab stop (defun set-tab-here () (interactive "") (setq tab-stop-list (cons (current-column) nil ) ) ) ;; ;; Hop between matching parens (defun match-paren (arg) "Go to the matching paren if on a paren; otherwise insert %." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (error "%s" "Not on a paren")) )) ;; ;; align with the preceding '=' in a statement (defun c++-lineup-statement-cont (langelem) (save-excursion (goto-char (cdr langelem)) (c-syntactic-re-search-forward c-assignment-op-regexp (min endpos (c-point 'eol)) t t t) (goto-char (+ (match-beginning 0) 2)) (vector (current-column))));; Generic option for all programming environs ;; ;; IDE tab and indentation settings. ;; http://cc-mode.sourceforge.net/html-manual/Syntactic-Symbols.html ;; ;; The settings are basically stroustrup mode, but a few differences (defun nb-ide-tabsets-personal () (setq indent-tabs-mode nil) (setq tab-width 4) (setq c-basic-offset tab-width) (c-set-offset 'statement-block-intro '+) (c-set-offset 'defun-block-intro '+) (c-set-offset 'substatement '+) (c-set-offset 'substatement-open 'c-indent-one-line-block) (c-set-offset 'brace-list-open 2) ;; enum \n { ... (c-set-offset 'innamespace 2) ;; namespace ... { (c-set-offset 'access-label -2) ;; public/private/protected (c-set-offset 'case-label +2) ;; switch (...) { label: (c-set-offset 'statement-case-open 0) (c-set-offset 'statement-cont 'c-lineup-math) (c-set-offset 'inline-open +2) ; (setq special-display-buffer-names '("*compilation*" "*grep*")) ;; display in a separate frame ) ;; DD preferred mode (defun nb-ide-tabsets-dd () (setq indent-tabs-mode nil) ) ;; ;; Settings for additional library loads (defun nb-ide-loads () ;(load-library "z:/job/HOME/nzafar/lib/elisp/idb.elc") ;(load-library "//dd/home/nzafar/lib/elisp/idb.elc" ) ;(setq semantic-load-turn-useful-things-on t) ; (load-file (concat (getenv "JOBDRIVE") ; "/job/HOME/nzafar/lib/cedet-1.0pre2/common/cedet.el") ) ;(semantic-load-enable-code-helpers) ) (defun nb-ide-bindings () (global-set-key "\C-m" 'reindent-then-newline-and-indent) (global-unset-key [C-down-mouse-2]) (global-set-key [C-down-mouse-2] `imenu) (global-set-key [f6] 'grep-in-code) (global-set-key [C-tab] 'ebrowse-tags-find-definition) (global-set-key "\M-[" 'match-paren) (global-set-key (read-kbd-macro "C-x ") 'next-error) (global-set-key [f2] 'gud-next) (global-set-key [f3] 'gud-step) (global-set-key [(control f2)] 'gud-until) ) (defun nb-ide-settings () (nb-ide-tabsets-personal) (nb-ide-bindings) (nb-ide-loads) (turn-on-auto-fill) (auto-fill-mode 1) (c-toggle-hungry-state 1) (setq comment-column 80) (setq compilation-window-height 20) (turn-on-font-lock) (setq font-lock-maximum-decoration t) (setq 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" "type_info" "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator" "reference" "const_reference" "uchar" "ulong" "[A-Z][a-z]\\sw+" "X[A-Z][a-z]\\sw+" ))) ) (add-hook 'c++-mode-hook 'nb-ide-settings) ;; c++ mode (add-hook 'c-mode-hook 'nb-ide-settings) ;; c mode (add-hook 'perl-mode-hook 'nb-ide-settings) ;; perl mode (add-hook 'java-mode-hook 'nb-ide-settings) ;; java mode (add-hook 'shell-script-mode-hook 'nb-shell-mode-hook) (add-hook 'c++-mode-hook (lambda () (font-lock-add-keywords nil '(("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) ("\\" . font-lock-keyword-face ) )))) ;; LaTeX editing prefs (add-hook 'latex-mode-hook 'latex-file-handler) (defun latex-file-handler () (global-set-key "\C-m" 'reindent-then-newline-and-indent) (global-unset-key [C-down-mouse-2]) (global-set-key [C-down-mouse-2] `imenu) (global-set-key "\M-[" 'match-paren) (turn-on-auto-fill) (auto-fill-mode 1) (set-fill-column 80) (turn-on-font-lock) (setq font-lock-maximum-decoration t) (turn-on-auto-fill) (setq tex-dvi-view-command "xdvi")) (defun nb-shell-mode-hook () (turn-on-auto-fill) (auto-fill-mode 1) (set-fill-column 80) (turn-on-font-lock) (setq font-lock-maximum-decoration t) ) ;; Personal options for HTML mode (add-hook 'html-mode-hook 'autoindent) ;; ---------------------------------------- ;; -- custom colors ;; ---------------------------------------- (cond (window-system (set-background-color "gray15") (set-foreground-color "gray85") (set-cursor-color "violet" ) (autoload 'faces "faces" t ) (set-face-foreground 'bold "red" ) (set-face-foreground 'bold-italic "blue" ) (set-face-foreground 'italic "deeppink2" ) (set-face-background 'highlight "thistle3") (set-face-foreground 'underline "darkorange4" ) (set-face-foreground 'modeline "black") (set-face-background 'modeline "Orange") (set-face-foreground 'region "red3") ;; marked text (set-face-background 'region "antiquewhite1") (set-face-foreground 'secondary-selection "yellow4") (if (eq system-type 'darwin) (set-frame-font "-apple-courier new-medium-r-normal--14-120-72-72-m-120-mac-roman" ) (set-frame-font "-adobe-courier-medium-r-normal--14-140-75-75-m-90-iso10646-1") ) )) ;; ---------------------------------------- ;; -- Infrequently used stuff ;; ---------------------------------------- (fset 'copyto "\C-w\C-xo\C-y\C-xo") (setq remem-scopes-list '(("code" 10 10 500))) ;; Word count on a region (defun count-words-region (beginning end) "Print number of words in the region." (interactive "r") (message "Counting words in region ... ") ;;; 1. Set up appropriate conditions. (save-excursion (let ((count 0)) (goto-char beginning) ;;; 2. Run the while loop. (while (and (< (point) end) (re-search-forward "\\w+\\W*" end t)) (setq count (1+ count))) ;;; 3. Send a message to the user. (cond ((zerop count) (message "The region does NOT have any words.")) ((= 1 count) (message "The region has 1 word.")) (t (message "The region has %d words." count)))))) ;; Places #ifdef guards in an include file (defun replace-in-string (string regexp newtext) (let ((skip (length newtext)) (start 0)) (while (string-match regexp string start) (setq string (replace-match newtext t t string) start (+ skip (match-beginning 0))))) string) (defun nb-include-guard () (interactive "") (goto-char 1) (let* ((inc-name (replace-in-string (buffer-name (current-buffer)) "\\." "_" ) ) (ftag (concat "__DD_" (upcase inc-name ) "__" )) ) (insert (concat "#ifndef " ftag)) (newline) (insert (concat "#define " ftag)) (newline) (newline) (end-of-buffer) (insert "#endif") (newline) ) ) (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t) (autoload 'c-mode "cc-mode" "C Editing Mode" t) (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t) (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. '(column-number-mode t) '(cua-mode nil) '(display-battery-mode nil) '(display-time-mode nil) '(global-font-lock-mode t) '(show-paren-mode t) '(transient-mark-mode t)) (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. ) ;; ---------------------------------------- ;; Display time (display-time) (iswitchb-mode)