-
-
Save shishi/989046 to your computer and use it in GitHub Desktop.
This file contains 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
(setenv "CLOJURE_EXT" (concat (getenv "HOME") "/.clojure")) | |
;;==================== | |
;; 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 req (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) | |
(eval-after-load ,lib | |
'(progn | |
,@body)))) | |
(defmacro global-set-key-fn (key args &rest body) | |
`(global-set-key ,key (lambda ,args ,@body))) | |
;;==================== | |
;; General | |
;;==================== | |
;; load-pathを追加 | |
(append-to-list load-path '("~/.emacs.d/" | |
"~/.emacs.d/elisp" | |
"~/.emacs.d/elisp/emacs-jabber" | |
"~/.emacs.d/elisp/clojure-mode" | |
"~/.clojure/swank-clojure")) | |
(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 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))) | |
;; 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) | |
;; .emacs.elの保存時にbyte compile | |
(add-hook-fn 'after-save-hook | |
(if (string= (expand-file-name "~/.emacs.el") | |
(buffer-file-name)) | |
(save-excursion | |
(byte-compile-file "~/.emacs.el")))) | |
;; kill-ring一覧を表示 | |
(global-set-key-fn (kbd "M-y") nil (interactive) (anything-show-kill-ring)) | |
;; モード行に時刻を表示 | |
(setq display-time-string-forms '(month "/" day " " dayname " " 24-hours ":" minutes)) | |
(display-time) | |
;;; 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 "C-c m") 'toggle-fullscreen) | |
(toggle-fullscreen) | |
;; よく使うモード | |
(defvar 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) | |
;; ウィンドウ内のカーソル移動 | |
(global-set-key-fn (kbd "C-M-h") nil (interactive) (move-to-window-line 0)) | |
(global-set-key-fn (kbd "C-M-m") nil (interactive) (move-to-window-line nil)) | |
(global-set-key-fn (kbd "C-M-l") nil (interactive) (move-to-window-line -1)) | |
;; 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 | |
;;==================== | |
;; tramp | |
(req tramp) | |
;; redmine | |
(lazyload (redmine-show-issues-all | |
redmine-show-activity | |
redmine-show-revisions | |
redmine-select-project) "redmine" | |
(load "redmine-conf")) | |
;; auto-install | |
;; elispのインストールを簡単に | |
(lazyload (auto-install-from-url | |
auto-install-from-emacswiki | |
auto-install-from-dired | |
auto-install-from-directory | |
auto-install-from-buffer | |
auto-install-from-gist | |
auto-install-batch) "auto-install" | |
(setq auto-install-directory "~/.emacs.d/elisp/") | |
(auto-install-update-emacswiki-package-name t) | |
(auto-install-compatibility-setup)) | |
;; 終了してもカーソル位置を記録 | |
(req 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)) | |
;; redo | |
(req redo | |
(global-set-key "\C-]" 'redo)) | |
;; outputz | |
(req outputz | |
(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") | |
(load "outputz-conf")) | |
;; anything | |
(req anything-startup) | |
;; cua-mode | |
;; 矩形選択を簡単に | |
(cua-mode t) | |
(setq cua-enable-cua-keys nil) | |
;; auto-complete | |
;; 補完候補を自動ポップアップ | |
(req auto-complete | |
(global-auto-complete-mode t) | |
(append-to-list ac-modes '(js-mode php-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をポップアップ | |
(lazyload (shell-pop) "shell-pop" | |
(shell-pop-set-internal-mode "ansi-term") | |
(shell-pop-set-internal-mode-shell "/bin/zsh") | |
(shell-pop-set-window-height 60) | |
(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) | |
;; SQL | |
(setq sql-user "fukamachi") | |
(setq sql-server "localhost") | |
;; ElScreen | |
;; EmacsでGNU screen風のインターフェイスを使う | |
(req 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回同じ操作をすると自動でマクロ登録 | |
(lazyload (dmacro-exec) "dmacro") | |
(defconst *dmacro-key* "\C-q") | |
(global-set-key *dmacro-key* 'dmacro-exec) | |
;; global | |
;; 関数定義に飛ぶ (gtags) | |
(lazyload (gtags-mode) "gtags" | |
(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 t) | |
(eval-after-load "gtags-mode" '(gtags-make-complete-list))) | |
;; 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" | |
(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") | |
("Memo" ?m "** %?\n :Memo:\n %t" nil "Memo")))) | |
(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) | |
;; color-moccur.el | |
(req color-moccur | |
(setq moccur-split-word t)) ;; 複数の検索語や、特定のフェイスのみマッチ | |
;; migemo | |
(req migemo | |
(setq migemo-command "cmigemo" | |
migemo-options '("-q" "--emacs" "-i" "\a") | |
migemo-dictionary "/usr/local/share/migemo/euc-jp/migemo-dict" | |
migemo-user-dictionary nil | |
migemo-regex-dictionary nil | |
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)) | |
;; twittering-mode | |
(lazyload (twit) "twittering-mode" | |
(twittering-jojo-mode t) | |
(setq twittering-username "nitro_idiot") | |
(setq twittering-timer-interval nil) | |
(setq twittering-retweet-format " RT @%s: %t")) | |
;; emacs-jabber | |
(lazyload (jabber-connect) "jabber" | |
(load "jabber-conf")) | |
;; erc | |
(lazyload (erc) "erc" | |
(setq erc-server "irc.tokyo.wide.ad.jp" | |
erc-nick-uniquifier "_" | |
erc-port "6667" | |
erc-prompt-for-password nil | |
erc-server-coding-system '(iso-2022-jp . iso-2022-jp)) | |
(load "erc-conf")) | |
;;==================== | |
;; Visual | |
;;==================== | |
;; color-themeの設定 | |
(req color-theme | |
(and (functionp 'color-theme-initialize) (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 t) | |
;; 全角空白、Tab、改行表示 | |
(req jaspace | |
(setq jaspace-alternate-jaspace-string "□" | |
jaspace-alternate-eol-string "↓\n" | |
jaspace-highlight-tabs t) | |
(append-to-list jaspace-modes (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 | |
;;==================== | |
;; clojure | |
(req clojure-mode | |
(setq clojure-src-root (expand-file-name "~/.clojure"))) | |
(req swank-clojure | |
(setq swank-clojure-jar-path "~/.clojure/clojure.jar" | |
swank-clojure-extra-classpaths '("~/.clojure/clojure-contrib.jar")) | |
(setq slime-lisp-implementations '((clojure ("/usr/local/bin/clj"))))) | |
(lazyload (slime) "slime" | |
(slime-setup '(slime-repl))) | |
;; php-mode | |
(lazyload (php-mode) "php-mode" | |
(req symfony)) | |
(add-hook-fn 'php-mode-hook | |
(setq tab-width 2) | |
(c-set-offset 'substatement-open 0) | |
(c-set-offset 'block-open '+) | |
(c-set-offset 'case-label 1) | |
(c-set-offset 'statement-case-open 0) | |
(c-set-offset 'arglist-intro '+) | |
(c-set-offset 'arglist-close 0)) | |
;; 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") | |
(lazyload (ruby-block-mode) "ruby-block" | |
(setq ruby-block-highlight-toggle t)) | |
(add-hook-fn 'ruby-mode-hook (ruby-electric-mode t) (ruby-block-mode t)) | |
(lazyload (rubydb) "rubydb3x") | |
;; js2-mode | |
(setq js-indent-level 2) | |
;; yaml-mode | |
(lazyload (yaml-mode) "yaml-mode") | |
;; css-mode | |
(lazyload (css-mode) "css-mode" | |
(setq cssm-indent-function 'cssm-c-style-indenter)) | |
;; mmm-mode | |
(req 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)))) | |
`(eval-after-load "flymake" | |
(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)) | |
;; 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