;; ---------------------------------------- ;; General Emacs preferences ;; ---------------------------------------- (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) (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") ;; set PATH (setq exec-path (append exec-path (list "/usr/local/bin"))) ;; ---------------------------------------- ;; -- 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) ;; ;; f7: set a bookmark to the current point ;; f8: return to the last bookmark set ;; (defun push-bookmark() (interactive "") (bookmark-set buffer-file-name nil) ) (fset 'pop-bookmark [?\C-x ?r ?b return]) (global-set-key "\C-xpd" 'push-bookmark) (global-set-key [f7] 'push-bookmark) (global-set-key "\C-xpu" 'pop-bookmark) (global-set-key [f8] 'pop-bookmark) ;; 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) ("\\.H$". c++-mode) ("\\.h$". c++-mode) ("\\.env$". shell-script-mode) ) auto-mode-alist)) (global-font-lock-mode 1) (transient-mark-mode 1) (font-lock-mode 1) (column-number-mode 1) (fmakunbound 'c++-mode) (makunbound 'c++-mode-map) (makunbound 'c-style-alist) (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) (fset 'grep-in-code [escape ?w f5 ?" ?\C-y ?" ? ?* ?. ?[ ?h ?H ?c ?C ?] 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 -k")) (global-set-key "\C-c\C-v" 'my-save-and-compile) (global-set-key [f9] 'recompile) ;; ;; 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 () (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 2) (c-set-offset 'substatement 2) (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) ) (defun nb-gud-runto () (gud-tbreak) (gud-cont)) (defun nb-ide-settings () (nb-ide-tabsets) (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 [(meta f2)] 'gud-cont) (global-set-key [(meta f4)] 'nb-gud-runto) (turn-on-auto-fill) (auto-fill-mode 1) (c-toggle-hungry-state 1) (setq comment-column 60) (turn-on-font-lock) (setq compilation-window-height 20) (setq font-lock-maximum-decoration t) (require 'psvn) ) (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 'shell-script-mode-hook 'nb-ide-settings) ;; 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 100) (turn-on-font-lock) (setq font-lock-maximum-decoration t) (turn-on-auto-fill) (setq tex-dvi-view-command "xdvi")) ;; 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-monaco-medium-r-normal--13-120-72-72-m-120-mac-roman") (set-frame-font "-apple-courier new-medium-r-normal--14-120-72-72-m-120-mac-roman" ) ;;(set-frame-font "-apple-andale mono-medium-r-normal--14-120-72-72-m-120-mac-roman" ) ;;(set-frame-font "-apple-ayuthaya-medium-r-normal--14-120-72-72-m-0-mac-cyrillic" ) ) )) ;; ---------------------------------------- ;; -- 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 protection in an include file (defun my-include-guard () "Compute the appropriate #include guard based on the current buffer's name" (let* ((split-name (my-split-current-filename)) (time (decode-time)) (prefix (car split-name)) (ext (cdr split-name)) (extension (if ext (concat "_" ext) "")) ) (upcase (concat prefix "_" my-initials (number-to-string (nth 5 time)) (number-to-string (nth 4 time)) (number-to-string (nth 3 time)) extension))))