Created
February 15, 2010 02:59
-
-
Save fukamachi/304391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;==================== | |
| ;; Functions | |
| ;;==================== | |
| (eval-when-compile (require 'cl)) | |
| (defmacro add-hook-fn (name &rest body) | |
| `(add-hook ,name (lambda () ,@body))) | |
| (defmacro append-to-list (to lst) | |
| `(setq ,to (append ,lst ,to))) | |
| (defmacro ifload (lib &rest body) | |
| `(when (locate-library ,(symbol-name lib)) | |
| (require ',lib) ,@body)) | |
| (defmacro lazyload (func lib &rest body) | |
| `(when (locate-library ,lib) | |
| ,@(mapcar (lambda (f) `(autoload ',f ,lib nil t)) func) | |
| ,@body)) | |
| (defmacro global-set-key-fn (key args &rest body) | |
| `(global-set-key ,key (lambda ,args ,@body))) | |
| ;;==================== | |
| ;; General | |
| ;;==================== | |
| ;; load-pathを追加 | |
| (add-to-list 'load-path "~/.emacs.d/elisp") | |
| (append-to-list exec-path | |
| '("/usr/bin" "/bin" | |
| "/usr/sbin" "/sbin" "/usr/local/bin" | |
| "/usr/X11/bin")) | |
| ;; テキストエンコーディングとしてUTF-8を優先使用 | |
| (prefer-coding-system 'utf-8) | |
| ;; 起動時のメッセージを非表示 | |
| (setq inhibit-startup-message t) | |
| ;; zshを使う | |
| (setq shell-file-name "/bin/zsh") | |
| ;; Tabの代わりにスペースでインデント | |
| (setq-default indent-tabs-mode nil) | |
| (setq-default tab-width 2 indent-tabs-mode nil) | |
| ;; shell-modeでpasswordを隠す | |
| (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt) | |
| ;; C-kで行全体を削除 | |
| (setq kill-whole-line t) | |
| ;; "yes or no"を"y or n"に | |
| (fset 'yes-or-no-p 'y-or-n-p) | |
| ;; minibufferでC-wで前の単語を削除 | |
| (define-key minibuffer-local-completion-map "\C-w" 'backward-kill-word) | |
| ;; 改行コードを表示 | |
| (setq eol-mnemonic-dos "(CRLF)" | |
| eol-mnemonic-mac "(CR)" | |
| eol-mnemonic-unix "(LF)") | |
| ;; 1行ずつスクロール | |
| (setq scroll-conservatively 35 | |
| scroll-margin 0 | |
| scroll-step 1) | |
| (setq comint-scroll-show-maximum-output t) ;; for shell-mode | |
| ;; *scratch*を消さない | |
| (defun my-make-scratch (&optional arg) | |
| ;; "*scratch*" を作成して buffer-list に放り込む | |
| (set-buffer (get-buffer-create "*scratch*")) | |
| (funcall initial-major-mode) | |
| (erase-buffer) | |
| (when (and initial-scratch-message (not inhibit-startup-message)) | |
| (insert initial-scratch-message)) | |
| (or arg (progn (setq arg 0) | |
| (switch-to-buffer "*scratch*"))) | |
| (cond ((= arg 0) (message "*scratch* is cleared up.")) | |
| ((= arg 1) (message "another *scratch* is created")))) | |
| (add-hook-fn 'kill-buffer-query-functions | |
| ;; *scratch* バッファで kill-buffer したら内容を消去するだけにする | |
| (if (string= "*scratch*" (buffer-name)) | |
| (progn (my-make-scratch 0) nil) | |
| t)) | |
| (add-hook-fn 'after-save-hook | |
| ;; *scratch* バッファの内容を保存したら *scratch* バッファを新しく作る | |
| (unless (member (get-buffer "*scratch*") (buffer-list)) | |
| (my-make-scratch 1))) | |
| ;; C-x bでミニバッファにバッファ候補を表示 | |
| (iswitchb-mode t) | |
| ;; beepを消す | |
| (defun my-bell-function () | |
| (unless (memq this-command | |
| '(isearch-abort abort-recursive-edit exit-minibuffer | |
| keyboard-quit mwheel-scroll down up next-line previous-line | |
| backward-char forward-char)) | |
| (ding))) | |
| (setq ring-bell-function 'my-bell-function) | |
| ;; \C-aでインデントを飛ばした行頭に移動 | |
| (defun beginning-of-indented-line (current-point) | |
| "インデント文字を飛ばした行頭に戻る。ただし、ポイントから行頭までの間にインデント文字しかない場合は、行頭に戻る。" | |
| (interactive "d") | |
| (if (string-match | |
| "^[ ¥t]+$" | |
| (save-excursion | |
| (buffer-substring-no-properties | |
| (progn (beginning-of-line) (point)) | |
| current-point))) | |
| (beginning-of-line) | |
| (back-to-indentation))) | |
| (defun beginning-of-visual-indented-line (current-point) | |
| "インデント文字を飛ばした行頭に戻る。ただし、ポイントから行頭までの間にインデント文 字しかない場合は、行頭に戻る。" | |
| (interactive "d") | |
| (let ((vhead-pos (save-excursion (progn (beginning-of-visual-line) (point)))) | |
| (head-pos (save-excursion (progn (beginning-of-line) (point))))) | |
| (cond | |
| ;; 物理行の1行目にいる場合 | |
| ((eq vhead-pos head-pos) | |
| (if (string-match | |
| "^[ ¥t]+$" | |
| (buffer-substring-no-properties vhead-pos current-point)) | |
| (beginning-of-visual-line) | |
| (back-to-indentation))) | |
| ;; 物理行の2行目以降の先頭にいる場合 | |
| ((eq vhead-pos current-point) | |
| (backward-char) | |
| (beginning-of-visual-indented-line (point))) | |
| ;; 物理行の2行目以降の途中にいる場合 | |
| (t (beginning-of-visual-line))))) | |
| (global-set-key "\C-a" 'beginning-of-visual-indented-line) | |
| (global-set-key "\C-e" 'end-of-visual-line) | |
| ;;; for Mac | |
| ;; Command-Key and Option-Key | |
| (setq ns-command-modifier 'meta) | |
| (setq ns-alternate-modifier 'super) | |
| ;; fullscreen | |
| (defun toggle-fullscreen () | |
| (interactive) | |
| (if (frame-parameter nil 'fullscreen) | |
| (set-frame-parameter nil 'fullscreen nil) | |
| (set-frame-parameter nil 'fullscreen 'fullboth))) | |
| (global-set-key (kbd "M-<RET>") 'toggle-fullscreen) | |
| ;; よく使うモード | |
| (setq my-fav-modes | |
| '((scheme-mode . "\\.scm$") | |
| (php-mode . "\\.php[45]?$") | |
| (yaml-mode . "\\.ya?ml$") | |
| (js-mode . "\\.js$") | |
| (ruby-mode . "\\.rb$") | |
| (text-mode . "\\.txt$") | |
| (fundamental-mode . nil) | |
| (LaTeX-mode . "\\.tex$") | |
| (org-mode . "\\.org$") | |
| (css-mode . "\\.css$") | |
| (nxml-mode . "\\.\(xml\|svg\|wsdl\|xslt\|wsdd\|xsl\|rng\|xhtml\)\'"))) | |
| ;; auto-mode-alist | |
| (loop for (k . v) in my-fav-modes | |
| do (unless (null v) (add-to-list 'auto-mode-alist (cons v k)))) | |
| ;; 分割したウィンドウ間をShift + 矢印で移動 | |
| (windmove-default-keybindings) | |
| (setq windmove-wrap-around t) | |
| ;; ウィンドウ内のカーソル移動 | |
| (defun point-to-top () | |
| (interactive) | |
| (move-to-window-line 0)) | |
| (defun point-to-middle () | |
| (interactive) | |
| (move-to-window-line nil)) | |
| (defun point-to-bottom () | |
| (interactive) | |
| (move-to-window-line -1)) | |
| (global-set-key "\M-," 'point-to-top) | |
| (global-set-key "\M-." 'point-to-middle) | |
| (global-set-key "\M-/" 'point-to-bottom) | |
| ;; goto-lineをM-gに | |
| (global-set-key-fn "\M-g" (x) (interactive "nLine: ") (goto-line x)) | |
| ;; C-x pで前のウィンドウへ移動(C-x oの逆) | |
| (global-set-key-fn "\C-xp" nil (interactive) (other-window -1)) | |
| ;;==================== | |
| ;; Utilities | |
| ;;==================== | |
| ;; auto-install | |
| ;; elispのインストールを簡単に | |
| (ifload auto-install | |
| (setq auto-install-directory "~/.emacs.d/elisp/") | |
| (auto-install-update-emacswiki-package-name t) | |
| (auto-install-compatibility-setup)) | |
| ;; 終了してもカーソル位置を記録 | |
| (ifload session | |
| (add-hook 'after-init-hook 'session-initialize) | |
| (setq session-initialize '(de-saveplace session keys menus places) | |
| session-globals-include '((kill-ring 50) | |
| (session-file-alist 500 t) | |
| (file-name-history 10000)) | |
| session-globals-max-string 100000000 | |
| history-length t | |
| session-undo-check -1)) | |
| ;; outputz | |
| (ifload outputz | |
| (setq outputz-key "DfiWDT31oxi.") | |
| (setq outputz-uri "http://%s/emacs.%s") | |
| (global-outputz-mode t) | |
| (defadvice outputz (before outputz-setup-uri) | |
| (setq outputz-uri | |
| (format outputz-uri | |
| (replace-regexp-in-string "-mode$" "" (symbol-name major-mode)) | |
| (system-name)))) | |
| (ad-activate-regexp "outputz-setup-uri")) | |
| ;; anything | |
| (ifload anything-startup) | |
| ;; cua-mode | |
| ;; 矩形選択を簡単に | |
| (cua-mode t) | |
| (setq cua-enable-cua-keys nil) | |
| ;; current-string-to | |
| (ifload current-string-to) | |
| ;; auto-complete | |
| ;; 補完候補を自動ポップアップ | |
| (ifload auto-complete | |
| (global-auto-complete-mode t) | |
| (add-to-list 'ac-modes 'js-mode)) | |
| ;; auto-insert | |
| ;; ファイル形式に応じて自動でテンプレート挿入 | |
| (add-hook 'find-file-hooks 'auto-insert) | |
| (setq auto-insert-directory "~/.emacs.d/templates" | |
| auto-insert-alist | |
| '((perl-mode . "perl-template.pl") | |
| (html-mode . "html-template.html") | |
| ("base.css" . "base.css") | |
| (css-mode . "css-template.css"))) | |
| ;; shell-pop | |
| ;; C-tでshellをポップアップ | |
| (ifload shell-pop | |
| (shell-pop-set-internal-mode "ansi-term") | |
| (shell-pop-set-internal-mode-shell "/bin/zsh") | |
| (defvar ansi-term-after-hook nil) | |
| (add-hook-fn 'ansi-term-after-hook | |
| (define-key term-raw-map "\C-t" 'shell-pop)) | |
| (defadvice ansi-term (after ansi-term-after-advice (org)) | |
| "run hook as after advice" | |
| (run-hooks 'ansi-term-after-hook)) | |
| (ad-activate 'ansi-term) | |
| (global-set-key "\C-t" 'shell-pop)) | |
| ;; ElScreen | |
| ;; EmacsでGNU screen風のインターフェイスを使う | |
| (ifload elscreen | |
| (setq elscreen-prefix-key "\C-z") | |
| (if window-system | |
| (define-key elscreen-map "\C-z" 'iconify-or-deiconify-frame) | |
| (define-key elscreen-map "\C-z" 'suspend-emacs))) | |
| ;; dmacro | |
| ;; 2回同じ操作をすると自動でマクロ登録 | |
| (defconst *dmacro-key* "\C-q") | |
| (global-set-key *dmacro-key* 'dmacro-exec) | |
| (autoload 'dmacro-exec "dmacro" nil t) | |
| ;; global | |
| ;; 関数定義に飛ぶ (gtags) | |
| (lazyload (gtags-mode) "gtags" | |
| (add-hook-fn 'c-mode-common-hook | |
| (gtags-mode 1) | |
| (gtags-make-complete-list)) | |
| (setq gtags-mode-hook | |
| (lambda () | |
| (local-set-key "\C-cf" 'gtags-find-tag) | |
| (local-set-key "\M-r" 'gtags-find-rtag) | |
| (local-set-key "\M-s" 'gtags-find-symbol) | |
| (local-set-key "\C-cp" 'gtags-pop-stack)))) | |
| ;; w3m | |
| (lazyload (w3m w3m-browse-url w3m-find-file w3m-search) "w3m" | |
| (setq w3m-use-cookies t) | |
| (setq browse-url-browser-function 'w3m-browse-url)) | |
| ;; org-mode | |
| ;; Emacsでメモ・TODO管理 | |
| (lazyload (org-store-link org-agenda org-remember) "org-install" | |
| (define-key global-map "\C-cl" 'org-store-link) | |
| (define-key global-map "\C-ca" 'org-agenda) | |
| (define-key global-map "\C-cr" 'org-remember) | |
| (setq org-startup-truncated nil | |
| org-return-follows-link t) | |
| (org-remember-insinuate) | |
| (setq org-directory "~/Dropbox/memo/") | |
| (setq org-default-notes-file (concat org-directory "notes.org")) | |
| (setq org-agenda-files `(,org-default-notes-file)) | |
| (setq org-remember-templates | |
| '(("Todo" ?t "** TODO %?\n %i\n %a\n %t" nil "Inbox") | |
| ("Bug" ?b "** TODO %? :bug:\n %i\n %a\n %t" nil "Inbox") | |
| ("Idea" ?i "** %?\n %i\n %a\n %t" nil "New Ideas")))) | |
| ;;; color-moccur.el | |
| (ifload color-moccur | |
| (setq moccur-split-word t)) ;; 複数の検索語や、特定のフェイスのみマッチ | |
| ;; migemo | |
| (ifload migemo | |
| (setq moccur-use-migemo t)) | |
| ;; anything-c-moccur | |
| (lazyload (anything-c-moccur-occur-by-moccur | |
| anything-c-moccur-dmoccur | |
| anything-c-moccur-dired-do-moccur-by-moccur) "anything-c-moccur" | |
| (setq anything-c-moccur-anything-idle-delay 0.2 ;`anything-idle-delay' | |
| anything-c-moccur-higligt-info-line-flag t ; `anything-c-moccur-dmoccur'などのコマンドでバッファ情報をハイライト | |
| anything-c-moccur-enable-auto-look-flag t ; 現在選択中の候補の位置を他のwindowに表示 | |
| anything-c-moccur-enable-initial-pattern t)) ; `anything-c-moccur-occur-by-moccur'の起動時にポイントの位置の単語を初期パターンにする | |
| (global-set-key (kbd "M-o") 'anything-c-moccur-occur-by-moccur) ;バッファ内検索 | |
| (global-set-key (kbd "C-M-o") 'anything-c-moccur-dmoccur) ;ディレクトリ | |
| (add-hook-fn 'dired-mode-hook ;dired | |
| (local-set-key (kbd "O") 'anything-c-moccur-dired-do-moccur-by-moccur)) | |
| ;;==================== | |
| ;; Visual | |
| ;;==================== | |
| ;; color-themeの設定 | |
| (ifload color-theme | |
| (color-theme-initialize) | |
| (color-theme-arjen)) | |
| ;; キーワードのカラー表示を有効化 | |
| (global-font-lock-mode t) | |
| ;; 選択範囲をハイライト | |
| (setq-default transient-mark-mode t) | |
| ;; バッファ一覧をまともに | |
| (global-set-key "\C-x\C-b" 'bs-show) | |
| ;; 対応するカッコをハイライト | |
| (show-paren-mode 1) | |
| ;; 全角空白、Tab、改行表示 | |
| (ifload jaspace | |
| (setq jaspace-alternate-jaspace-string "□" | |
| jaspace-alternate-eol-string "↓\n" | |
| jaspace-highlight-tabs t) | |
| (append-to-list jaspace-mode (mapcar 'car my-fav-modes))) | |
| ;; カーソル行をハイライト | |
| (defface hlline-face | |
| '((((class color) | |
| (background dark)) | |
| (:background "dark slate gray")) | |
| (((class color) | |
| (background light)) | |
| (:background "ForestGreen")) | |
| (t | |
| ())) | |
| "*Face used by hl-line.") | |
| (setq hl-line-face 'hlline-face) | |
| (global-hl-line-mode) | |
| ;;==================== | |
| ;; Window System | |
| ;;==================== | |
| (when window-system | |
| (server-start) ;; Emacs serverを起動 | |
| (set-frame-parameter nil 'alpha 80) ;; フレームを透過 | |
| (menu-bar-mode 0) ;; メニューバーを消す | |
| (tool-bar-mode 0) ;; ツールバーを消す | |
| (toggle-scroll-bar nil)) ;; スクロールバーを消す | |
| ;;==================== | |
| ;; Syntax | |
| ;;==================== | |
| ;; lisp (slime) | |
| (lazyload (slime-autoloads) "slime-autoloads" | |
| (setq slime-lisp-implementations | |
| `((sbcl ("/usr/local/bin/sbcl")))) | |
| (add-hook-fn 'lisp-mode-hook | |
| (cond ((not (featurep 'slime)) | |
| (require 'slime) | |
| (normal-mode)))) | |
| (eval-after-load "slime" | |
| '(slime-setup '(slime-fancy slime-banner)))) | |
| ;; php-mode | |
| (lazyload (php-mode) "php-mode" | |
| (add-hook-fn 'php-mode-hook | |
| (require 'php-completion) | |
| (php-completion-mode t) | |
| (define-key php-mode-map (kbd "C-o") 'phpcmp-complete) | |
| (when (require 'auto-complete nil t) | |
| (make-variable-buffer-local 'ac-sources) | |
| (add-to-list 'ac-sources 'ac-source-php-completion) | |
| (auto-complete-mode t)) | |
| (setq c-basic-offset 2 | |
| c-tab-width 2 | |
| c-indent-level 2 | |
| tab-width 2) | |
| (setq-default tab-width 2) | |
| (c-set-offset 'substatement-open 0) | |
| (c-set-offset 'block-open 0) | |
| (c-set-offset 'case-label '+) | |
| (c-set-offset 'statement-case-open 0)) | |
| (setq php-mode-force-pear t)) | |
| (ifload symfony) | |
| ;; ruby | |
| (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode)) | |
| (lazyload (run-ruby inf-ruby-keys) "inf-ruby" | |
| (add-hook-fn 'ruby-mode-hook (inf-ruby-keys))) | |
| (lazyload (ruby-electric-mode) "ruby-electric" | |
| (add-hook-fn 'ruby-mode-hook (ruby-electric-mode t))) | |
| (lazyload (ruby-block-mode) "ruby-block" | |
| (ruby-block-mode t) | |
| (setq ruby-block-highlight-toggle t)) | |
| (autoload 'rubydb "rubydb3x" | |
| "run rubydb on program file in buffer *gud-file*. | |
| the directory containing file becomes the initial working directory | |
| and source-file directory for your debugger." t) | |
| ;; js2-mode | |
| (setq js-indent-level 2) | |
| ;; yaml-mode | |
| (autoload 'yaml-mode "yaml-mode") | |
| ;; css-mode | |
| (autoload 'css-mode "css-mode") | |
| (setq cssm-indent-function 'cssm-c-style-indenter) | |
| ;; mmm-mode | |
| (ifload mmm-auto | |
| (setq mmm-global-mode 'maybe) | |
| (mmm-add-classes | |
| '((embedded-css | |
| :submode css-mode | |
| :front "<style[^>] *>" | |
| :back "<style>"))) | |
| (mmm-add-mode-ext-class nil "\\.html\\'" 'embedded-css)) | |
| ;; AUCTeX | |
| (lazyload (japanese-latex-mode) "tex-site" | |
| (setq TeX-default-mode 'japanese-latex-mode) | |
| (setq japanese-LaTeX-command-default "platex") | |
| (setq japanese-LaTeX-default-style "jarticle") | |
| (setq kinsoku-limit 10) | |
| (setq LaTeX-indent-level 4) | |
| (setq LaTeX-item-indent 2) | |
| (setq TeX-output-view-style '(("^dvi$" "." "pxdvi '%d'"))) | |
| (setq preview-image-type 'dvipng) | |
| (add-hook-fn 'LaTeX-mode-hook | |
| (require 'tex-jp) | |
| (add-to-list 'TeX-command-list | |
| '("ptex" "%(PDF)ptex %`%S%(PDFout)%(mode)%' %t" | |
| TeX-run-TeX nil (plain-tex-mode) :help "Run ASCII pTeX")) | |
| (add-to-list 'TeX-command-list | |
| '("platex" "%(PDF)platex %`%S%(PDFout)%(mode)%' %t" | |
| TeX-run-TeX nil (latex-mode) :help "Run ASCII pLaTeX")) | |
| (add-to-list 'TeX-command-list | |
| '("pdfview" "okular '%s.pdf' " TeX-run-command t nil)) | |
| (add-to-list 'TeX-command-list | |
| '("pdfbuild" "dvipdfmx -V 4 '%s' " TeX-run-command t nil)))) | |
| ;; nxml-mode | |
| (setq nxml-slash-auto-complete-flag t) | |
| ;; git commit | |
| (add-hook-fn 'server-visit-hook | |
| (if (string-match "COMMIT_EDITMSG" buffer-file-name) | |
| (set-buffer-file-coding-system 'utf-8))) | |
| ;;==================== | |
| ;; Syntax Checking | |
| ;;==================== | |
| ;; flymake | |
| (defmacro def-flymake-init (name masks exec error) | |
| (let ((init-name (intern (format "flymake-%s-init" name)))) | |
| `(when (not (fboundp ',init-name)) | |
| ,(unless (null masks) | |
| `(setq flymake-allowed-file-name-masks | |
| (append flymake-allowed-file-name-masks | |
| ',(mapcar (lambda (x) (list x init-name)) masks)))) | |
| (defun ,init-name () | |
| (let* ((temp-file (flymake-init-create-temp-buffer-copy | |
| 'flymake-create-temp-inplace)) | |
| (local-file (file-relative-name | |
| temp-file | |
| (file-name-directory buffer-file-name)))) | |
| ,exec)) | |
| ,(unless (null error) | |
| `(setq flymake-err-line-patterns | |
| (cons ',error flymake-err-line-patterns))) | |
| (add-hook-fn ',(intern (format "%s-mode-hook" name)) (flymake-mode t))))) | |
| (lazyload (flymake-mode) "flymake" | |
| (global-set-key "\C-cd" 'flymake-display-err-menu-for-current-line) | |
| (eval-after-load "flymake" | |
| '(progn | |
| ;; JavaScript | |
| (def-flymake-init js ("\.js$") | |
| `("jsl" ("-process" ,local-file)) | |
| ("\(.+\)(\([0-9]+\)): \(?:lint \)?\(\(?:Warning\|SyntaxError\):.+\)" 1 2 nil 3)) | |
| ;; PHP | |
| (def-flymake-init php ("\.php[345]?") | |
| `("php" ("-f" ,local-file "-l")) | |
| ("\(\(?:Parse error\|Fatal error\|Warning\): .*\) in \(.*\) on line \([0-9]+\)" 2 3 nil 1)) | |
| ;; Ruby | |
| (def-flymake-init ruby () | |
| `("ruby" ("-c" ,local-file)) nil)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment