Created
February 15, 2010 02:59
-
-
Save fukamachi/304391 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
(let ((default-directory (expand-file-name "~/Dropbox/home/.emacs.d"))) | |
(add-to-list 'load-path default-directory) | |
(load (expand-file-name "~/Dropbox/home/.emacs.d/subdirs.el") t t t)) | |
(if (file-exists-p (locate-library "init")) | |
(load (locate-library "init") nil t nil)) |
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
;;==================== | |
;; Functions | |
;;==================== | |
(eval-when-compile (require 'cl)) | |
(defun file-name-parent-directory (file-name &optional idx) | |
(nth (1+ (or idx 0)) (reverse (split-string file-name "/" t)))) | |
(defun upper-camelcase (str) | |
(replace-regexp-in-string "-" "" (capitalize str))) | |
(defun escape-single-quoted (text) | |
(replace-regexp-in-string | |
"'" "\\\\'" (replace-regexp-in-string "\\\\" "\\\\\\\\" text))) | |
(defun yas/field-current () | |
(overlay-get yas/active-field-overlay 'yas/field)) | |
(defun yas/field-current-number () | |
(yas/field-number (yas/field-current))) | |
(defvar yas/replace-prev-field-by nil) | |
(defun yas/replace-prev-field (to) | |
(setq yas/replace-prev-field-by to) | |
(add-hook 'post-command-hook 'yas/replace-prev-field-once 'append 'local) | |
"") | |
(defun yas/replace-prev-field-once () | |
(let ((to yas/replace-prev-field-by) | |
(from (yas/field-value (1- (yas/field-current-number))))) | |
(search-backward from nil t) | |
(replace-match | |
(if (functionp to) (funcall to from) to) nil t) | |
(yas/next-field)) | |
(setq yas/replace-prev-field-by nil) | |
(remove-hook 'post-command-hook 'yas/replace-prev-field-once 'local)) | |
(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 t)) | |
(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)) t)) | |
(defmacro global-set-key-fn (key &rest body) | |
`(global-set-key ,key (lambda () (interactive) ,@body))) | |
(defmacro defadvice-many (fn-lst class &rest body) | |
`(progn | |
,@(mapcar | |
(lambda (fn) | |
`(defadvice ,fn (,class ,(intern (concat (symbol-name fn) "-" (symbol-name class) "-advice")) activate) | |
,@body)) fn-lst))) | |
;;==================== | |
;; General | |
;;==================== | |
;; load-pathを追加 | |
(let ((default-directory (expand-file-name "~/.emacs.d"))) | |
(add-to-list 'load-path default-directory) | |
(load (expand-file-name "~/.emacs.d/subdirs.el") t t t)) | |
;; exec-path | |
(loop for x in (reverse | |
(split-string (substring (shell-command-to-string "echo $PATH") 0 -1) ":")) | |
do (add-to-list 'exec-path x)) | |
(lazyload (e2wm:start-management) "e2wm" | |
(e2wm:add-keymap | |
e2wm:pst-minor-mode-keymap | |
'(("M-h" . e2wm:dp-code) ; codeへ変更 | |
("M-l" . e2wm:dp-two) ; twoへ変更 | |
("M-k" . e2wm:dp-array) ; arrayへ変更 | |
("M-j" . e2wm:dp-dashboard) ; dashboardへ変更 | |
("C-." . e2wm:pst-history-forward-command) ; 履歴を進む | |
("C-," . e2wm:pst-history-back-command) ; 履歴をもどる | |
("prefix L" . ielm) | |
) e2wm:prefix-key) | |
(setq e2wm:c-dashboard-plugins | |
'((open :plugin-args (:command twit :buffer "*twittering*")) | |
(open :plugin-args (:command doctor :buffer "*doctor*"))))) | |
;; 自分の情報 | |
(setq user-full-name "深町英太郎 (E.Fukamachi)" | |
user-mail-address "e.arrows@gmail.com") | |
;; テキストエンコーディングとしてUTF-8を優先使用 | |
(prefer-coding-system 'utf-8) | |
;; 起動時のメッセージを非表示 | |
(setq inhibit-startup-message t) | |
;; lisp-interaction-modeを使わない | |
(setq initial-major-mode 'emacs-lisp-mode) | |
;; Tabの代わりにスペースでインデント | |
(setq-default tab-width 2 | |
indent-tabs-mode nil) | |
;; 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 (kbd "C-w") 'backward-kill-word) | |
;; 範囲指定していないとき、C-wで前の単語を削除 | |
(defadvice kill-region (around kill-word-or-kill-region activate) | |
(if (and (interactive-p) transient-mark-mode (not mark-active)) | |
(backward-kill-word 1) | |
ad-do-it)) | |
;; GCを減らして軽くする | |
(setq gc-cons-threshold (* 10 gc-cons-threshold)) | |
;; ダイアログを使わない | |
(setq use-dialog-box nil) | |
(defalias 'message-box 'message) | |
;; キーストロークのミニバッファへの表示を早く | |
(setq echo-keystrokes 0.1) | |
;; 終了時に自動でプロセスをkill | |
(setq process-kill-without-query t) | |
;; クリップボードにコピー | |
(setq x-select-enable-clipboard t) | |
;; 1行ずつスクロール | |
(setq scroll-conservatively 35 | |
scroll-margin 0 | |
scroll-step 1) | |
(setq comint-scroll-show-maximum-output t) ;; for shell-mode | |
;; beepを消す | |
(setq ring-bell-function 'ignore) | |
;;; for Mac | |
(defun mac-os-p () | |
(member window-system '(mac ns))) | |
(defun linuxp () | |
(eq window-system 'x)) | |
;; Command-Key and Option-Key | |
(when (mac-os-p) | |
(setq ns-command-modifier 'meta) | |
(setq ns-alternate-modifier 'super) | |
(setq mac-pass-command-to-system nil)) | |
;; fullscreen | |
(defun toggle-fullscreen () | |
(interactive) | |
(cond | |
((mac-os-p) (ns-toggle-fullscreen)) | |
((linuxp) | |
(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) | |
;; よく使うモード | |
(defvar my-fav-modes | |
'((emacs-lisp-mode . "\\.el$") | |
(common-lisp-mode . "\\.\\(cl\\|lisp\\)$") | |
(scheme-mode . "\\.scm$") | |
(clojure-mode . "\\.clj$") | |
(pir-mode . "\\.\\(imc\\|pir\\)$") | |
; (malabar-mode . "\\.java$") | |
(php-mode . "\\.php[45]?$") | |
(yaml-mode . "\\.ya?ml$") | |
(js2-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\\|jsp\\|tag\\)$") | |
(markdown-mode . "\\.\\(md\\|markdown\\)$"))) | |
;; auto-mode-alist | |
(loop for (k . v) in my-fav-modes | |
do (unless (null v) (add-to-list 'auto-mode-alist (cons v k)))) | |
;; コメントアウト | |
(global-set-key "\C-x;" 'comment-region) | |
(global-set-key "\C-x:" 'uncomment-region) | |
;; goto-lineをM-gに | |
(global-set-key "\M-g" 'goto-line) | |
;; C-kで行が連結したときにインデントを減らす | |
(defadvice kill-line (before kill-line-and-fixup activate) | |
(when (and (not (bolp)) (eolp)) | |
(forward-char) | |
(fixup-whitespace) | |
(backward-char))) | |
;; バックアップファイルを作らない | |
(setq make-backup-files nil) | |
(setq auto-save-default nil) | |
;; 日本語フォント | |
(defun set-jp-font () | |
(when (display-graphic-p) | |
(set-fontset-font | |
(frame-parameter nil 'font) | |
'japanese-jisx0208 | |
'("Hiragino Maru Gothic Pro" . "iso10646-1")))) | |
(set-jp-font) | |
;; 行間を開く | |
(setq-default line-spacing 0.1) | |
;; フォントサイズ変更 | |
(defun font-big () | |
(interactive) | |
(set-face-attribute 'default nil :height | |
(+ (face-attribute 'default :height) 10)) | |
(set-jp-font)) | |
(defun font-small () | |
(interactive) | |
(set-face-attribute 'default nil :height | |
(- (face-attribute 'default :height) 10)) | |
(set-jp-font)) | |
(global-set-key (kbd "C--") 'font-small) | |
(global-set-key (kbd "C-+") 'font-big) | |
;;==================== | |
;; Search | |
;;==================== | |
(defvar last-search-char nil) | |
(defvar last-search-direction 'forward) | |
(defun search-forward-with-char (char) | |
(interactive "cMove to Char: ") | |
;; カーソルの文字と等しいときはヒットさせない | |
(if (eq (char-after (point)) char) (forward-char)) | |
(and (search-forward (char-to-string char) nil t) | |
(backward-char)) | |
(setq last-search-char char | |
last-search-direction 'forward)) | |
(defun search-backward-with-char (char) | |
(interactive "cMove backward to Char: ") | |
(search-backward (char-to-string char) nil t) | |
(setq last-search-char char | |
last-search-direction 'backward)) | |
(defun search-repeat-with-char () | |
(interactive) | |
(cond | |
((eq nil last-search-char) (message "You haven't searched yet. Stupid!")) | |
((eq last-search-direction 'forward) | |
(or (search-forward-with-char last-search-char) (backward-char))) | |
((eq last-search-direction 'backward) (search-backward-with-char last-search-char)))) | |
(global-set-key "\C-f" 'search-forward-with-char) | |
(global-set-key "\C-b" 'search-backward-with-char) | |
(global-set-key (kbd "C-;") 'search-repeat-with-char) | |
(global-set-key "\M-s" 'query-replace-regexp) | |
(defun kill-word-at-point () | |
(interactive) | |
(let ((char (char-to-string (char-after (point))))) | |
(cond | |
((string= " " char) (delete-horizontal-space)) | |
((string-match "[\t\n -@\[-`{-~]" char) (kill-word 1)) | |
(t (forward-char) (backward-word) (kill-word 1))))) | |
(global-set-key "\M-d" 'kill-word-at-point) | |
(global-set-key "\M-/" 'expand-abbrev) | |
;;==================== | |
;; Move Cursor | |
;;==================== | |
(global-set-key "\C-h" 'backward-char) | |
(global-set-key "\C-j" 'next-line) | |
(global-set-key "\C-k" 'previous-line) | |
(global-set-key "\C-l" 'forward-char) | |
(global-set-key "\C-n" 'newline-and-indent) | |
(global-set-key "\C-o" 'kill-line) | |
(global-set-key (kbd "C-'") 'recenter) | |
;;==================== | |
;; View-mode | |
;;==================== | |
(setq view-read-only t) | |
(defvar pager-keybind | |
`( ;; vi-like | |
("h" . backward-word) | |
("l" . forward-word) | |
("j" . next-line) | |
("k" . previous-line) | |
("b" . scroll-down) | |
(" " . scroll-up) | |
)) | |
(defun define-many-keys (keymap key-table &optional includes) | |
(let (key cmd) | |
(dolist (key-cmd key-table) | |
(setq key (car key-cmd) | |
cmd (cdr key-cmd)) | |
(if (or (not includes) (member key includes)) | |
(define-key keymap key cmd)))) | |
keymap) | |
(add-hook-fn 'view-mode-hook (define-many-keys view-mode-map pager-keybind)) | |
;; 書き込み不能なファイルはview-modeで開くように | |
(defadvice find-file | |
(around find-file-switch-to-view-file (file &optional wild) activate) | |
(if (and (not (file-writable-p file)) | |
(not (file-directory-p file))) | |
(view-file file) | |
ad-do-it)) | |
;; 書き込み不能な場合はview-modeを抜けないように | |
(defvar view-mode-force-exit nil) | |
(defmacro do-not-exit-view-mode-unless-writable-advice (f) | |
`(defadvice ,f (around do-not-exit-view-mode-unless-writable activate) | |
(if (and (buffer-file-name) | |
(not view-mode-force-exit) | |
(not (file-writable-p (buffer-file-name)))) | |
(message "File is unwritable, so stay in view-mode.") | |
ad-do-it))) | |
(do-not-exit-view-mode-unless-writable-advice view-mode-exit) | |
(do-not-exit-view-mode-unless-writable-advice view-mode-disable) | |
(req key-chord | |
(setq key-chord-two-keys-delay 0.04) | |
(key-chord-mode 1) | |
(key-chord-define-global "jk" 'view-mode)) | |
;;==================== | |
;; Window | |
;;==================== | |
(global-set-key-fn (kbd "C-M-h") (move-to-window-line 0)) | |
(global-set-key-fn (kbd "C-M-m") (move-to-window-line nil)) | |
(global-set-key-fn (kbd "C-M-l") (move-to-window-line -1)) | |
;; 分割したウィンドウ間を移動 | |
(define-prefix-command 'windmove-map) | |
(global-set-key (kbd "C-q") 'windmove-map) | |
(define-key windmove-map "h" 'windmove-left) | |
(define-key windmove-map "j" 'windmove-down) | |
(define-key windmove-map "k" 'windmove-up) | |
(define-key windmove-map "l" 'windmove-right) | |
(define-key windmove-map "0" 'delete-window) | |
(define-key windmove-map "1" 'delete-other-windows) | |
(define-key windmove-map "2" 'split-window-vertically) | |
(define-key windmove-map "3" 'split-window-horizontally) | |
;; windowを分割・削除したときに幅をあわせる+別のwindowに移動 | |
;(defadvice-many (split-window-vertically | |
; split-window-horizontally | |
; delete-window) after | |
; (balance-windows) | |
; (other-window 1)) | |
(defun split-window-conditional () | |
(interactive) | |
(if (> (* (window-height) 2) (window-width)) | |
(split-window-vertically) | |
(split-window-horizontally))) | |
(define-key windmove-map "s" 'split-window-conditional) | |
(define-key windmove-map "n" (lambda () (interactive) (split-window-conditional) (switch-to-buffer "*scratch*"))) | |
;;==================== | |
;; Utilities | |
;;==================== | |
;; hs-minor-mode | |
(req hideshow | |
(loop for (k . v) in my-fav-modes | |
do (add-hook (intern (concat (symbol-name k) "-hook")) | |
(lambda () | |
(and (hs-minor-mode) (hs-hide-all))))) | |
(global-set-key (kbd "C-=") 'hs-toggle-hiding) | |
(global-set-key (kbd "C-\\") 'hs-hide-level)) | |
;; remember | |
(global-set-key "\C-cr" 'remember) | |
(setq org-default-notes-file "~/Dropbox/memo.markdown") | |
(global-set-key-fn "\C-cv" (find-file org-default-notes-file)) | |
;; Don't type twice | |
;(req dont-type-twice | |
; (global-dont-type-twice t) | |
; (setq dt2-notify-func 'dt2-growl) | |
; (add-to-list 'dt2-modes 'markdown-mode)) | |
;; grep | |
(setq grep-command "ack --nogroup ") | |
;; undo-tree | |
(req undo-tree | |
(global-undo-tree-mode)) | |
;; auto-complete | |
;; 補完候補を自動ポップアップ | |
(req auto-complete | |
(global-auto-complete-mode t) | |
(append-to-list ac-modes (mapcar 'car my-fav-modes))) | |
;; yasnippet | |
(req yasnippet | |
(req anything-c-yasnippet | |
(setq anything-c-yas-space-match-any-greedy t) | |
(global-set-key (kbd "C-c i") 'anything-c-yas-create-snippet-on-region)) | |
(yas/initialize) | |
(yas/load-directory "~/Dropbox/home/.emacs.d/elisp/yasnippet/snippets/") | |
(req auto-complete-yasnippet | |
(add-to-list 'ac-sources 'ac-source-yasnippet)) | |
;; 使い捨て | |
(defvar yas/oneshot-snippet nil) | |
(defun yas/register-oneshot-snippet (s e) | |
(interactive "r") | |
(setq yas/oneshot-snippet (buffer-substring-no-properties s e)) | |
(delete-region s e) | |
(yas/expand-oneshot-snippet) | |
(message "%s" (substitute-command-keys "Press \\[yas/expand-oneshot-snippet] to expand."))) | |
(defun yas/expand-oneshot-snippet () | |
(interactive) | |
(if (string< "0.6" yas/version) | |
(yas/expand-snippet yas/oneshot-snippet) | |
(yas/expand-snippet (point) (point) yas/oneshot-snippet))) | |
(global-set-key (kbd "C-x C-y") 'yas/register-oneshot-snippet) | |
(global-set-key (kbd "C-x y") 'yas/expand-oneshot-snippet)) | |
(defvar growl-program "/usr/local/bin/growlnotify") | |
(defmacro growl (title message &optional id stickyp) | |
(let ((args `("growl" "*growl*" ,growl-program | |
,title "-w"))) | |
(or (null id) | |
(setq args (append args `("-d" ,id)))) | |
(or (null stickyp) | |
(setq args (append args `("-s")))) | |
`(progn | |
(start-process ,@args) | |
(process-send-string "*growl*" (concat ,message "\n")) | |
(process-send-eof "*growl*")))) | |
;; uniquify | |
(req uniquify | |
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)) | |
;; tramp | |
(lazyload (tramp) "tramp" | |
(setq tramp-default-method "sshx")) | |
;; Emacs Lispの保存時にbyte compile | |
(req auto-async-byte-compile | |
(setq auto-async-byte-compile-exclude-files-regexp "/junk/") | |
(add-hook 'emacs-lisp-mode-hook 'enable-auto-async-byte-compile-mode)) | |
;; 同じコマンドを連続実行したときの振る舞いを変更 | |
(req sequential-command-config | |
(sequential-command-setup-keys)) | |
;; 最近使ったファイルを開く | |
(req recentf-ext | |
(setq recentf-max-saved-items 500) | |
(setq recentf-exclude '("/TAGS$" "/var/tmp/")) | |
(global-set-key (kbd "M-r") 'anything-for-files)) | |
;; カーソル位置を戻す | |
(req point-undo | |
(global-set-key (kbd "C-p") 'point-undo) | |
(global-set-key (kbd "C-0") 'point-redo)) | |
;; カーソル位置に目に見える印をつける | |
(req bm | |
(setq-default bm-buffer-persistence nil) | |
(setq bm-restore-repository-on-load t) | |
(add-hook 'find-file-hooks 'bm-buffer-restore) | |
(add-hook 'kill-buffer-hook 'bm-buffer-save) | |
(add-hook 'after-save-hook 'bm-buffer-save) | |
(add-hook 'after-revert-hook 'bm-buffer-restore) | |
(add-hook 'vc-before-checkin-hook 'bm-buffer-save) | |
(global-set-key (kbd "M-p") 'bm-toggle) | |
(global-set-key (kbd "M-[") 'bm-previous) | |
(global-set-key (kbd "M-]") 'bm-next)) | |
; 翻訳 | |
(lazyload (text-translator-all-by-auto-selection) "text-translator" | |
(setq text-translator-auto-selection-func | |
'text-translator-translate-by-auto-selection-enja) | |
(defalias 'translate 'text-translator-all-by-auto-selection)) | |
;; redmine | |
(lazyload (redmine-show-issues-all | |
redmine-show-activity | |
redmine-show-revisions | |
redmine-select-project) "redmine" | |
(load "redmine-conf" t)) | |
;; smart-compile+ | |
(global-set-key "\C-x\C-x" 'smart-compile) | |
(lazyload (smart-compile) "smart-compile+" | |
(append-to-list smart-compile-alist | |
'(("\\.cl$" . "sbcl --noinform %f") | |
("\\.scm$" . "gosh %f") | |
("\\.clj$" . "clj %f") | |
("\\.pir$" . "parrot %f") | |
("\\.\(pl\|pm\)$" . "perl %f")))) | |
;; 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 "~/Dropbox/home/.emacs.d/elisp/")) | |
;; 終了してもカーソル位置を記録 | |
(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) | |
(append-to-list outputz-modes (mapcar 'car my-fav-modes)) | |
(defadvice outputz (before outputz-setup-uri) | |
(when (get-ip-address "en1") | |
(set-proxy) | |
(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" t)) | |
;; anything | |
(req anything-startup | |
;; kill-ring一覧を表示 | |
; (global-set-key "\M-y" 'anything-show-kill-ring) | |
(define-key anything-map "\C-j" 'anything-next-line) | |
(define-key anything-map "\C-k" 'anything-previous-line) | |
(define-key anything-map "\M-j" 'anything-next-page) | |
(define-key anything-map "\M-k" 'anything-previous-page)) | |
;; popup-kill-ring | |
(lazyload (popup-kill-ring) "popup-kill-ring" | |
(require 'popup) | |
(require 'pos-tip) | |
(setq popup-kill-ring-interactive-insert t) | |
(define-key popup-kill-ring-keymap "\C-j" 'popup-kill-ring-next) | |
(define-key popup-kill-ring-keymap "\C-k" 'popup-kill-ring-previous) | |
(define-key popup-kill-ring-keymap "\C-l" 'popup-kill-ring-current) | |
(define-key popup-kill-ring-keymap "\C-h" 'popup-kill-ring-hide)) | |
(global-set-key "\M-y" 'popup-kill-ring) | |
;; cua-mode | |
;; 矩形選択を簡単に | |
(cua-mode t) | |
(setq cua-enable-cua-keys nil) | |
;; auto-insert | |
;; ファイル形式に応じて自動でテンプレート挿入 | |
(add-hook 'find-file-hooks 'auto-insert) | |
(setq auto-insert-directory "~/Dropbox/home/.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") | |
(".*\\.class\\.php$" . ["php-class-template.php" my-template]))) | |
(defvar template-replacements-alists | |
'(("%file%" . (lambda () (file-name-nondirectory (buffer-file-name)))) | |
("%file-without-ext%" . (lambda () (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))) | |
("%name%" . user-full-name) | |
("%mail%" . user-mail-address) | |
("%directory-name%" . (lambda () (file-name-parent-directory (buffer-file-name)))))) | |
(defun my-template () | |
(time-stamp) | |
(mapc (lambda (c) | |
(progn | |
(goto-char (point-min)) | |
(while (re-search-forward (car c) nil t) | |
(replace-match (funcall (cdr c)))))) | |
template-replacements-alists) | |
(goto-char (point-max)) | |
(message "done.")) | |
;; 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 50) | |
(defvar ansi-term-after-hook nil) | |
(add-hook-fn 'term-mode-hook | |
(define-key term-raw-map "\C-t" 'shell-pop) | |
(define-key term-raw-map "\C-y" 'term-paste) | |
(define-key term-raw-map "\M-x" nil) | |
(define-key term-raw-map (kbd "C-,") 'term-line-mode) | |
(define-key term-mode-map (kbd "C-,") | |
(lambda () (interactive) | |
(term-char-mode) | |
(end-of-buffer) | |
(previous-line))) | |
(define-key term-raw-map "\C-q" nil) | |
(define-key term-raw-map "\C-z" nil)) | |
(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 (kbd "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" | |
elscreen-display-tab nil) | |
(defun elscreen-frame-title-update () | |
(when (elscreen-screen-modified-p 'elscreen-frame-title-update) | |
(let* ((screen-list (sort (elscreen-get-screen-list) '<)) | |
(screen-to-name-alist (elscreen-get-screen-to-name-alist)) | |
(title (mapconcat | |
(lambda (screen) | |
(format "%d%s %s" | |
screen (elscreen-status-label screen) | |
(get-alist screen screen-to-name-alist))) | |
screen-list " "))) | |
(if (fboundp 'set-frame-name) | |
(set-frame-name title) | |
(setq frame-title-format title))))) | |
(add-hook 'elscreen-screen-update-hook 'elscreen-frame-title-update)) | |
;; 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 | |
w3m-default-display-inline-images t | |
w3m-quick-start nil | |
w3m-home-page "http://www.google.com/")) | |
;(setq browse-url-browser-function 'w3m-browse-url) | |
;; wdired | |
(add-hook-fn 'dired-mode-hook | |
(req wdired | |
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode))) | |
;; M-x occurで検索結果を一覧 | |
(lazyload (occur moccur moccur-grep moccur-grep-find) "color-moccur" | |
(setq moccur-split-word t)) | |
;; migemo | |
(req migemo | |
(load "migemo-conf" t) | |
(when (linuxp) | |
(setq migemo-dictionary "/usr/share/migemo/migemo-dict")) | |
(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)) | |
;; twittering-mode | |
(lazyload (twit twittering-update-status-interactive) "twittering-mode" | |
(setq twittering-username "nitro_idiot") | |
(setq twittering-auth-method 'xauth) | |
(setq twittering-retweet-format " RT @%s: %t") | |
(setq twittering-timer-interval nil) | |
(load "twittering-conf" t)) | |
;; emacs-jabber | |
(lazyload (jabber-connect) "jabber" | |
(load "jabber-conf" t) | |
(setq jabber-message-alert-same-buffer nil) | |
(defun pg-jabber-growl-notify (from buf text proposed-alert) | |
"(jabber.el hook) Notify of new Jabber chat messages via Growl" | |
(when (or jabber-message-alert-same-buffer | |
(not (memq (selected-window) (get-buffer-window-list buf)))) | |
(if (jabber-muc-sender-p from) | |
(growl (format "(PM) %s" | |
(jabber-jid-displayname (jabber-jid-user from))) | |
(format "%s: %s" (jabber-jid-resource from) text) | |
(format "jabber-from-%s" (jabber-jid-resource from))) | |
(growl (format "%s" (jabber-jid-displayname from)) | |
text "jabber-from-unknown")))) | |
(add-hook 'jabber-alert-message-hooks 'pg-jabber-growl-notify) | |
;; Same as above, for groupchats | |
(defun pg-jabber-muc-growl-notify (nick group buf text proposed-alert) | |
"(jabber.el hook) Notify of new Jabber MUC messages via Growl" | |
(when (or jabber-message-alert-same-buffer | |
(not (memq (selected-window) (get-buffer-window-list buf)))) | |
(if nick | |
(when (or jabber-muc-alert-self | |
(not (string= | |
nick (cdr (assoc group *jabber-active-groupchats*))))) | |
(growl (format "%s" (jabber-jid-displayname group)) | |
(format "%s: %s" nick text) | |
(format "jabber-chat-%s" (jabber-jid-displayname group)))) | |
(growl (format "%s" (jabber-jid-displayname group)) | |
text "jabber-chat-unknown")))) | |
(add-hook 'jabber-alert-muc-hooks 'pg-jabber-muc-growl-notify)) | |
;; 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" t)) | |
;;==================== | |
;; 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))) | |
(loop for m in (mapcar 'car my-fav-modes) | |
do (progn | |
(add-hook-fn (intern (concat (symbol-name m) "-hook")) | |
(setq show-trailing-whitespace t)) | |
(add-hook-fn 'jaspace-mode-hook | |
(assq-delete-all 'jaspace-mode minor-mode-alist)))) | |
(add-hook 'before-save-hook 'delete-trailing-whitespace) | |
;; カーソル行をハイライト | |
(defface hlline-face | |
'((((class color) | |
(background dark)) | |
(:background "dark slate gray")) | |
(((class color) | |
(background light)) | |
(:background "ForestGreen")) | |
(t | |
())) | |
nil :group 'font-lock-highlighting-faces) | |
(setq hl-line-face 'hlline-face) | |
(global-hl-line-mode) | |
;; 表示不要なマイナーモードを削除 | |
(loop for m in '(outputz undo-tree auto-complete jaspace) | |
do (assq-delete-all (intern (concat (symbol-name m) "-mode")) minor-mode-alist)) | |
;; モード行に行番号、桁番号を表示 | |
(line-number-mode t) | |
(column-number-mode t) | |
;; モード行に時刻を表示 | |
(setq display-time-string-forms '(24-hours ":" minutes)) | |
(display-time) | |
;; モード行にバッテリ残量を表示 | |
(display-battery-mode t) | |
;; 改行コードを表示 | |
(setq eol-mnemonic-dos "(CRLF)" | |
eol-mnemonic-mac "(CR)" | |
eol-mnemonic-unix "(LF)") | |
;;==================== | |
;; Window System | |
;;==================== | |
(when window-system | |
(server-start) ;; Emacs serverを起動 | |
(set-frame-parameter nil 'alpha 85) ;; フレームを透過 | |
(menu-bar-mode 0) ;; メニューバーを消す | |
(tool-bar-mode 0) ;; ツールバーを消す | |
(toggle-scroll-bar nil)) ;; スクロールバーを消す | |
;;==================== | |
;; Syntax | |
;;==================== | |
;; Clojure | |
(lazyload (clojure-mode) "clojure-mode" | |
(setenv "CLOJURE_EXT" (concat (getenv "HOME") "/.clojure")) | |
(setq clojure-src-root (expand-file-name "~/.clojure"))) | |
;(req swank-clojure | |
; (add-hook 'slime-mode-hook | |
; (lambda () | |
; (setq slime-truncate-lines nil) | |
; (slime-redirect-inferior-output))) | |
; (add-to-list 'slime-lisp-implementations | |
; `(clojure ,(swank-clojure-cmd) :init swank-clojure-init)) | |
; (add-to-list 'swank-clojure-classpath (concat (getenv "HOME") "/Dropbox/home/.emacs.d/elisp/swank-clojure/src")) | |
; (add-hook 'slime-repl-mode-hook 'clojure-mode-font-lock-setup)) | |
;; Gauche | |
(lazyload (scheme-mode run-scheme) "cmuscheme" | |
(add-to-list 'process-coding-system-alist '("gosh" utf-8 . utf-8)) | |
(setq scheme-program-name "gosh -i")) | |
;; Common lisp | |
(req cl-indent-patches) | |
(req slime | |
(setq inferior-lisp-program "~/Dropbox/home/bin/ccl") | |
(add-hook 'slime-connected-hook | |
(lambda () | |
(define-key slime-repl-mode-map (kbd "C-n") 'slime-repl-newline-and-indent) | |
(define-key slime-repl-mode-map (kbd "C-j") 'next-line))) | |
(slime-setup '(slime-repl slime-fancy slime-banner))) | |
(setf anything-c-source-hyperspec | |
`((name . "Lookup Hyperspec") | |
(candidates . (lambda () | |
(let ((symbols nil)) | |
(mapatoms #'(lambda (sym) (push (symbol-name sym) symbols)) | |
common-lisp-hyperspec-symbols) | |
symbols))) | |
(action . (("Show Hyperspec" . hyperspec-lookup))))) | |
(add-to-list 'anything-sources anything-c-source-hyperspec) | |
;; Parrot | |
(lazyload (pir-mode) "pir-mode" | |
(define-key pir-mode-map "\C-j" 'next-line)) | |
;; CPerl | |
(defalias 'perl-mode 'cperl-mode) | |
(lazyload (cperl-mode) "cperl-mode" | |
(req perltidy | |
(defvar cperl-auto-tidy t) | |
(defun cperl-save-buffer (&optional args) | |
"Perltidy and save current buffer in visited file if modified." | |
(interactive) | |
(if (and (buffer-modified-p) | |
cperl-auto-tidy) | |
(perltidy-buffer)) | |
(save-buffer)) | |
(define-key cperl-mode-map "\C-x\C-s" 'cperl-save-buffer)) | |
(setq cperl-continued-statement-offset 4 | |
cperl-indent-level 4 | |
cperl-tab-always-indent t) | |
(define-key cperl-mode-map "\C-j" 'next-line)) | |
;; php-mode | |
(lazyload (php-mode) "php-mode") | |
(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 | |
(lazyload (js2-mode) "js2" | |
(setq js2-basic-offset 2 | |
js2-mirror-mode nil) | |
(req espresso | |
(setq espresso-indent-level 2 | |
espresso-expr-indent-offset 2 | |
indent-tabs-mode nil) | |
(defun my-js-indent-line () | |
(interactive) | |
(let* ((parse-status (save-excursion (syntax-ppss (point-at-bol)))) | |
(offset (- (current-column) (current-indentation))) | |
(indentation (espresso--proper-indentation parse-status))) | |
(back-to-indentation) | |
(if (looking-at "case\\s-") | |
(indent-line-to (+ indentation 2)) | |
(espresso-indent-line)) | |
(when (> offset 0) (forward-char offset)))) | |
(add-hook-fn 'js2-mode-hook | |
(set (make-local-variable 'indent-line-function) 'my-js-indent-line)))) | |
;; 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))) | |
(req git-status) | |
(req hg-status) | |
(lazyload (markdown-mode) "markdown-mode") | |
(add-hook 'markdown-mode-hook #'(lambda () | |
(req word-count (word-count-mode-on)) | |
(setq show-trailing-whitespace nil))) | |
;;==================== | |
;; Syntax Checking | |
;;==================== | |
;; flymake | |
(defadvice flymake-post-syntax-check (before flymake-force-check-was-interrupted) | |
(setq flymake-check-was-interrupted t)) | |
(ad-activate 'flymake-post-syntax-check) | |
(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 | |
',(mapc (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)) | |
;; Perl | |
(def-flymake-init perl ("\.p[lm]$") | |
`("perl" ("-wc" ,local-file)) | |
("\(.*\) at \([^ \n]+\) line \([0-9]+\)[,.\n]" 2 3 nil 1)) | |
(add-hook-fn 'cperl-mode-hook (flymake-mode t)) | |
;; JavaScript | |
(def-flymake-init js2 ("\.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) | |
;;==================== | |
;; Network | |
;;==================== | |
(defun get-ip-address (dev) | |
(format-network-address (car (network-interface-info dev)) t)) | |
(defun mac-network-location () | |
(substring | |
(shell-command-to-string "scselect 2>&1 | grep '^ ' 2>&1 | grep '*' | cut -f 2 -d '(' | cut -f 1 -d ')'") | |
0 -1)) | |
(defun officep () | |
(let ((ip (get-ip-address "en1"))) | |
(and (not (null ip)) (eq 0 (string-match "^10\\.0\\.100\\." ip))))) | |
(defun set-proxy () | |
(if (officep) | |
(progn | |
;; 会社にいるときはプロキシを設定 | |
(let ((protocol "http") | |
(domain "192.168.0.230") | |
(port "3128")) | |
(setq url-proxy-services | |
`((,protocol . ,(concat domain ":" port)))) | |
(setq w3m-command-arguments-alist | |
`(("" "-o" ,(format "http_proxy=%s://%s:%s" protocol domain port)))) | |
(eval-after-load 'twittering-mode | |
`(setq twittering-proxy-use t | |
twittering-proxy-server ,(concat protocol "://" domain) | |
twittering-proxy-port ,port))) | |
t) | |
(progn | |
(setq url-proxy-services nil) | |
(setq w3m-command-arguments-alist nil) | |
(eval-after-load 'twittering-mode | |
`(setq twittering-proxy-use nil | |
twittering-proxy-server nil | |
twittering-proxy-port nil))))) | |
(set-proxy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment