;; -*- mode: emacs-lisp -*- ;;============================================================================== ;;; init.el ;; ;;; Main Emacs Settings File ;; ;;; Author: Kyle W T Sherman ;; ;; Time-stamp: <2008-08-04 12:09:40 (kyle)> ;;============================================================================== (message ";;; init --> Start") ;;============================================================================== ;;; Information ;;============================================================================== ;; Faces that may be set with font-lock: ;; ------------------------------------- ;; font-lock-comment-face ;; font-lock-string-face ;; font-lock-keyword-face ;; font-lock-builtin-face ;; font-lock-function-name-face ;; font-lock-variable-name-face ;; font-lock-type-face ;; font-lock-constant-face ;; font-lock-warning-face ;;============================================================================== ;;; General Settings ;;============================================================================== (message ";;; init --> General Settings") ;; ;; turn debugging on when errors occur ;; (setq debug-on-error t) ;; load cl lib (cl commands are used for a lot of things) (require 'cl) ;; see if we are in Linux or Windows (w32-system is t if in Windows) (defvar w32-system (memq system-type '(emx win32 w32 mswindows ms-dos windows-nt)) "Non-nil if running on Windows.") ;; see if we are in Emacs or XEmacs (defconst xemacsp (string-match "Lucid\\|XEmacs" emacs-version) "Non-nil if using XEmacs.") (defconst emacsp (not xemacsp) "Non-nil if using Emacs.") ;; make sure system name is set correctly (when (equal system-name "localhost.localdomain") (let ((name (shell-command-to-string "uname -n"))) (when (> (length name) 0) (setq system-name (substring name 0 -1))))) ;; cd to home (cd "~") ;; set customizations file (setq custom-file (expand-file-name "~/emacs.d/customizations.el")) ;; set username (setq user-full-name "Kyle W T Sherman") ;; set email address (if (getenv "EMAIL") (setq user-mail-address (getenv "EMAIL")) (setq user-mail-address (concat "kyle" "w" "sherman" "@" "gmail" "." "com"))) ;; set newsserver (setq gnus-select-method '(nntp "news.gmane.org")) ;; (setq gnus-select-method '(nnimap "gmail" ;; (nnimap-address "imap.gmail.com") ;; (nnimap-server-port 993) ;; (nnimap-stream ssl))) ;; gnus settings (setq gnus-nntp-server nil) (setq gnus-check-new-newsgroups 'ask-server) ;; make baskspace key work (setq normal-erase-is-backspace-mode t) ;; turn off startup messages (setq inhibit-startup-message t) (setq inhibit-splash-screen t) (setq initial-scratch-message nil) ;; enable file variables (setq enable-local-variables t) (setq enable-local-eval 'maybe) ;; turn on time and date in status bar (when emacsp (setq display-time-day-and-date t) (setq display-time-string-forms '(" " (format-time-string "%a %Y-%m-%d %H:%M" now) " ")) (display-time-mode t)) ;; turn off menubar in text mode (use M-` to activate) (when emacsp (if window-system (unless menu-bar-mode (menu-bar-mode t)) (when menu-bar-mode (menu-bar-mode nil)))) ;; turn off menubar (use M-` to activate) (when emacsp (when menu-bar-mode (menu-bar-mode nil))) ;; speed up emacs (setq gc-cons-threshold (* gc-cons-threshold 4)) ;; delete auto-save files (setq delete-auto-save-files t) ;; do not make auto-save files (setq auto-save-list-file-name nil) (setq auto-save-default nil) ;; do not make backup files (setq make-backup-files nil) ;; ;; set backup directory ;; (add-to-list 'backup-directory-alist '("~/emacs_backup")) ;; ;; make backup files ;; (setq make-backup-files t ;; version-control t ;; delete-old-versions t) ;; do not parse comments (setq parse-sexp-ignore-comments t) (setq-default parse-sexp-ignore-comments t) ;; handle gzip/zip/jar/tar files (setq auto-compression-mode t) ;; reuse existing buffers, following file links (setq find-file-existing-other-name t) ;; end files with a newline (setq require-final-newline t) ;; do not truncate lines (setq default-truncate-lines nil) (setq truncate-lines nil) ;; show line numbers (setq line-number-mode t) ;; show column numbers (setq column-number-mode t) ;; stop cursor at the end of the file (setq next-line-add-newlines nil) ;; keep screen position when using pgup and pgdn (setq scroll-preserve-screen-position 'keep) ;; scroll one line at a time (setq scroll-step 1) ;; scroll fewer lines (setq scroll-conservatively 5) ;; make searches case-insensitive (setq case-fold-search t) ;; highlight matches from searches (setq search-highlight t) (setq isearch-highlight t) (setq query-replace-highlight t) ;; make current selection visible (when emacsp (transient-mark-mode t) (setq-default transient-mark-mode t)) ;; set default tab indentation, width, and convert to spaces (setq tab-width 4) (setq default-tab-width 4) (setq standard-indent 4) (setq c-basic-indent 4) (setq-default indent-tabs-mode nil) (setq-default tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76)) ;; set default fill column for auto-fill mode and fill-paragraph (setq fill-column 78) (setq-default fill-column 78) ;; set default comment column for in-line comments (setq comment-column 40) (setq-default comment-column 40) ;; insert two spaces after a sentence when filling text (setq sentence-end-double-space t) ;; insert two spaces after a colon when filling text (setq colon-double-space t) ;; ;; set current buffer's filename, and full path in titlebar ;; (setq frame-title-format '("%b" (buffer-file-name ": %f"))) ;; smart buffer switching (when emacsp (iswitchb-mode 1)) ;; prompt before closing (setq kill-emacs-query-functions (cons (lambda () (y-or-n-p "Really kill Emacs? ")) kill-emacs-query-functions)) ;; change all calls to yes-or-no-p to y-or-n-p (fset 'yes-or-no-p 'y-or-n-p) ;; enable upercase region (C-x C-u) (put 'upcase-region 'disabled nil) ;; enable lowercase region (C-x C-l) (put 'downcase-region 'disabled nil) ;; enable narrow to region (put 'narrow-to-region 'disabled nil) ;; turn off the disabling of certain commands (setq disabled-command-hook nil) ;; turn on auto buffer revert (global-auto-revert-mode t) ;; set default font ;;(set-default-font "8x13") (set-default-font "9x15") ;; turn on syntax highlighting (when emacsp (global-font-lock-mode t) (setq font-lock-maximum-decoration t)) ;; replace highlighted text with typed ;;(delete-selection-mode t) ;; ;; make text-mode default ;; (setq default-major-mode 'text-mode) ;; set max message log size (setq message-log-max 2048) ;; set max variable bindings ;;(setq max-specpdl-size 640) ;; original value (setq max-specpdl-size 10000) ;; set max eval depth ;;(setq max-lisp-eval-depth 300) ;; original value (setq max-lisp-eval-depth 10000) ;; make apropos command search more (setq apropos-do-all t) ;; turn off diary entries view when calendar is run (setq view-diary-entries-initially nil) ;; ;; set diary size ;; (setq number-of-diary-entries 10) ;; ;; turn on diary appointments ;; (add-hook 'diary-hook 'appt-make-list) ;; ;; turn on calendar marks for diary entries ;; (setq mark-diary-entries-in-calendar t) ;; ;; turn on save place ;; (setq save-place t) ;; set outline regexp (setq outline-regexp "\~") ;; ;; abbrieviations (auto load and save abbrevs file) ;; (defconst abbrevs-file "~/.abbrev_defs") ;; (call-process "touch" nil nil nil (expand-file-name abbrevs-file)) ;; (abbrev-mode t) ;; (quietly-read-abbrev-file) ;; (setq save-abbrevs t) ;; (add-hook 'kill-emacs-hook '(lambda () (write-abbrev-file abbrevs-file))) ;; turn off abbreviation mode (abbrev-mode nil) ;; preserve case when replacing abbreviations (setq dabbrev-case-replace nil) ;; auto-save bookmarks (setq bookmark-save-flag 1) ;; follow symlinks to svn files w/o warning/asking (setq vc-follow-symlinks t) (setq-default vc-follow-symlinks t) ;; time-stamps ;; when there is a "Time-stamp: <>" in the first 10 lines of a file, ;; emacs will write the time-stamp there when saving the file (setq time-stamp-active t time-stamp-line-limit 20 time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") (add-hook 'write-file-hooks 'time-stamp) ;; add underscore and dash to word boundaries (modify-syntax-entry ?_ "w") (modify-syntax-entry ?- "w") ;; saved scripts are set as executable (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p) ;; ;; turn on imenu bar index ;; (imenu-add-menubar-index) ;; make shell files executable when saving (when (fboundp 'executable-make-buffer-file-executable-if-script-p) (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)) ;; ;; set comment start (default) and padding ;; (setq comment-start "#") ;; (setq comment-padding " ") ;; set comment style (setq comment-style 'indent) ;; save place in files (setq save-place t) (setq-default save-place t) ;; ;; load tags table ;; (when (file-exists-p "~/TAGS") (visit-tags-table "~/TAGS")) ;; shell environment (setq shell-file-name "bash") (setq shell-command-switch "-c") ;;(setq explicit-shell-file-name "/usr/bin/env bash") (setq explicit-shell-file-name shell-file-name) (setenv "SHELL" shell-file-name) (setq explicit-sh-args '("-login" "-i")) ;; quote arguments on windows (when w32-system (setq w32-quote-process-args ?\")) ;; set grep command (setq grep-command "grep -n -H -i -e ") ;; email settings (setq mail-sources `((pop :server "pop.gmail.com" :port 995 :user ,user-mail-address :connection ssl :leave t))) ;; set default browser ;;(setq browse-url-generic-program "x-www-browser") ;;(setq browse-url-generic-program "mozilla") ;;(setq browse-url-generic-program "w3m") ;;(setq browse-url-browser-function 'browse-url-generic) (setq browse-url-browser-function 'w3m-browse-url) ;; allows shift arrow keys to move between windows (when (fboundp 'windmove-default-keybindings) (windmove-default-keybindings)) ;; use meta arrow keys instead ;;(windmove-default-keybindings 'meta) ;; print settings (setq ps-print-header nil) ;; auto scroll compilation buffer (setq compilation-scroll-output t) ;;------------------------------------------------------------------------------ ;; ediff customizations ;;------------------------------------------------------------------------------ ;; split windows horizontally (setq ediff-split-window-function 'split-window-horizontally) ;; only hilight current diff (setq-default ediff-highlight-all-diffs 'nil) ;; turn off whitespace checking (setq ediff-diff-options "-w") ;; place control window in same frame (setq ediff-window-setup-function 'ediff-setup-windows-plain) ;; place control window in separate frame ;;(setq ediff-window-setup-function 'ediff-setup-windows-multiframe) ;; highlight changes to characters rather than words ;;(setq ediff-forward-word-function 'forward-char) ;;============================================================================== ;;; GUI Settings ;;============================================================================== (when window-system (message ";;; init --> GUI Settings") ;; ;; clipboard ;; (setq x-select-enable-clipboard t) ;; (setq interprogram-paste-function 'x-cut-buffer-or-selection-value) ;; inverse video on (setq inverse-video t) ;; turn off cursor blinking (when blink-cursor-mode (blink-cursor-mode)) ;; scroll bar on right (setq scroll-bar-mode 'right) (scroll-bar-mode -1) (scroll-bar-mode 1) ;; turn off toolbar (when (and (>= emacs-major-version 21) tool-bar-mode) (tool-bar-mode)) ;; mouse button one drags the scroll bar (global-set-key [vertical-scroll-bar down-mouse-1] 'scroll-bar-drag) ;; ;; scroll mouse settings ;; (defun mouse-up-slightly () (interactive) (scroll-up 5)) ;; (defun mouse-down-slightly () (interactive) (scroll-down 5)) ;; (global-set-key [mouse-4] 'mouse-down-slightly) ;; (global-set-key [mouse-5] 'mouse-up-slightly) ;; (defun mouse-up-one () (interactive) (scroll-up 1)) ;; (defun mouse-down-one () (interactive) (scroll-down 1)) ;; (global-set-key [S-mouse-4] 'mouse-down-one) ;; (global-set-key [S-mouse-5] 'mouse-up-one) ;; (defun mouse-up-lots () (interactive) (scroll-up)) ;; (defun mouse-down-lots () (interactive) (scroll-down)) ;; (global-set-key [C-mouse-4] 'mouse-down-lots) ;; (global-set-key [C-mouse-5] 'mouse-up-lots) ;; font ;;(set-default-font "-Misc-Fixed-Medium-R-Normal--15-140-75-75-C-90-ISO8859-1") (set-default-font "-Misc-Fixed-Bold-R-Normal--15-140-75-75-C-90-ISO8859-1") ;; faces ;; green foreground on black background with green cursor (custom-set-faces '(default ((t (:stipple nil :background "#000000" :foreground "#00ff00" )))) ;; :inverse-video nil ;; :box nil ;; :strike-through nil ;; :overline nil ;; :underline nil ;; :slant normal ;; :weight normal ;; :height 109 ;; :width normal ;; :family "misc-fixed" '(cursor ((t (:background "#00ff00"))))) ) ;;============================================================================== ;;; Functions ;;============================================================================== (message ";;; init --> Functions") ;; safe substring (defun safe-substring (string from &optional to) "Calls the `substring' function safely. \nNo errors will be returned for out of range values of FROM and TO. Instead an empty string is returned." (let ((len (length string))) (unless to (setq to len)) (when (< from 0) (setq from (+ len from))) (when (< to 0) (setq to (+ len to))) (if (or (< from 0) (> from len) (< to 0) (> to len) (< to from)) "" (substring string from to)))) ;; require if available ;; prevent load errors if a required package does not exist (defun require-if-available (&rest args) "Require symbols and load library strings. \nFails quietly if some are not available." (let (lib) (condition-case err (mapc (lambda (e) (setq lib e) (cond ((stringp e) (load-library e)) ((symbolp e) (require e)))) args) (file-error (progn (message "Could not load extension: %s" lib) nil))))) ;; load file if available (defun load-file-if-available (file) "Load emacs lisp file, if it exists. \nFails quietly if file does not exist." (when (file-exists-p file) (load-file file))) ;; compile file if needed (defun compile-file-if-needed (file) "Compile emacs lisp file if needed." ;; compile expanded file name (defun process-file (file) (let* ((file (expand-file-name file)) (file-comp (concat file "c"))) (when (or (not (file-exists-p file-comp)) (file-newer-than-file-p file file-comp)) (byte-compile-file file)))) ;; add .el if needed (unless (equal (safe-substring file -3) ".el") (setq file (concat file ".el"))) ;; find file (if (file-exists-p file) (process-file file) (dolist (path load-path) (let ((file (concat path "/" file))) (when (file-exists-p file) (process-file file))))) (when (get-buffer "*Compile-Log*") (kill-buffer "*Compile-Log*") (delete-other-windows))) ;;------------------------------------------------------------------------------ ;; Safe Load ;;------------------------------------------------------------------------------ (defconst safe-load-error-list "" "*List of files that reported errors when loaded with `safe-load'") (defun safe-load (file &optional noerror nomessage nosuffix) "Load FILE safely. \nIf an error occurs when loading, report it and add FILE to `safe-load-error-list'." (interactive "f") (condition-case nil (load file noerror nomessage nosuffix) (error (progn (setq safe-load-error-list (concat safe-load-error-list " " file)) (message "Error loading %s" file) ;;(sleep-for 1) nil)))) (defun safe-load-check () "Check for any previous `safe-load' loading errors." (interactive) (unless (equal safe-load-error-list "") (message "Error loading: %s" safe-load-error-list))) (defun safe-load-compile (file &optional noerror nomessage nosuffix) "Calls `compile-file-if-needed' followed by `safe-load'." (interactive "f") (compile-file-if-needed file) (safe-load file noerror nomessage nosuffix)) ;;============================================================================== ;;; Load Other Settings Files ;;============================================================================== (message ";;; init --> Other Settings Files") ;; local paths (add-to-list 'load-path "~/.emacs.d") (add-to-list 'load-path "~/.elisp") (add-to-list 'load-path (concat "~/.elisp/" user-login-name)) ; personal elisp projects (add-to-list 'load-path "~/emacs") ;; load other configuration files (safe-load-compile "keys") ; key bindings (first pass) (safe-load-compile "aliases") ; aliases (safe-load-compile "functions") ; functions (when emacsp (safe-load-compile "modules") ; modules (safe-load-compile "modes") ; modes (safe-load-compile "menus")) ; menus (safe-load-compile "keys") ; key bindings (second pass) (safe-load-compile "windows") ; windows settings (safe-load-compile "mode-line") ; mode line modifictions (safe-load-compile "ercrc") ; erc ;;(safe-load-compile "gnusrc") ; gnus ;;(safe-load-compile "googlerc") ; google ;; if on work machine, load work settings (when (or (equal system-name "min-kyle-linux.production.bigcharts.com") (equal system-name "min-kyle-linux")) (safe-load-compile "work")) ;; compile personal projects if needed (let ((dir (expand-file-name (concat "~/.elisp/" user-login-name) t))) (when (file-exists-p dir) (dolist (file (directory-files dir t)) (when (file-readable-p file) (cond ((string-match "^\\." (file-name-nondirectory file))) ((string-match ".*\.el$" file) (when (not (file-directory-p file)) (compile-file-if-needed file)))))))) ;; load customizations last (when (and custom-file (file-exists-p custom-file)) (safe-load custom-file)) ;;============================================================================== ;;; Final Stuff ;;============================================================================== (message ";;; init --> Final Stuff") ;; start emacs server (server-start-maybe) ;; clear mark (set-mark-command nil) ;; ;; restore context ;; (when (load "context" t) ;; (context-restore)) ;; ;; restore buffers ;; (require 'desktop) ;; (desktop-load-default) ;; (desktop-read) ;; ;; remove compile log buffer ;; (when (get-buffer "*Compile-Log*") ;; (kill-buffer "*Compile-Log*")) ;; remove symbol mapping buffer (when (get-buffer "Map_Sym.txt") (kill-buffer "Map_Sym.txt")) ;; report any load errors (or (and (safe-load-check) (switch-to-buffer "*Messages*")) (message ";;; init --> End")) ;;============================================================================== ;;; End Of File ;;==============================================================================