;;;; Emacs 初期設定ファイル ;;;; $Id: .emacs.el,v 1.116 2012/05/08 02:26:24 masao Exp $ ;;;(初期化ファイルの読み込み中など) エラーが起きた際は、エラー個所を表示 (setq debug-on-error t) ;;; ライブラリ探索パスの設定 (add-to-list 'load-path (expand-file-name "~/mule")) ;;; 日本語と文字コードの設定 (set-language-environment 'Japanese) ; 日本語環境 (set-default-coding-systems 'euc-jp-unix) ; EUC-JP が基本 (set-terminal-coding-system 'euc-jp-unix) ; emacs -nw も文字化けしない ;;; Windows 上の NTEmacs 用設定 (if (string= system-type "windows-nt") (progn (set-default-coding-systems 'shift_jis-dos) (set-clipboard-coding-system 'shift_jis-dos))) ; Shift_JIS が基本 ; どのcoding-systemにするかいちいち聞かれない。 ; news:tzg0dmjly9.wl@tenryu.tom.sfc.keio.ac.jp (from fj.editor.emacs) (add-hook 'write-file-hooks (function (lambda () (if (eq buffer-file-coding-system 'undecided-unix) (setq buffer-file-coding-system default-file-name-coding-system)) nil))) ; time-stamp を自動で使用する。 (if (not (memq 'time-stamp write-file-hooks)) (setq write-file-hooks (cons 'time-stamp write-file-hooks))) ;; ファイルの保存は EUC-JP ;(setq default-buffer-file-coding-system 'euc-jp-unix) ;; 外部プログラムとのやり取りも EUC-JP ;(setq default-process-coding-system '(euc-jp . euc-jp)) ;;; Emacs server ; (if window-system ; (let () ; (server-start) ; (setq server-temp-file-regexp "^/tmp/snd") ; (global-set-key "\C-x\C-c" 'server-edit))) ; (add-hook 'server-switch-hook 'new-frame) ; (add-hook 'server-done-hook 'kill-this-buffer) ; (add-hook 'server-done-hook 'delete-frame) ;;; Emacs21以上: ; ツールバー非表示 (if (fboundp 'tool-bar-mode) (tool-bar-mode 0)) ; カーソル点滅は停止 (if (fboundp 'blink-cursor-mode) (blink-cursor-mode 0)) ; 行折返しでのfringe表示は右側だけにする (if (fboundp 'fringe-mode) (fringe-mode '(0 . nil))) ;バージョン番号付のバックアップを作らない。 (setq version-control 'never) ;; font-lock を常に使って華やかにする。 (global-font-lock-mode t) (setq font-lock-support-mode 'jit-lock-mode) ;; Mule-UCS (Unicode対応) (require 'un-define nil t) (setq enable-double-n-syntax t) ;"nn"と打って、'ん'と変換。 ;;; キーバインド (global-set-key "\M-g" 'goto-line) (global-set-key "\M-%" 'query-replace-regexp) (global-set-key "\C-h" 'delete-backward-char) (global-set-key "\M-h" 'help-for-help) (load "term/bobcat") ; emacs -nw 時にも Backspace キーを有効にする。 ;; X Windows 上で動かしている時に間違えてアイコン化しないようにする ;(if window-system ; (global-unset-key "\C-z")) ;;; テキスト編集の設定 ;標準のメジャーモードはtext-mode。 (setq default-major-mode 'text-mode) ;リターンを押した時にオートインデントさせる(前の行と同じインデント)。 (global-set-key "\C-m" 'newline-and-indent) (setq indent-line-function 'indent-relative-maybe) ;ファイルの最後には改行が必要。 (setq require-final-newline t) ;ファイルの最後で↓(newline)をしても改行されない。 (setq next-line-add-newlines nil) ;C-k だけで行全体を削除。 (setq kill-whole-line t) ;現在行をモードラインに表示。 (line-number-mode t) ;初期メッセージを表示しない。 (setq inhibit-startup-message t) ;文字列検索時にマッチを強調表示 (setq search-highlight t) ;選択範囲を見えるようにしておく。 (setq transient-mark-mode t) ;ミニバッファの内容を全部見る (resize-minibuffer-mode 1) ; {C-x C-u or C-x C-l} だけで選択範囲の ASCII 文字列を{大文字 or 小文字}化 (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) ;; history から重複したのを消す ;; from (require 'cl) (defun minibuffer-delete-duplicate () (let (list) (dolist (elt (symbol-value minibuffer-history-variable)) (unless (member elt list) (push elt list))) (set minibuffer-history-variable (nreverse list)))) (add-hook 'minibuffer-setup-hook 'minibuffer-delete-duplicate) ;PSプリンタで日本語印刷 (setq ps-multibyte-buffer 'non-latin-printer) (setq ps-paper-type 'a4) ; 用紙サイズ ; (setq ps-number-of-columns 2) ; (2段組) ; (setq ps-landscape-mode t) ; (2段組) 用紙方向を横にする ;diff コマンドのオプション (setq diff-switches "-u") ;;; テンプレートを挿入する。(auto-insert を使ってみる) (load "autoinsert") (add-hook 'find-file-hooks 'auto-insert) (setq auto-insert-query nil) (setq auto-insert-directory "~/mule/templates/") (setq auto-insert-alist (append '( ("\\.c$" . "c-insert.c") ("\\.h$" . "h-insert.h") ("\\.pl$" . "perl-insert.pl") ("\\.rb$" . "ruby-insert.rb") ("\\.sh$" . "sh-insert.sh") ("\\.s?html?\\(\\.\\(en\\|ja\\|in\\)\\)?$" . "html-insert.html") ("\\.hikidoc$" . "hikidoc-insert.hikidoc") ("\\.xsl$" . "xsl-insert.xsl") ("\\.tex$" . "tex-insert.tex")) auto-insert-alist)) ;;; メールの文章 & 下書き (add-to-list 'auto-mode-alist '("\\.message" . mail-mode)) (add-to-list 'auto-mode-alist '("/Mail/draft/" . mail-mode)) ;(setq mail-personal-alias-file (expand-file-name "~/Mail/Aliases")) ;(eval-after-load "mailabbrev" '(load "sendmail-alias")) ;(eval-after-load "mailalias" '(load "sendmail-alias")) ;(add-hook 'mail-setup-hook 'mail-abbrevs-setup) ;;; For C Programming (setq c-default-style '((other . "user"))) ;(setq c-site-default-style "bsd") ;;; For Perl Programming (add-to-list 'auto-mode-alist '("\\.pl$" . cperl-mode)) (add-hook 'cperl-mode-hook '(lambda () (cperl-set-style "BSD"))) ;;; For Ruby Programming (autoload 'ruby-mode "ruby-mode" "Mode for editing ruby source files") (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode)) (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") (setq ruby-indent-level 3) (add-hook 'ruby-mode-hook '(lambda () (inf-ruby-keys) (define-key ruby-mode-map "\C-m" 'newline-and-indent) (define-key ruby-mode-map "\C-j" 'newline) (and (stringp (buffer-file-name)) (string-match "/mobo\\|tdiary/" (buffer-file-name)) (progn (setq indent-tabs-mode t) (setq tab-width ruby-indent-level))))) ;; codingの自動挿入をやめる ;(remove-hook 'before-save-hook 'ruby-mode-set-encoding) ;;; For rd-mode (autoload 'rd-mode "rd-mode" "major mode for ruby document formatter RD") (add-to-list 'auto-mode-alist '("\\.rd$" . rd-mode)) ;;; For ChangeLog mode (add-hook 'change-log-mode-hook '(lambda () (turn-on-auto-fill))) (setq user-mail-address "tmasao@acm.org") (setq user-full-name "Masao Takaku") ; (setq time-stamp-format "%02m/%02d/%:y %02H:%02M %u") ; (setq time-stamp-format "%:y-%02m-%02d %02H:%02M %u") (defface change-log-memo-title-face '((t (:inherit change-log-file-face))) "") (defface change-log-memo-title-public-face '((t (:inherit font-lock-warning-face))) "") (font-lock-add-keywords 'change-log-mode '(("^\t\\* \\(\\[pub\\]\\)[ ]*\\([^:]+\\)" (1 'change-log-memo-title-public-face) (2 'change-log-memo-title-face)) ("^\t\\* \\([^:]+\\)" 1 'change-log-memo-title-face))) ; ;;; For ChangeLog memo ; (autoload 'clmemo "clmemo" "ChangeLog memo mode." t) ; (define-key ctl-x-map "M" 'clmemo) (setq clmemo-file-name "~/public_html/private/ChangeLog") (defun my-open-clmemo () "ChangeLogメモを開く" (interactive) (find-file clmemo-file-name)) (define-key ctl-x-map "m" 'my-open-clmemo) ;全文検索システムNamazuのMule用フロントエンドnamazu.elの設定 (autoload 'namazu "namazu" nil t) ;;; For YaTeX (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t) (add-to-list 'auto-mode-alist '("\\.tex$" . yatex-mode)) (add-hook 'yatex-mode-hook (function (lambda () ; (require 'font-latex) ; (font-latex-setup) (auto-fill-mode nil)))) ; すぐに環境補完に入る。 (setq YaTeX-no-begend-shortcut t) ; 編集するファイルの漢字コードの設定 ;; nil = original, 0 = mule, 1 = Shift JIS, 2 = JIS, 3 = EUC (setq YaTeX-kanji-code nil) ; 閉じ括弧の補完は止める ; → \end{}の補完もやめてしまうのは不便なので、コメントアウト ;(setq-default YaTeX-modify-mode t) ;;; For psgml (SGML/XML の編集) ; (add-to-list 'auto-mode-alist '("\\.xml$" . xml-mode)) ; ;(autoload 'sgml-mode "psgml" "Major mode to edit SGML files." t) ; (autoload 'xml-mode "psgml" "Major mode to edit XML files." t) ; (setq sgml-set-face t) ;; For xslide (XSLT) (autoload 'xsl-mode "xslide" "Major mode for XSL stylesheets." t) (add-to-list 'auto-mode-alist '("\\.xsl$" . xsl-mode)) (setq xsl-indent-attributes t) ;;; HTML ファイルの索引を生成するコマンド (defun html-insert-index () "HTML ファイルの索引を生成するコマンド カレントバッファに含まれる bar タグから 階層的な索引を作成してカーソルの位置に挿入するコマンド 他のファイルへのリンクを索引に付け加えたい場合は、 というタグをその場所に書いておく。 \(? の部分には 1-6 の数字が入る\)" (interactive) (save-match-data (let ((case-fold-search t) ; 大文字/小文字を無視して検索する (tag "
  • %s") (start "") item str p h i) (save-excursion (beginning-of-line) (if (looking-at start) (catch 'search-failed (setq h 0 p (point) str (concat "\\(" (regexp-quote start) "\\|" (regexp-quote end) "\\)\n?")) (while (and (or (re-search-forward str nil t) (throw 'search-failed nil)) (setq h (if (string= start (match-string 1)) (1+ h) (1- h))) (> h 0))) (delete-region p (match-end 0))))) (save-excursion (setq i 0) (goto-char (point-min)) (while (re-search-forward "\\(\\)?" nil t) ; $1 $2 $3 $4 $5 (and (if (string= "name" (downcase (match-string 4))) (setq str (concat "#" (match-string 5))) (and (not (char-equal ?# (char-after (match-beginning 5)))) (match-string 2) (setq str (match-string 5)))) (setq h (string-to-number (or (match-string 2) "7")) p (point)) (search-forward "" (save-excursion (forward-line 3) (point)) t) (cond ((< i h) (setq item (cons start item))) ((> i h) (setq item (cons end item))) (t)) (setq item (cons (format tag str (buffer-substring p (match-beginning 0))) item) i h) ))) (if item ; 索引の項目が発見されなかったら何もしない (progn (setq p (point) i 0) (mapcar (lambda (s) (cond ((string= s start) (setq i (1+ i))) ((string= s end) (setq i (1- i)))) (insert s "\n")) (nreverse item)) (while (> i 0) (insert end "\n") (setq i (1- i))) (indent-region p (point) nil)))))) ;;; For html-helper-mode (autoload 'html-helper-mode "html-helper-mode" "Yay HTML." t) (add-to-list 'auto-mode-alist '("\\.[rpsx]?html?\\(\\.\\(en\\|ja\\|in\\|erb\\)\\)?$" . html-helper-mode)) (add-hook 'html-helper-mode-hook '(lambda () ;(outline-minor-mode t) ;(make-local-variable 'outline-regexp) ;(setq outline-regexp "<[Hh][1-6]*>") (html-helper-add-tag '(logical "o" "" "Original" ("\n" (r "Original: ") "\n"))) (define-key html-helper-mode-functions-map "i" 'html-insert-index) (progn (make-local-variable 'compile-command) (setq compile-command ;; M-x compile とするとhtmllintを起動。 ;; (jweblintでもいいけど) (concat "htmllint -lc -d tab-in-pre " (buffer-file-name)))) ; (define-key html-helper-mode-functions-map ; "j" 'compile-with-jweblint) ; (html-helper-add-tag '(compile "h" "" "compile")) ; (html-helper-add-type-to-alist ; '(compile . (html-helper-compile-map "\C-c\C-x" html-helper-compile-menu "Check HTML Syntax"))) ; (html-helper-install-type 'compile) ; (setq html-helper-user-menu ; "Check Syntax" ; '(["by HTML-lint" compile-with-htmllint t] ; ["by Japanese Weblint" compile-with-jweblint t]) ; "") ; html-helper-user-menu) (define-key html-helper-mode-functions-map "h" 'compile) (setq html-helper-user-menu (cons '["HTML-lint" compile t] html-helper-user-menu)) (html-helper-rebuild-menu))) (setq html-helper-timestamp-template "
    最終更新日: %Y年%m月%d日
    \n") (add-hook 'html-helper-timestamp-hook '(lambda () (insert (format-time-string html-helper-timestamp-template)))) (setq html-helper-build-new-buffer nil) ; autoinsert を使うので無効化 (setq html-helper-build-new-buffer-flag nil) ; autoinsert を使うので無効化 (setq html-helper-use-expert-menu t) ;(setq html-helper-item-continue-indent 4) (setq html-helper-never-indent nil) ;;; For HikiDoc (autoload 'hikidoc-mode "hikidoc-mode") (add-to-list 'auto-mode-alist '("\\.hikidoc\\(\\.en\\|\\.ja\\)?$" . hikidoc-mode)) ;;; For CSS (autoload 'css-mode "css-mode") (add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode)) (setq cssm-indent-function #'cssm-c-style-indenter) ;;; For trr19 (typing) (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/trr") (autoload 'trr "trr" nil t) (setq TRR:return-is-space t) ;;; For apache configuration files ;; (autoload 'apache-mode "apache-mode" "Editing apache configuration file" t) ;; (add-to-list 'auto-mode-alist '("\\.htaccess$" . apache-mode)) ;; (add-to-list 'auto-mode-alist '("httpd\\.conf$" . apache-mode)) ;;; For SDIC (English-Japanese dictionaries) (autoload 'sdic-describe-word "sdic" "英単語の意味を調べる" t nil) (global-set-key "\C-cw" 'sdic-describe-word) (autoload 'sdic-describe-word-at-point "sdic" "カーソルの位置の英単語の意味を調べる" t nil) (global-set-key "\C-cW" 'sdic-describe-word-at-point) ;;; For Auto Lookup minor mode (autoload 'auto-lookup-mode "autolookup" "ポイント下の単語の訳を自動的に表示するマイナーモード" t) (autoload 'global-auto-lookup-mode "autolookup" "ポイント下の単語の訳を自動的に表示するマイナーモードをすべてのバッファで起動する." t) ;; 辞書の検索にSDIC, Lookupどちらを使うかを選ぶ ;(setq auto-lookup-backend 'lookup) (setq auto-lookup-backend 'sdic) ;全てのバッファで auto-lookup-mode を利用する ;(global-auto-lookup-mode) ;;; For w3m-mode (autoload 'w3m "w3m" "Interface for w3m on Emacs." t) (autoload 'w3m-weather "w3m-weather" "*Display weather report." t) ;(setq w3m-weather-default-area "茨城県・南部") (autoload 'w3m-search "w3m-search" "*Search QUERY using SEARCH-ENGINE." t) (setq w3m-search-default-engine "google-ja") ;;; For Migemo (load "migemo" t) ;;; For SKK ;;; (一部は ~/.skk にも…) ;(require 'skk-setup) ;; SKK を Emacs のデフォルト input method として使用する (setq default-input-method "japanese-skk") ;; migemo を使うから skk-isearch にはおとなしくしていて欲しい (if (featurep 'migemo) (setq skk-isearch-start-mode 'latin)) ;; メッセージを日本語で通知する (setq skk-japanese-message-and-error t) ;; 変換時に註釈 (annotation) を表示する (setq skk-show-annotation t) ;; Enter キーを押したときには確定する (setq skk-egg-like-newline t) ;; 対応する閉括弧を自動的に挿入する (setq skk-auto-insert-paren t) ;; 動的な補完を使う (setq skk-dcomp-activate t) ;; 送り仮名が厳密に正しい候補を優先して表示する (setq skk-henkan-strict-okuri-precedence t) ;; 送りあり変換を送りなし変換と同じ操作でできるようにする (setq skk-auto-okuri-process t) ;; 複数の Emacsen を起動しても個人辞書を共有する (setq skk-share-private-jisyo t) ;; BS を押しても確定しない (setq skk-delete-implies-kakutei nil) ;;; For Anthy ;(load "anthy") ;(global-set-key "\C-\\" 'anthy-mode) ;;; For PoBox-el ;(load "pobox-conf") ;;; For IIIMECF (Atok)? ; (setq coding-category-utf-8 'utf-8 ; iiimcf-server-control-hostlist '("localhost") ; Iiimc-server-control-default-language "ja" ; default-input-method 'iiim-server-control) ; (require 'iiimcf-sc) ; (setcar default-mode-line-format "") ; (setq default-input-method 'iiim-server-control) ;;; MELL (Emacs Lisp ライブラリ) ;(require 'init-mell) ;;; Suikyo (ローマ字ひらがな変換ライブラリ) ;(require 'suikyo) ;;; PRIME for Emacs ;(require 'init-prime) ;;; For session.el: (when (require 'session nil t) ;; from http://www.fan.gr.jp/~ring/Meadow/meadow.html#session.el (setq session-globals-include '((kill-ring 50) (session-file-alist 100 t) (file-name-history 100))) (add-hook 'after-init-hook 'session-initialize)) ;;; For recentf.el ;(require 'recentf nil t) ;(recentf-mode t) ;;; For ac-mode.el ;(load "ac-mode") ;(setq ac-mode-goto-end-of-word t) ;(add-hook 'find-file-hooks 'ac-mode-without-exception) ;;; For minibuf-isearch.el (require 'minibuf-isearch nil t) ;;; For word-count.el (require 'word-count nil t) (if (featurep 'word-count) (add-to-list 'word-count-preremove-regexp-alist '(yatex-mode . ("\\\\%" "%.*$")))) ;;; For Navi2ch (autoload 'navi2ch "navi2ch" "Navigator for 2ch for Emacs" t) ;;; For Wikipedia (autoload 'wikipedia-mode "wikipedia-mode.el" "Major mode for editing documents in Wikipedia markup." t) (add-to-list 'auto-mode-alist '("\\.wiki\\'" . wikipedia-mode)) ;;; For YAML-mode ;(autoload 'yaml-mode "yaml-mode.el" ; "Major mode for editing documents in YAML." t) ;(add-to-list 'auto-mode-alist '("\\.yaml\\'" . yaml-mode)) ;;; For mmm-mode (require 'mmm-mode nil t) (require 'mmm-sample nil t) (if (featurep 'mmm-mode) (progn ;(setq mmm-global-mode t) (setq mmm-global-mode 'maybe) (setq mmm-submode-decoration-level 2) (set-face-background 'mmm-default-submode-face "Green") (set-face-foreground 'mmm-default-submode-face "Black") ;; eRuby (mmm-add-group 'eruby '((eruby-ruby :submode ruby-mode :front "<%" :back "%>"))) (mmm-add-mode-ext-class 'html-helper-mode "\\.rhtml\\'" 'eruby) (mmm-add-mode-ext-class 'html-helper-mode nil 'embedded-css) (mmm-add-mode-ext-class nil "\\.php\\'" 'html-php) )) ;;; For PHP-mode (autoload 'php-mode "php-mode" "Mode for editing PHP files") ;;; For JS2 (autoload 'js2-mode "js2" nil t) (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)) ;;; For color-selection (autoload 'list-hexadecimal-colors-display "color-selection" "Display hexadecimal color codes, and show what they look like." t) ;;; For GraphViz DOT format (autoload 'graphviz-dot-mode "graphviz-dot-mode" "GraphViz DOT format" t) (add-to-list 'auto-mode-alist '("\\.dot$" . graphviz-dot-mode)) ;;; For Python mode (add-to-list 'auto-mode-alist '("\\.py$" . python-mode)) (autoload 'python-mode "python-mode" "Python editing mode." t) ;;; For Markdown mode (autoload 'markdown-mode "markdown-mode" "Major mode for editing Markdown files" t) (add-to-list 'auto-mode-alist '("\\.markdown$" . markdown-mode)) (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))