;; ;; Erik Gillespie's emacs initializations ;; ;; ;; Set some internal variables ;; (setq user-full-name "Erik Gillespie") ; My full name (setq user-mail-address "rattles@yakko.cs.wmich.edu") ; My email address (setq inhibit-startup-message t) ; Don't display that annoying startup message (setq default-major-mode 'text-mode) ; Default mode is text mode (setq c-recognize-knr-p nil) ; This supposedly speeds up indenting (setq make-backup-files nil) ; Don't make myfile.txt~ backup files (setq hscroll-step-percent 8) ; Scroll horizontally X columns at a time (setq scroll-step 1) ; Scroll vertically 1 line at a time (setq default-truncate-lines t) ; Don't wrap long lines (setq next-line-add-newlines nil) ; Don't add a newline when scrolling at EOF (setq require-final-newline t) ; Require a newline at EOF (setq line-number-mode t) ; Show what line # we're on (setq column-number-mode t) ; Show what column # we're on (setq win32-num-mouse-buttons 2) ; Number of mouse buttons I have on my Windows computer (setq default-tab-width 4) ; A single tab looks like 4 spaces (setq indent-tabs-mode t) ; Always insert tabs when the tab key is hit ;; ;; Custom functions used here ;; ;; Date/time stamp functions (defun insert-date () "Insert date (YYYY-MM-DD) at point." (interactive) (insert (format-time-string "%Y-%m-%d"))) (defun insert-timestamp () "Insert timestamp (YYYY-MM-DD hh:mm:ss) at point." (interactive) (insert (format-time-string "%Y-%m-%d %H:%M:%S"))) ;; Reindent the entire buffer (defun indent-buffer () "Reindent the entire buffer" (interactive) (save-excursion (goto-char (point-min)) (while (< (point) (point-max)) (indent-for-tab-command) (forward-line 1)))) ;; Get help on current word (defun man-current-word () "Manual entry for the current word" (interactive) (manual-entry (current-word))) (defun info-current-word () "Info page for the current word" (interactive) (info-lookup-symbol (current-word))) ;; ;; Make sure the colors are how I like them ;; (set-background-color "black") (set-foreground-color "white") (set-face-background 'region "DeepSkyBlue4") (set-face-foreground 'region "black") (set-cursor-color "white") ;; ;; Setup some keys I like to use ;; (global-set-key "\M-g" 'goto-line) ; Goto specified line (global-set-key "\C-x\C-d" 'insert-date) ; Insert date "YYYY-MM-DD" at cursor (custom function) (global-set-key "\C-x\C-t" 'insert-timestamp) ; Insert date/time "YYYY-MM-DD hh:mm:ss" at cursor (custom function) (global-set-key [M-f4] 'save-buffers-kill-emacs) ; So we can close with Alt+F4 (global-set-key [delete] 'delete-char) ; Delete character the cursor is on (global-set-key [kp-delete] 'delete-char) ; Delete character the cursor is on (global-set-key "\C-x\C-i" 'indent-buffer) ; Reindent the entire buffer (custom function) (global-set-key [f1] 'man-current-word) ; Show man page for current word (global-set-key [C-f1] 'info-current-word) ; Show info page for current word (global-set-key [(mouse-3)] 'yank) ; Right-click pastes ;; ;; Replace some default functions/behavior ;; (fset 'yes-or-no-p 'y-or-n-p) ; Always prompt for 'y' or 'n' instead of 'yes' or 'no' (put 'downcase-region 'disabled nil) ; So we can make an entire region lowercase (transient-mark-mode t) ; Automatically highlight current selection (hscroll-global-mode t) ; Turn on horizontal scrolling by default (global-font-lock-mode t) ; Turn on font-lock mode (syntax highlighting) (toggle-truncate-lines) ; Don't wrap lines ;; ;; The rest of the file is dedicated to programming/major mode customization ;; ;; OpenGL data types (in C mode, anything that starts with GL) (setq c-font-lock-extra-types (append '("\\") c-font-lock-extra-types)) (setq c++-font-lock-extra-types (append c-font-lock-extra-types c++-font-lock-extra-types)) ;; Add some highlighted keywords: ;; Macros ;; Functions (font-lock-add-keywords 'c-mode '(("\\<\\([A-Z_][A-Z0-9_]*\\)\\>" 1 font-lock-constant-face) ("\\<\\([A-Za-z_][A-Za-z0-9_]*\\)\\>(" 1 font-lock-function-name-face))) (font-lock-add-keywords 'c++-mode '(("\\<\\([A-Z_][A-Z0-9_]*\\)\\>" 1 font-lock-constant-face) ("\\<\\([A-Za-z_][A-Za-z0-9_]*\\)\\>(" 1 font-lock-function-name-face))) ;; Associate .h files with c++-mode instead of c-mode (add-to-list 'auto-mode-alist '("\\.h$" . c++-mode)) ;; Other C/C++ mode features to add (add-hook 'c-mode-hook '(lambda() ;; F5 will compile the current buffer (with 'make -k') (local-set-key [f5] '(lambda() (interactive) (compile "make -k"))) ;; Hitting Enter automatically tabs to correct location (local-set-key "\C-m" 'newline-and-indent) ;; Normally F1 displays man page section 1, this displays section 3 ;; Lots of function syntax manpages are in section 3 (local-set-key [f1] '(lambda() (interactive) (manual-entry (concat (current-word) "(3)")))))) (add-hook 'c++-mode-hook '(lambda() ;; F5 will compile the current buffer (with 'make -k') (local-set-key [f5] '(lambda() (interactive) (compile "make -k"))) ;; Hitting Enter automatically tabs to correct location (local-set-key "\C-m" 'newline-and-indent) ;; Normally F1 displays man page section 1, this displays section 3 ;; Lots of function syntax manpages are in section 3 (local-set-key [f1] '(lambda() (interactive) (manual-entry (concat (current-word) "(3)")))))) ;; Syntax highlighting, etc. for PHP files (autoload 'php-mode "php-mode" "PHP Editing Mode" t) (add-to-list 'auto-mode-alist '("\\.php$" . php-mode)) ;; Syntax highlighting, etc. for JIL files (autoload 'jil-mode "jil-mode" "JIL Editing Mode" t) (add-to-list 'auto-mode-alist '("\\.jil$" . jil-mode)) ;; Add some words to the SQL font-lock mode (font-lock-add-keywords 'sql-mode '(("\\<\\(TRUNCATE\\|IDENTITY\\|DROP\\|DATABASE\\|IF\\|ELSE\\|WHILE\\|CASE\\|WHEN\\|THEN\\|OFF\\|USE\\|FLUSH\\|END\\|BEGIN\\)\\>" 1 font-lock-keyword-face) ("\\<\\(COMMIT\\|ROLLBACK\\|TRAN\\|PROC\\|STATISTICS\\|EXECUTE\\|PROCEDURE\\|INDEX\\|UNIQUE\\|CLUSTERED\\|NONCLUSTERED\\)\\>" 1 font-lock-keyword-face) ("\\<\\(ALTER\\|ADD\\)\\>" 1 font-lock-keyword-face) ("\\<\\(LOCK\\|ALLPAGES\\|CONSTRAINT\\)\\>" 1 font-lock-keyword-face) ("\\<\\(NUMERIC\\|TINYINT\\|BIGINT\\|TIMESTAMP\\|UNSIGNED\\|DATE\\|DATETIME\\|TEXT\\|VARCHAR\\|FLOAT\\|TIME\\|SMALLDATETIME\\)\\>" 1 font-lock-type-face) ("\\<\\(BIT\\)\\>" 1 font-lock-type-face) ("\\<\\(GETDATE\\|DATEPART\\|ABS\\|DATEADD\\|CONVERT\\|PATINDEX\\|RETURN\\|PASSWORD\\|PRINT\\|BREAK\\|ISNULL\\)\\>" 1 font-lock-function-name-face) ("\\<\\(ROUND\\|SUBSTRING\\|RTRIM\\|LTRIM\\|CHAR_LENGTH\\|CHARINDEX\\|REVERSE\\|OBJECT_ID\\|RAISERROR\\|DATEDIFF\\)\\>" 1 font-lock-function-name-face) ("\\<\\(AUTO_INCREMENT\\|TYPE\\|COMMENT\\)\\>" 1 font-lock-variable-name-face) ("[#@]\\<\\([A-Za-z]\\w*\\)\\>" 1 font-lock-variable-name-face) ("\\(<[A-Za-z_]+>\\)" 1 font-lock-builtin-face))) ;; Any file under 400K will get highlighted (custom-set-variables '(font-lock-maximum-size 400000)) (custom-set-faces)