;; --------------------------------------------------------------------------- ;; File: .emacs ;; Time-stamp: ;; Author: Nick Nielsen ;; --------------------------------------------------------------------------- ;; Load external files from the ~/emacs directory. ;(setq load-path (cons "~/emacs" load-path)) ;;(setq load-path (cons "/usr/local/share/emacs/site-lisp" load-path)) ;; Files that should be opened automatically in a particular mode: (setq auto-mode-alist (cons '("\\.php$" . c-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.mak$" . makefile-mode) auto-mode-alist)) (add-to-list 'load-path "~/emacs"); ;(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/") ;(require 'tramp) (setq tramp-default-method "ssh") ; At work, I think autosave might be hanging Emacs in Windows XP. (setq auto-save-default nil) ; Always turn on font lock mode. Need the pretty colors. (global-font-lock-mode t) ;; 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 [delete] 'delete-char) (global-set-key [kp-delete] 'delete-char) ;; Swith to the next/previous buffers using CTLR-TAB and SHIFT-TAB (global-set-key [\C-tab] 'yic-next-buffer) (global-set-key [(shift tab)] 'yic-prev-buffer) (global-set-key [(S-iso-lefttab)] 'yic-prev-buffer) ;; Use the % button to find matching parentheses. Function defined below. (global-set-key "%" 'match-paren) (global-set-key "\M-g" 'goto-line) ;; Alt-g to goto line ;; Create file header prefix (define-prefix-command 'header-keymap nil "f1 CableLabs notice, f2 Std Header CableLabs, f3 Std Header Nielsenhome.net") (global-set-key [f1] 'header-keymap) ;; File headers for my current company. (define-key header-keymap [f1] (concat "// COPYRIGHT_BEGIN // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER // // Copyright (c) 2009, Cable Television Laboratories, Inc. // // // This program is free software; you can redistribute it and/or modify // it under the terms of only version 2 of the GNU General Public License // as published by the Free Software Foundation. // // This file is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. (a copy is included // that accompanied this file and can also be found at // https://opencable.dev.java.net/, or write to: the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, // MA 02110-1301 USA). // // Please contact CableLabs if you need additional information or // have any questions. // // CableLabs // 858 Coal Creek Cir // Louisville, CO 80027-9750 // 303 661-9100 // // oc-mail@cablelabs.com // COPYRIGHT_END " )) (defun buildHeader2() "builds header2 - standard header with CableLabs email address." (interactive nil) (buildHeader "n.nielsen@cablelabs.com") ) (defun buildHeader3() "builds header3 - standard header with Nielsenhome.net email address." (interactive nil) (buildHeader "nick@nielsenhome.net") ) (defun buildHeader(emailStr) "Builds a standard header using whichever comment characters are necessary for the current mode, and using the given email address string." (interactive nil) (insert (concat comment-start " File: " (buffer-name) comment-end "\n" comment-start " Author: Nick Nielsen <" emailStr ">" comment-end "\n" comment-start " Date: " (format-time-string "%a %b %d %H:%M:%S %Y") comment-end "\n" comment-start " Description: " (buffer-name) comment-end "\n\n" ) ) ) (define-key header-keymap [f2] 'buildHeader2) (define-key header-keymap [f3] 'buildHeader3) ;; the function toggle-hexl is defined below (global-set-key [f3] 'toggle-hexl) ;; the function dos2unix is defined below (global-set-key [f4] 'dos2unix) ;; revert-buffer is a built-in emacs command, and set it to the f5 key here. (global-set-key [f5] 'revert-buffer) (global-set-key [f6] 'gud-break) ;; gdb breakpoing (global-set-key [f7] 'gud-print) ;; gdb print variable at cursor (global-set-key [f9] 'gud-next) ;; gdb next (global-set-key [f10] 'gud-step) ;; gdb step (global-set-key [f11] 'gud-finish) ;; gdb finish current function (global-set-key [f12] 'gud-cont) ;; gdb continue ;; Set up additional gtags configuration. (global-set-key [(control meta .)] 'gtags-find-rtag) (global-set-key [(control meta >)] 'gtags-find-with-grep) (global-set-key "\C-cu" 'gtags-update) ;; Preserve middle-mouse paste, since gtags takes over middle mouse button. Now ;; it will be C-c middle-mouse. (global-set-key [(control c)mouse-2] 'comint-insert-clicked-input) ;; Allow for quick-and-easy reloading of the .emacs file, for testing. (global-set-key [(control f1)] 'loaddotemacs) ; NOTE: For compiling, use C-x ; RET to go to the first error.Use C-x ` to go ; to subsquent errors. (global-set-key [(control f9)] 'compile_nick) (global-set-key [(control meta shift f9)] 'compileclean_nick) ; Function to toggle between hexl-mode and hexl-mode-exit. (defun toggle-hexl () (interactive) "Toggle between hexl-mode and hexl-mode-exit" (if (string= mode-name "Hexl") (hexl-mode-exit) (hexl-mode)) ) ;; ;; NOTE: If you are using ssh from a cygwin terminal, and you start Emacs, I ;; have trouble with the backspace key (cygwin passes ^H, while Linux generally ;; expects ^?. The way to fix this is to add the following to your ;; .bash_profile on the Linux box to which you are connected. ;; ;;if [ "$TERM" == "cygwin" ] ; then ;; stty erase ^H ;;fi ;; ;; There are other problems in connecting with Cygwin, because Windows / Cygwin ;; disallows certain CTRL combinations to be sent. ;; ;; Set the mark using both c-RET and c-SPC because on some terminals (for ;; instance, cygwin) c-SPC does not come through correctly to the remote ;; machine. Also set C-M-m just in case. (global-set-key [(control return)] 'set-mark-command) (global-set-key [(control space)] 'set-mark-command) (global-set-key [(control meta m)] 'set-mark-command) ;; This makes it so Emacs displays right away despite font setting changes. ;; Sometimes without this, I have a long pause at startup, on some X Windows ;; systems (modify-frame-parameters nil '((wait-for-wm . nil))) ;; --------------------------------------------------------------------------- ;; Support for global gtags. You must install global and copy gtags.el to your ;; ~/emacs/ directory. ;; --------------------------------------------------------------------------- (add-hook 'c-mode-common-hook (lambda () (require 'gtags) (gtags-mode t))) (add-hook 'c-mode-hook (lambda () (c++-mode))) ;; --------------------------------------------------------------------------- ;; Highlight characters past the 80 column mark. Needs highlight-80+.el from: ;; http://nschum.de/src/emacs/highlight-80+/ ;; --------------------------------------------------------------------------- (add-hook 'c-mode-common-hook (lambda () (require 'highlight-80+) (font-lock-mode t) (highlight-80+-mode t) ) ) (add-hook 'text-mode-hook (lambda () (require 'highlight-80+) (font-lock-mode t) (highlight-80+-mode t) ) ) (add-hook 'emacs-lisp-mode-hook (lambda () (require 'highlight-80+) (font-lock-mode t) (highlight-80+-mode t) ) ) (add-hook 'sh-mode-hook (lambda () (require 'highlight-80+) (font-lock-mode t) (highlight-80+-mode t) ) ) ; ---------------------------------------------------------------------------- ; Integration of psvn.el, acquired from http://www.xsteve.at/prg/emacs/psvn.el ; ---------------------------------------------------------------------------- ; I HATE the subversion integration. It is too slow!! ;(require 'psvn) ;; To start, do a M-x svn-status (Map this operation?) ; ---------------------------------------------------------------------------- ; Nick's specific key mappings ; ---------------------------------------------------------------------------- ;; Always end a file with a newline (setq require-final-newline t) ;; Stop at the end of the file, not just add lines (setq next-line-add-newlines nil) ;; Do not show the splash screen at startup! (setq inhibit-splash-screen t) ;; Enable wheelmouse support by default (cond (window-system (mwheel-install) )) ;; Ditch the Emacs UI. The toolbar and menu system takes up valuable screen ;; real estate ;; (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) ;; I like the scrollbar. (if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) (if (fboundp 'menu-bar-mode) (menu-bar-mode -1)) ;; For very large buffers, font-lock can take a really long time. Supress font- ;; lock for huge buffers. This parameter is in? A value of nil will disable ;; supression (always fontify whole buffer) ;; (setq font-lock-maximum-size nil) ;; This allows me to set a starting size for my frames when I start up Emacs. ;;(defun framehook(framename) ;; "Default Frame Hook" ;; (interactive nil) ;; (set-frame-height framename 77) ;; ) ;;(add-hook 'create-frame-hook 'framehook) ;;(framehook (selected-frame)) ;;(make-frame) (defun compile_nick() "Compiles my current project with no other input." (interactive nil) (compile "cd /cygdrive/c/Projects/eyes-1.0_working/eyes-tct && ./compile_cabletester.sh") ) (defun compileclean_nick() "Cleans my current project with no other input." (interactive nil) (compile "make clean") ) (defun dos2unix() "Removes all ^M characters in the current buffer (converts DOS text to UNIX text)" (interactive nil) (goto-line 1) (replace-string "\r" "") (goto-line 1) ) (defun loaddotemacs() "Loads my .emacs file again." (interactive nil) (load-file "~/.emacs") ) (custom-set-variables ;; custom-set-variables was added by Custom -- don't edit or cut/paste it! ;; Your init file should contain only one such instance. '(c-basic-offset 3) '(c-tab-always-indent t) '(c-toggle-hungry-state 1) '(case-fold-search t) '(c-hanging-braces-alist 'set-from-style) '(c-offsets-alist '((substatement-open . 0))) '(fill-column 80) '(column-number-mode t) '(debug-on-error t) '(font-lock-maximum-size 512000) '(indent-tabs-mode nil) '(line-number-mode t) '(save-place t nil (saveplace)) '(show-paren-mode t nil (paren)) '(tab-width 3) '(transient-mark-mode nil) ; '(gud-jdb-use-classpath t) ; '(gud-jdb-classpath "/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/comcast-truview-parent-2.4.0-SNAPSHOT-jar-with-dependencies.jar") ; '(gud-jdb-directories "/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/cabletester/src/main/java:/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/common/src/main/java:/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/epgviewer/src/main/java:/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/protocol/src/main/java:/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/sisniffer/src/main/java:/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/tunnelsniffer/src/main/java:/cygdrive/c/Projects/oc/ears/cl_truview_2.4/target/tool/src/main/java") '(user-mail-address "nick@nielsenhome.net")) (custom-set-faces ;; NMN: Uncomment this line to make the font smaller. ;;'(default ((t (:background "darkslateblue" :foreground "whitesmoke" :height 87)))) ;;'(default ((t (:background "darkslateblue" :foreground "whitesmoke" :height 123)))) '(default ((t (:background "darkslateblue" :foreground "whitesmoke")))) '(font-lock-builtin-face ((t (:foreground "yellow" :weight bold)))) '(font-lock-comment-face ((((class color)) (:foreground "yellow3")))) '(font-lock-constant-face ((((class color) (background dark)) (:foreground "tan" :weight bold)))) '(font-lock-doc-face ((((class color) (background dark)) (:foreground "green" :bold t)))) '(font-lock-function-name-face ((((class color) (background dark)) (:foreground "lightsteelblue" :weight bold)))) '(font-lock-keyword-face ((((class color) (background dark)) (:foreground "orange" :bold t)))) '(font-lock-negation-face ((((class color) (background dark)) (:foreground "red" :bold t)))) '(font-lock-reference-face ((((class color) (background dark)) (:foreground "tan" :bold t)))) '(font-lock-string-face ((((class color) (background dark)) (:foreground "green")))) '(font-lock-type-face ((((class color) (background dark)) (:foreground "Violet")))) '(font-lock-variable-name-face ((((class color) (background dark)) (:foreground "cyan")))) '(highlight ((((type tty) (class color)) (:background "green" :foreground "black"))))) ;; ---------------------------------------------------------------------------- ;; Function to update my gtags. ;; ---------------------------------------------------------------------------- (defun gtags-update () "Update the gtags for the current file." (interactive nil) (shell-command "global -vu") ) ;; ---------------------------------------------------------------------------- ;; Functions I wrote quite a while ago for perforce integration. ;; ---------------------------------------------------------------------------- ;; p4edit will check out the current file (defun p4edit () "Check out the current file out using perforce, and then revert the buffer (so it is no longer read-only)" (interactive nil) (shell-command (concat "p4 edit " (buffer-file-name) ) ) (revert-buffer t t) ) ;; p4add will check out the current file (defun p4add () "Check out the current file out using perforce, and then revert the buffer (so it is no longer read-only)" (interactive nil) (shell-command (concat "p4 add " (buffer-file-name) ) ) (revert-buffer t t) ) ;; p4revert will prompt the user (yes or no) whether he or she wants to revert ;; the file back to perforce without saving (defun p4revert () "Undo a checkout through perforce" (interactive nil) (if (yes-or-no-p (format "Discard changes and revert file %s back to perforce? " (buffer-name (current-buffer)))) (let ((first (shell-command (concat "p4 revert " (buffer-file-name) ) )) (second (revert-buffer t t)) ) ) ) ) ;; ---------------------------------------------------------------------------- ;; Good example Emacs files I've found: ;; http://dahoiv.net/.emacs ;; ---------------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions found from external sources (original source preserved, if ;; possible): ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Pulled from sigquit.wordpress.com ;; http://sigquit.wordpress.com/2008/09/14/insert-date-string-dot-emacs/ (defun insert-date-string() "Insert a nicely formatted date string." (interactive) (insert (format-time-string "%a %b %d %H:%M:%S %Y"))) ;; Prevent accidentally killing emacs. (from dahoiv.net/.emacs) (global-set-key [(control x) (control c)] '(lambda () (interactive) (if (y-or-n-p-with-timeout "Do you really want to exit Emacs ? " 4 nil) (save-buffers-kill-emacs)))) ;; ---------------------------------------------------------------------- ;; Original yic-buffer.el ;; From: choo@cs.yale.edu (young-il choo) ;; Date: 7 Aug 90 23:39:19 GMT ;; ;; Modified ;; ---------------------------------------------------------------------- (defun yic-ignore (str) (or ;;buffers I don't want to switch to (string-match "\\*Buffer List\\*" str) (string-match "^TAGS" str) (string-match "^\\*Messages\\*$" str) (string-match "^\\*Scratch\\*$" str) (string-match "^\\*Compile-Log\\*$" str) (string-match "^\\*Completions\\*$" str) (string-match "^ " str) ;;Test to see if the window is visible on an existing visible frame. ;;Because I can always ALT-TAB to that visible frame, I never want to ;;Ctrl-TAB to that buffer in the current frame. That would cause ;;a duplicate top-level buffer inside two frames. (memq str (mapcar (lambda (x) (buffer-name (window-buffer (frame-selected-window x)))) (visible-frame-list))) )) (defun yic-next (ls) "Switch to next buffer in ls skipping unwanted ones." (let* ((ptr ls) bf bn go ) (while (and ptr (null go)) (setq bf (car ptr) bn (buffer-name bf)) (if (null (yic-ignore bn)) ;skip over (setq go bf) (setq ptr (cdr ptr)) ) ) (if go (switch-to-buffer go)))) (defun yic-prev-buffer () "Switch to previous buffer in current window." (interactive) (yic-next (reverse (buffer-list)))) (defun yic-next-buffer () "Switch to the other buffer (2nd in list-buffer) in current window." (interactive) (bury-buffer (current-buffer)) (yic-next (buffer-list))) ;;end of yic buffer-switching methods ;; time-stamps from http://www.djcbsoftware.nl/dot-emacs.html ;; when there is a "Time-stamp: <>" in the first 10 lines of the file, ;; emacs will write time-stamp information there when saving the file. ;; see the top of this file for an example... ;; NMN: There is a 1 second delay when I pause, and I can't stand it. Disabling ;; this for now. ;; (setq ;; time-stamp-active t ; do enable time-stamps ;; time-stamp-line-limit 3 ; check first 10 buffer lines for Time-stamp: <> ;; time-stamp-format "Last changed %02d-%02m-%04y %02H:%02M:%02S by %L, %u") ; date format ;; (add-hook 'write-file-hooks 'time-stamp) ; update when saving ;; --------------------------------------------------------------------------- ;; NMN: I don't remember where this came from, but it is useful. ;; --------------------------------------------------------------------------- (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 (self-insert-command (or arg 1)))))