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 | |
| ;;==================== | |
| (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))) | |
| ;;==================== | |
| ;; General | |
| ;;==================== | |
| ;; load-pathを追加 | |
| (append-to-list load-path | |
| '("/usr/local/share/emacs/site-lisp" | |
| "/opt/local/share/emacs/site-lisp" | |
| "/opt/local/share/emacs/site-lisp/slime" | |
| "/opt/local/share/emacs/site-lisp/apel" | |
| "/opt/local/share/emacs/23.1/site-lisp/emu" | |
| "~/.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) | |
| ;; 終了してもカーソル位置を記録 | |
| (require 'session) | |
| (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) | |
| (add-hook 'after-init-hook 'session-initialize) | |
| ;; "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) | |
| (iswitchb-default-keybindings) | |
| ;; 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) | |
| ;;; for Kayac Emacs | |
| ;; fullscreen | |
| (global-set-key (kbd "M-<RET>") 'ns-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)))) | |
| ;;==================== | |
| ;; Utilities | |
| ;;==================== | |
| ;; auto-install | |
| ;; elispのインストールを簡単に | |
| (require 'auto-install) | |
| (setq auto-install-directory "~/.emacs.d/elisp/") | |
| (auto-install-update-emacswiki-package-name t) | |
| (auto-install-compatibility-setup) | |
| ;; outputz | |
| (require 'outputz) | |
| (setq outputz-key "My Private Key") | |
| (setq outputz-uri "http://%s/emacs.%s") | |
| (global-outputz-mode t) | |
| (remove-hook 'after-save-hook 'outputz) | |
| (add-hook 'kill-buffer-hook 'outputz) | |
| (defvar my-before-kill-emacs-hook nil | |
| "Hook to run before `save-buffers-kill-emacs'.") | |
| (defun outputz-buffers () | |
| (dolist (buf (buffer-list)) | |
| (with-current-buffer buf | |
| (outputz)))) | |
| (add-hook 'my-before-kill-emacs-hook 'outputz-buffers) | |
| (defadvice save-buffers-kill-emacs (around before-kill-emacs-hook activate) | |
| (run-hook 'my-before-kill-emacs-hook) | |
| (sleep-for 1) | |
| ad-do-it) | |
| (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 | |
| (require 'anything-startup) | |
| ;; cua-mode | |
| ;; 矩形選択を簡単に | |
| (cua-mode t) | |
| (setq cua-enable-cua-keys nil) | |
| ;; current-string-to | |
| (require 'current-string-to) | |
| ;; auto-complete | |
| ;; 補完候補を自動ポップアップ | |
| (require '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をポップアップ | |
| (require '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風のインターフェイスを使う | |
| (setq elscreen-prefix-key "\C-z") | |
| (require 'elscreen) | |
| (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) | |
| (autoload 'gtags-mode "gtags" "" t) | |
| (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))) | |
| (add-hook-fn 'c-mode-common-hook | |
| (gtags-mode 1) | |
| (gtags-make-complete-list)) | |
| ;; w3m | |
| (load "w3m") | |
| (setq w3m-use-cookies t) | |
| (setq browse-url-browser-function 'w3m-browse-url) | |
| ;; org-mode | |
| ;; Emacsでメモ・TODO管理 | |
| (require '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 | |
| (require 'color-moccur) | |
| (setq moccur-split-word t) ;; 複数の検索語や、特定のフェイスのみマッチ | |
| ;; migemo | |
| (if (require 'migemo nil t) | |
| (setq moccur-use-migemo t)) | |
| ;; anything-c-moccur | |
| (require '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の設定 | |
| (require '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、改行表示 | |
| (require '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 | |
| ;;==================== | |
| (defun my-set-fontset () | |
| (create-fontset-from-ascii-font | |
| "-apple-monaco-medium-normal-normal-*-12-*" nil "hirakaku12") | |
| (set-default-font "fontset-hirakaku12") | |
| (add-to-list 'default-frame-alist '(font . "fontset-hirakaku12")) | |
| (set-fontset-font | |
| "fontset-hirakaku12" | |
| 'japanese-jisx0208 | |
| "-apple-hiragino_kaku_gothic_pro-medium-normal-normal-*-14-*-iso10646-1") | |
| (set-fontset-font | |
| "fontset-hirakaku12" | |
| 'jisx0201 | |
| "-apple-hiragino_kaku_gothic_pro-medium-normal-normal-*-14-*-iso10646-1") | |
| (set-fontset-font | |
| "fontset-hirakaku12" | |
| 'japanese-jisx0212 | |
| "-apple-hiragino_kaku_gothic_pro-medium-normal-normal-*-14-*-iso10646-1") | |
| (set-fontset-font | |
| "fontset-hirakaku12" | |
| 'katakana-jisx0201 | |
| "-apple-hiragino_kaku_gothic_pro-medium-normal-normal-*-14-*-iso10646-1")) | |
| (when window-system | |
| (server-start) ;; Emacs serverを起動 | |
| (set-frame-parameter nil 'alpha 80) ;; フレームを透過 | |
| (tool-bar-mode 0) ;; ツールバーを消す | |
| (toggle-scroll-bar nil) ;; スクロールバーを消す | |
| (if (= emacs-major-version 23) (my-set-fontset))) ;; フォント設定 | |
| ;;==================== | |
| ;; Syntax | |
| ;;==================== | |
| ;; lisp (slime) | |
| (require '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 | |
| (autoload 'php-mode "php-mode") | |
| (setq php-mode-force-pear t) | |
| (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))) | |
| (add-hook-fn 'php-mode-hook | |
| (setq c-basic-offset 2) | |
| (setq c-tab-width 2) | |
| (setq c-indent-level 2) | |
| (setq 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)) | |
| (require 'symfony) | |
| ;; ruby | |
| (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode)) | |
| (autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process") | |
| (autoload 'inf-ruby-keys "inf-ruby" | |
| "Set local key defs for inf-ruby in ruby-mode") | |
| (add-hook-fn 'ruby-mode-hook (inf-ruby-keys)) | |
| (require 'ruby-electric) | |
| (add-hook-fn 'ruby-mode-hook (ruby-electric-mode t)) | |
| (require '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 | |
| (require '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 | |
| (require 'tex-site) | |
| (require 'tex-jp) | |
| (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 | |
| (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 | |
| (require 'flymake) | |
| (global-set-key "\C-cd" 'flymake-display-err-menu-for-current-line) | |
| (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))))) | |
| ;; 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