;; ============================================================ ;;; ;; Author: Adam Jiang ;; Reversion: 1.1 ;; Update: 2009/07/11 ;; ============================================================ ;;; ;; This file is designed to be re-evaled; use the variable first-time ;; to avoid any problems with this. (defvar first-time t "Flag signifying this is the first time that .emacs has been evaled") ;;;------------------------------------------------------------;;; ;;; LOADPATH (if (fboundp 'normal-top-level-add-subdirs-to-load-path) (let* ((my-lisp-dir "~/.elisp/") (default-directory my-lisp-dir)) (setq load-path (cons my-lisp-dir load-path)) (normal-top-level-add-subdirs-to-load-path))) ;;;------------------------------------------------------------;;; ;;; ============================================================ ;;; ;;; BYTE COMPILE FOR SPEEDING UP ;;; ============================================================ ;;; ;; automatically do byte-compilation of .emacs when save it (defun byte-compile-user-init-file () (let ((byte-compile-warnings '(unresolved))) ;; in case compilation fails, don't leave the old .elc around: (when (file-exists-p (concat user-init-file ".elc")) (delete-file (concat user-init-file ".elc"))) (byte-compile-file user-init-file) ;; (message "%s compiled" user-init-file) )) (defun my-emacs-lisp-mode-hook () (when (equal buffer-file-name user-init-file) (add-hook 'after-save-hook 'byte-compile-user-init-file t t))) ;; (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) (add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook) ;; byte compile loaded files for speeding up (require 'byte-code-cache) ;;; ============================================================ ;;; ;;; INIT MISC ;;; ============================================================ ;;; (require 'init-misc) ;;; ============================================================= ;;; ;;; KEY BINDINGS ;;; ============================================================= ;;; ;; Meta (global-set-key "\M- " 'set-mark-command) (global-set-key "\M-\C-h" 'backward-kill-word) (global-set-key "\M-\C-r" 'query-replace) (global-set-key "\M-r" 'replace-string) (global-set-key "\M-g" 'goto-line) (global-set-key "\M-h" 'help-command) ;; Function keys (global-set-key [f1] 'manual-entry) (global-set-key [f2] 'info) (global-set-key [f3] 'repeat-complex-command) (global-set-key [f4] 'advertised-undo) (global-set-key [f5] 'eval-current-buffer) (global-set-key [f6] 'buffer-menu) (global-set-key [f7] 'other-window) (global-set-key [f8] 'find-file) (global-set-key [f9] 'save-buffer) (global-set-key [f10] 'next-error) (global-set-key [f11] 'compile) (global-set-key [f12] 'grep) (global-set-key [C-f1] 'compile) (global-set-key [C-f2] 'grep) (global-set-key [C-f3] 'next-error) (global-set-key [C-f4] 'previous-error) (global-set-key [C-f5] 'display-faces) (global-set-key [C-f8] 'dired) (global-set-key [C-f10] 'kill-compilation) ;; Keypad bindings (global-set-key [up] "\C-p") (global-set-key [down] "\C-n") (global-set-key [left] "\C-b") (global-set-key [right] "\C-f") (global-set-key [home] "\C-a") (global-set-key [end] "\C-e") (global-set-key [prior] "\M-v") (global-set-key [next] "\C-v") (global-set-key [C-up] "\M-\C-b") (global-set-key [C-down] "\M-\C-f") (global-set-key [C-left] "\M-b") (global-set-key [C-right] "\M-f") (global-set-key [C-home] "\M-<") (global-set-key [C-end] "\M->") (global-set-key [C-prior] "\M-<") (global-set-key [C-next] "\M->") (global-set-key [mouse-3] 'imenu) ;; Treat 'y' or as yes, 'n' as no. (fset 'yes-or-no-p 'y-or-n-p) (define-key query-replace-map [return] 'act) (define-key query-replace-map [?\C-m] 'act) ;; Load desktop as session manager (require 'desktop) ;; Pretty diff mode (autoload 'ediff-buffers "ediff" "Intelligent Emacs interface to diff" t) (autoload 'ediff-files "ediff" "Intelligent Emacs interface to diff" t) (autoload 'ediff-files-remote "ediff" "Intelligent Emacs interface to diff") ;;; ============================================================ ;;; ;;; MODE HOOKS ;;; ============================================================ ;;; ;; C++ and C mode... (defun my-c++-mode-hook () (setq tab-width 4) (define-key c++-mode-map "\C-m" 'reindent-then-newline-and-indent) (define-key c++-mode-map "\C-ce" 'c-comment-edit) (setq c++-auto-hungry-initial-state 'none) (setq c++-delete-function 'backward-delete-char) (setq c++-tab-always-indent t) (setq c-indent-level 4) (setq c-continued-statement-offset 4) (setq c++-empty-arglist-indent 4)) (defun my-c-mode-hook () (setq tab-width 4) (define-key c-mode-map "\C-m" 'reindent-then-newline-and-indent) (define-key c-mode-map "\C-ce" 'c-comment-edit) (setq c-auto-hungry-initial-state 'none) (setq c-delete-function 'backward-delete-char) (setq c-tab-always-indent t) ;; BSD-ish indentation style (setq c-indent-level 4) (setq c-continued-statement-offset 4) (setq c-brace-offset -4) (setq c-argdecl-indent 0) (setq c-label-offset -4)) ;; Perl mode (defun my-perl-mode-hook () (setq tab-width 4) (define-key c++-mode-map "\C-m" 'reindent-then-newline-and-indent) (setq perl-indent-level 4) (setq perl-continued-statement-offset 4)) ;; Scheme mode... (defun my-scheme-mode-hook () (define-key scheme-mode-map "\C-m" 'reindent-then-newline-and-indent)) ;; Emacs-Lisp mode... (defun my-lisp-mode-hook () (define-key lisp-mode-map "\C-m" 'reindent-then-newline-and-indent) (define-key lisp-mode-map "\C-i" 'lisp-indent-line) (define-key lisp-mode-map "\C-j" 'eval-print-last-sexp)) ;; Add all of the hooks... (add-hook 'c++-mode-hook 'my-c++-mode-hook) (add-hook 'c-mode-hook 'my-c-mode-hook) (add-hook 'scheme-mode-hook 'my-scheme-mode-hook) (add-hook 'emacs-lisp-mode-hook 'my-lisp-mode-hook) (add-hook 'lisp-mode-hook 'my-lisp-mode-hook) (add-hook 'perl-mode-hook 'my-perl-mode-hook) ;;;============================================================;;; ;;; USER INFO ;;;============================================================;;; (setq user-full-name "NAME") (setq user-mail-address "EMAIL.COM") ;;;------------------------------------------------------------;;; ;;; LANGUAGE ;;; Japanese ;;;(set-language-environment "Japanese") ;;;------------------------------------------------------------;;; ;;;------------------------------------------------------------;;; ;;; VIEW ;;; No startup message (setq inhibit-startup-message t) ;;; GUI font (set-default-font "Bitstream Vera Sans Mono-10") ;;; JP fonts (set-fontset-font (frame-parameter nil 'font) 'japanese-jisx0208 '("M+2VM+IPAG circle" . "unicode-bmp")) ;;; zh-CN fonts (set-fontset-font (frame-parameter nil 'font) 'han '("Vera Sans YuanTi Mono" . "unicode-bmp")) ;;;;===========================================================;;;; ;;; cjk-misc fonts (set-fontset-font (frame-parameter nil 'font) 'cjk-misc '("Vera Sans YuanTi Mono" . "unicode-bmp")) ;;; bopomofo fonts (set-fontset-font (frame-parameter nil 'font) 'bopomofo '("Vera Sans YuanTi Mono" . "unicode-bmp")) ;;; symbol fonts (set-fontset-font (frame-parameter nil 'font) 'symbol '("Vera Sans YuanTi Mono" . "unicode-bmp")) ;;;;=========================================================;;;; ;;; colorscheme (require 'color-theme) (color-theme-jedit-grey) ;;; No meno on console (or window-system (menu-bar-mode 0)) ;;;------------------------------------------------------------;;; ;;;------------------------------------------------------------;;; ;;; FRAMESIZE ;;;------------------------------------------------------------;;; (defun set-frame-size-according-to-resolution () (interactive) (if window-system (progn ;; use 120 char wide window for largeish displays ;; and smaller 80 column windows for smaller displays ;; pick whatever numbers make sense for you (if (> (x-display-pixel-width) 1280) (add-to-list 'default-frame-alist (cons 'width 120)) (add-to-list 'default-frame-alist (cons 'width 80))) ;; for the height, subtract a couple hundred pixels ;; from the screen height (for panels, menubars and ;; whatnot), then divide by the height of a char to ;; get the height we want (add-to-list 'default-frame-alist (cons 'height (/ (- (x-display-pixel-height) 200) (frame-char-height))))))) (set-frame-size-according-to-resolution) ;;;------------------------------------------------------------;;; ;;; CALENDAR ;;; Tokyo (setq calendar-latitude 35.35) (setq calendar-longitude 139.44) (setq calendar-location-name "Tokyo, JP") ;;; Japan (setq calendar-time-zone +540) (setq calendar-standard-time-zone-name "JST") (setq calendar-daylight-time-zone-name "JST") ;;;------------------------------------------------------------;;; ;;;============================================================;;; ;;; BACKUPS ;;;============================================================;;; ;;; Enanble backup files. (setq make-backup-files t) ;;; Enable versioning with default values (keep five last versions) (setq version-control t) ;;; Save all backup file in this directory (setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/")))) ;;; =========================================================== ;;; ;;; MODE LINE ;;; =========== Enable Line and Column Numbering ==========;;; ;;; Show line-number in the mode line (line-number-mode 1) ;;; Show column-number in the mode line (column-number-mode 1) ;;; =========================================================== ;;; ;;; AUTOFILL AND TEXT ;;; =========================================================== ;;; ;;; Auto return at 72 charactors (setq-default fill-column 72) ;; ----- Turn on Auto Fill mode automatically in all modes ----- ;; Auto-fill-mode the the automatic wrapping of lines and insertion of ;; newlines when the cursor goes over the column limit. ;; ;; This should actually turn on auto-fill-mode by default in all major ;; modes. The other way to do this is to turn on the fill for specific modes ;; via hooks. (setq auto-fill-mode 1) ;; ----- Make Text mode the default mode for new buffers ----- (setq default-major-mode 'text-mode) ;;; ============================================================ ;;; ;;; TERM MODE ;;; ============================================================ ;;; (require 'term) (global-set-key "\C-t" '(lambda ()(interactive)(ansi-term "/bin/bash"))) (defvar ansi-term-after-hook nil) (add-hook 'ansi-term-after-hook (function (lambda () (define-key term-raw-map "\C-t" '(lambda ()(interactive)(ansi-term "/bin/bash")))))) (defadvice ansi-term (after ansi-term-after-advice (arg)) "run hook as after advice" (run-hooks 'ansi-term-after-hook)) (ad-activate 'ansi-term) ;;;=================================================================;;; ;;; UNIX SETTINGS ;;;=================================================================;;; ;; TTY type terminal ;; tty keys change (if (and (not window-system) (not (equal system-type 'ms-dos))) (progn (if first-time (progn (keyboard-translate ?\C-h ?\C-?) (keyboard-translate ?\C-? ?\C-h))))) ;; Under UNIX ;; starting emacs-server (if (not (equal system-type 'ms-dos)) (progn (if first-time (server-start)))) ;;;-----------------------------------------------------------------;;; ;;; CEDET ;;;-----------------------------------------------------------------;;; ;; Load CEDET. ;; See cedet/common/cedet.info for configuration details. (require 'cedet) ;; Enable EDE (Project Management) features (global-ede-mode 1) ;; Enable EDE for a pre-existing C++ project ;; (ede-cpp-root-project "NAME" :file "~/myproject/Makefile") ;; Enabling Semantic (code-parsing, smart completion) features ;; Select one of the following: ;; * This enables the database and idle reparse engines (semantic-load-enable-minimum-features) ;; * This enables some tools useful for coding, such as summary mode ;; imenu support, and the semantic navigator (semantic-load-enable-code-helpers) ;; * This enables even more coding tools such as intellisense mode ;; decoration mode, and stickyfunc mode (plus regular code helpers) ;; (semantic-load-enable-gaudy-code-helpers) ;; * This enables the use of Exuberent ctags if you have it installed. ;; If you use C++ templates or boost, you should NOT enable it. ;; (semantic-load-enable-all-exuberent-ctags-support) ;; Or, use one of these two types of support. ;; Add support for new languges only via ctags. ;; (semantic-load-enable-primary-exuberent-ctags-support) ;; Add support for using ctags as a backup parser. ;; (semantic-load-enable-secondary-exuberent-ctags-support) ;; Enable SRecode (Template management) minor-mode. ;; (global-srecode-minor-mode 1) ;;; ============================================================ ;;; ;;; WEB BROWSER ;;; ;;; ============================================================ ;;; ;; standard install (require 'w3m-load) (require 'mime-w3m) ;; addons (require 'w3m-addons) ;; customizations (setq browse-url-browser-function 'w3m-browse-url) (autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t) ;; optional keyboard short-cut (global-set-key "\C-xm" 'browse-url-at-point) (setq w3m-use-cookies t) (setq w3m-coding-system 'utf-8 w3m-file-coding-system 'utf-8 w3m-file-name-coding-system 'utf-8 w3m-input-coding-system 'utf-8 w3m-output-coding-system 'utf-8 w3m-terminal-coding-system 'utf-8) (standard-display-ascii ?\225 [?+]) ;;;-----------------------------------------------------------------;;; ;;; ICICLES ;;;-----------------------------------------------------------------;;; ;;;;;;;;(byte-recompile-directory "~/.elisp/icicles/" 0) ;;(load-library "icicles") ;;;;;;;;(require 'icicles) ;;; --------------------------------------------------------------- ;;; ;;; SMALL TRICK ;;; --------------------------------------------------------------- ;;; (defun join-lines () (interactive) (let ((fill-column 999999)) (fill-paragraph nil))) ;;; =============================================================== ;;; ;;; Close up initilization ;;; =============================================================== ;;; ;; Indicate that this file has been read at least once (setq first-time nil) ;; No need to debug anything now (setq debug-on-error nil) ;; All done (message "All done, %s%s" (user-login-name) ".") ;;; End of .emacs (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(icicle-reminder-prompt-flag 4)) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. )