;;================================================== ;; The perfect .emacs file ;; Trent Rolf ;;================================================== ;;------------------------------------------ ;; Behavior ;;------------------------------------------ ;; Set the folder for add-on libraries (setq load-path (cons "~/.emacs_addons" load-path)) ;; Fix the C-h backspace key (define-key global-map "\C-h" 'backward-delete-char) ;; Do not display a splash screen on startup (setq inhibit-splash-screen t) ;; Show column-number in the mode line (column-number-mode 1) ;; Save all backup file in this directory. (setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/")))) ;; Enable basic version control for backup files (setq backup-by-copying t) (setq delete-old-versions t kept-new-versions 6 kept-old-versions 2 version-control t) ;; Line by line scrolling (setq scroll-step 1) ;; My shortcut for "go to line" (global-set-key (kbd "C-x g") 'goto-line) ;; My shortcut for "calculator" (not calc) (global-set-key (kbd "C-x c") 'calculator) ;; Find file at point (global-set-key (kbd "C-x f") 'find-file-at-point) ;; Indent entire buffer (global-set-key (kbd "C-x i") 'indent-entire-buffer) ;; Invoke shell (global-set-key (kbd "C-x u") 'shell) ;; Invoke telnet-style shell (global-set-key (kbd "C-x y") 'my-telnet) ;; Change the default behavior of recenter (defun my-recenter () (interactive) (recenter 3) ) (global-set-key (kbd "C-l") 'my-recenter) ;; Make sure that all files end with a newline (setq require-final-newline t) ;;------------------------------------------ ;; Shell Mode ;;------------------------------------------ (defun my-keys-shell () (define-key shell-mode-map "\C-j" 'comint-send-input) (set-face-foreground 'comint-highlight-prompt "orange") ) (add-hook 'shell-mode-hook 'my-keys-shell) (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) ;;------------------------------------------ ;; Telnet Mode ;;------------------------------------------ ;;(defun my-telnet () ;; (load "telnet") ;; (interactive) ;; (shell "telnet") ;; (telnet-mode) ;; ) (defun my-keys-telnet () (define-key telnet-mode-map "\C-j" 'telnet-send-input) ) (add-hook 'telnet-mode-hook 'my-keys-telnet) (add-hook 'telnet-mode-hook 'ansi-color-for-comint-mode-on) ;;------------------------------------------ ;; C++ Mode ;;------------------------------------------ (defun my-c++-mode-hook () (setq c-tab-always-indent t) ) (add-hook 'c++-mode-hook 'my-c++-mode-hook) ;;------------------------------------------ ;; C Mode ;;------------------------------------------ (defun my-c-mode-hook () (setq c-tab-always-indent t) ) (add-hook 'c-mode-hook 'my-c-mode-hook) ;;------------------------------------------ ;; MATLAB Mode ;; ;; http://www.andrew.cmu.edu/course/16-720/ ;; extras/matlab_in_emacs/index.html ;; ;; Comment out this line in matlab.el : ;; (define-key km [(control h) (control m)] matlab-help-map) ;;------------------------------------------ (autoload 'matlab-mode "matlab.el" "Matlab Mode" t) (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist)) (autoload 'matlab-shell "matlab.el" "Interactive Matlab mode." t) ;;------------------------------------------ ;; Verilog Mode ;; ;; http://www.veripool.org/wiki/verilog-mode ;;------------------------------------------ ;;(autoload 'verilog-mode "verilog-mode.el" "Verilog Mode" t) ;;(setq auto-mode-alist (cons '("\\.v\\'" . verilog-mode) auto-mode-alist)) ;;(add-hook 'verilog-mode-hook '(lambda () (font-lock-mode 1))) ;;------------------------------------------ ;; Lilypond Mode ;; ;; http://www.geoffhorton.com/lilymacs.html ;; Follow the instructions! Do not use the usual .emacs_addons ;;------------------------------------------ (autoload 'LilyPond-mode "lilypond-mode") (setq auto-mode-alist (cons '("\\.ly$" . LilyPond-mode) auto-mode-alist)) (add-hook 'LilyPond-mode-hook (lambda () (turn-on-font-lock))) ;;------------------------------------------ ;; Clearcase Mode ;; ;; http://members.verizon.net/kevin.a.esler/EmacsClearCase/ ;; Instructions are in clearcase.el ;;------------------------------------------ ;;(load "clearcase") ;;(setq clearcase-suppress-checkout-comments t) ;;(setq clearcase-keep-uncheckouts nil) ;;(global-set-key (kbd "C-c i") 'clearcase-checkin-current-buffer) ;;(global-set-key (kbd "C-c o") 'clearcase-checkout-current-buffer) ;;------------------------------------------ ;; Appearance ;;------------------------------------------ ;; Don't show the menu, tool, or scroll bars (menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1) ;; Indenting style (setq c-set-style "ellemtel") (setq c-default-style "ellemtel") ;; Use spaces instead of tabs for indent. (setq-default indent-tabs-mode nil) ;; Spacing between lines (for GUI mode) (setq-default line-spacing 1) ;; Turn on synatx highlighting (global-font-lock-mode 1) ;; Highlight bracket/parentheses pairs (show-paren-mode t) ;; Set the default screen split to be side-by-side (setq display-buffer-prefer-horizontal-split t) ;; Make ediff split side-by-side by default (setq ediff-split-window-function 'split-window-horizontally) ;; Set default font (if supported) ;;(add-to-list 'default-frame-alist '(font . "-*-Courier New-normal-r-*-*-11-*-*-*-c-*-iso8859-1")) ;;(add-to-list 'default-frame-alist '(font . "-*-Lucida Console-normal-r-*-*-12-*-*-*-c-*-iso8859-1")) ;; Use "M-x list-faces-display" to see the current colors. ;;(set-cursor-color "#D40E15") ;;(set-foreground-color "#FFFFFF") ;;(set-background-color "#030303") ;;(set-face-foreground 'font-lock-comment-face "#EE6363") ;;(set-face-foreground 'font-lock-comment-delimiter-face "#EE6363") ;;(set-face-foreground 'font-lock-string-face "#D8A315") ;;(set-face-foreground 'font-lock-preprocessor-face "#D1CB3F") ;;(set-face-foreground 'font-lock-keyword-face "#1E90FF") ;;(set-face-foreground 'font-lock-type-face "#43CD80") ;;(set-face-foreground 'font-lock-variable-name-face "#25912A") ;;(set-face-foreground 'font-lock-function-name-face "#1E90FF") (set-face-foreground 'minibuffer-prompt "#1E90FF") ;;(set-face-foreground 'isearch "#000000") ;;(set-face-background 'isearch "#FFFF00") ;;(set-face-foreground 'lazy-highlight "#000000") ;;(set-face-background 'lazy-highlight "#97FFFF") ;;------------------------------------------ ;; Custom Functions ;;------------------------------------------ ;; Custom grep tool (defun my-grep () "Grep recursively for something. Defaults to term at cursor position and current directory." (interactive) ;; Define what we are looking for (setq default_needle (thing-at-point 'symbol)) (setq needle (read-string (concat "grep for (" default_needle "): "))) (setq needle (if (equal needle "") default_needle needle)) ;; Determine the options (setq default_options "srin") (setq options (read-string (concat "grep options (" default_options "): "))) (setq options (if (equal options "") default_options options)) ;; Determine the directory (setq haystack (read-directory-name (concat "in directory: ") ".")) ;; Execute the grep (grep (concat "grep -" options " " needle " " haystack " "))) ;; Shortcut for my-grep (global-set-key (kbd "C-x t") 'my-grep) ;; Some linux distributions configure user sessions by default to enable ;; color highlighting of all output from `ls'. ;; Thees don't work in emacs buffers by default; this function strips them ;; out unless ansi-color.el is enabled. (defun my-strip-ansi-color () "Possibly strip ANSI terminal color escape sequences." (interactive) (goto-char 0) ;; (while (re-search-forward "\e\\[[0-9;]*m" nil t) (while (re-search-forward "\e\\[." nil t) (delete-region (match-beginning 0) (match-end 0))))