;;================================================== ;; 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 scroll-conservatively 10000) ;; My shortcut for "go to line" (global-set-key (kbd "C-x g") 'goto-line) ;; Find file at point (global-set-key (kbd "C-x f") 'find-file-at-point) ;; Invoke shell (global-set-key (kbd "C-x u") 'shell) ;; Shortcut for switch to other window (global-set-key (kbd "C-o") 'other-window) ;; Compile source (global-set-key (kbd "C-x c") 'compile) (setq compilation-read-command nil) ;; Invoke Python shell (global-set-key (kbd "C-x y") 'python-shell) ;; Better mapping for undo (global-set-key (kbd "C-l") 'undo) ;; Make sure that all files end with a newline (setq require-final-newline t) ;; Don't wrap long lines (setq-default truncate-lines t) ;; Make find-file and buffer switch case insensitive (setq read-file-name-completion-ignore-case t) (setq read-buffer-completion-ignore-case 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) ;;------------------------------------------ ;; C and C++ Modes ;;------------------------------------------ (defun my-c-mode-common-hook () (setq c-tab-always-indent t) (setq comment-style 'multi-line) (setq comment-start "/* ") (setq comment-end " */") ) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) ;;------------------------------------------ ;; Scons ;;------------------------------------------ ;; Tells Emacs to use scons instead of make to compile (setq compile-command "scons -Q") ;; Load python-mode for scons files (setq auto-mode-alist(cons '("SConstruct" . python-mode) auto-mode-alist)) (setq auto-mode-alist(cons '("SConscript" . python-mode) auto-mode-alist)) ;;------------------------------------------ ;; Perforce Library ;; ;; http://p4el.sourceforge.net/ ;;------------------------------------------ ;;(load-library "p4") ;;------------------------------------------ ;; MATLAB and Octave Mode ;;------------------------------------------ (setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist)) ;;------------------------------------------ ;; 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))) ;;------------------------------------------ ;; 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) ;; Set tab width for all buffers (setq-default tab-width 3) ;; 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) ;;(set-face-attribute 'default nil :font "Andale Mono-9") ;; Use "M-x list-faces-display" to see the current colors. (set-cursor-color "#D40E15") (set-foreground-color "#FFFFFF") (set-background-color "#111111") (set-face-background 'mode-line "#D8A315") ;;(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 item at cursor position and current directory." (interactive) (grep (read-string "Run grep as: " (concat "grep -Isrni " "\"" (thing-at-point 'symbol) "\"" " ."))) ) ;; Shortcut for my grep (global-set-key (kbd "C-x t") 'my-grep) (defun generate-tags () "Generate TAGS file. Relies on Exuberant CTAGS. Download it and replace the default ctags in the emacs bin directory. Use visit-tags-table to add more tags files to the emacs tags table." (interactive) (setq ctags_cmd (read-string "Run ctags as: " "ctags -e -R .")) (shell-command ctags_cmd) ) (defun remove-windows-line-endings () "removes the ^M line endings" (interactive) (replace-string "\^M" "") )