.emacs
;; Last Modified: 2007/02/08 (Thu) 11:42:48 JST by Shigeyuki Osada
;; Information-tag: /usr/home/osada_ns/.emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 言語設定 文字入力に関する設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; 不要だけど...一応
(set-language-environment "Japanese")
(set-default-coding-systems 'euc-japan)
(set-terminal-coding-system 'euc-japan)
;;;;;;; IMEによる日本語入力
(set-keyboard-coding-system 'euc-japan)
;;;;;;; i-searchで日本語を使う
;;;;;;; i-search中に,C-kを押してから,検索ワードを入力
(define-key isearch-mode-map "\C-k" 'isearch-edit-string)
;;;;;;; Egg for FreeWnn
(setq its-hira-comma ",")
(setq its-hira-period ".")
(setq its-hira-enable-zenkaku-alphabet nil)
(defun toggle-kutoten ()
;;;;;;; "句読点を 「,」「.」にするか「、」「。」にするか切り替える。"
(interactive)
(if (equal its-hira-comma "、")
(progn
(setq its-hira-comma ",") ; “,”を“,”に変換
(setq its-hira-period ".") ; “.”を“.”に変換
(message ",.モード"))
(setq its-hira-comma "、") ; “,”を“、”に変換
(setq its-hira-period "。") ; “.”を“。”に変換
(message "、。モード")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 表示に関する設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; 全体的なデザイン
(setq default-frame-alist
(append
'((foreground-color . "AntiqueWhite") ; 前景色
(background-color . "black") ; 背景色
;; (cursor-color . "DarkGreen") ; カーソル色
(cursor-color . "Green") ; カーソル色
(width . 114) ; フレーム幅(文字数)
(height . 48) ; フレーム高(文字数)
(top . 50) ; フレームの Y 位置(ピクセル数)
(left . 10) ; フレームの X 位置(ピクセル数)
)
default-frame-alist))
;;;;;;; モードラインの設定
(set-face-foreground 'modeline "black")
(set-face-background 'modeline "green")
(line-number-mode t) ;; 行数
(column-number-mode t) ;; 桁数
;;;;;;;; 現在ポイントがある関数名をモードラインに表示
(which-function-mode 1)
;;;;;;;; 対応する括弧をハイライト
(show-paren-mode t)
;;;;;;;; リージョンのハイライト
(transient-mark-mode t)
;;;;;;;; font-lock-mode の設定
(global-font-lock-mode t) ; font-lock-mode を常時利用する
(setq font-lock-support-mode 'jit-lock-mode) ;; Just in Time
;;;;;;;; スクロールバーを右
(set-scroll-bar-mode 'right)
;;;;;;;; ターミナルのときメニューを表示しない
(if (eq window-system 'x)
(menu-bar-mode 1) (menu-bar-mode 0))
;;;;;;;; ^M をとる(問題あるかも?)
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)
;;;;;;;; 全角スペースなどを表示
;;(defface my-face-r-1 '((t (:background "gray15"))) nil)
(defface my-face-b-1 '((t (:background "gray"))) nil)
(defface my-face-b-2 '((t (:background "gray15"))) nil) ;; 15%くらいGray
(defface my-face-u-1 '((t (:foreground "SteelBlue" :underline t))) nil)
;;(defvar my-face-r-1 'my-face-r-1)
(defvar my-face-b-1 'my-face-b-1)
(defvar my-face-b-2 'my-face-b-2)
(defvar my-face-u-1 'my-face-u-1)
(defadvice font-lock-mode (before my-font-lock-mode ())
(font-lock-add-keywords
major-mode
'(("\t" 0 my-face-b-2 append)
(" " 0 my-face-b-1 append)
("[ \t]+$" 0 my-face-u-1 append)
;;("[\r]*\n" 0 my-face-r-1 append)
)))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)
;;;;;;; font-lock色緩和
(defun egoge-wash-out-colour (colour)
"Return a colour string specifying a washed-out version of COLOUR."
(let ((basec (color-values
(face-attribute 'default :foreground)))
(list nil))
(apply 'format "#%02x%02x%02x"
(dolist (cv (color-values colour) (nreverse list))
;; 暗い色(背景が白むけ)
;; (push (/ (/ (+ cv (* 3 (car basec))) 2) 256) list)))))
;; 鮮やかな色(背景が黒むけ)
(push (/ (/ (+ cv (* 3 (car basec))) 1) 256) list)))))
(defun egoge-wash-out-face (face)
"Make the foreground colour of FACE appear a bit more pale."
(let ((colour (face-attribute face :foreground)))
(unless (eq colour 'unspecified)
(set-face-attribute face nil
:foreground (egoge-wash-out-colour colour)))))
(defun egoge-find-faces (regexp)
"Return a list of all faces whose names match REGEXP."
(delq nil
(mapcar (lambda (face)
(and (string-match regexp
(symbol-name face))
face))
(face-list))))
(when (> (length (defined-colors)) 16)
(mapc 'egoge-wash-out-face
(delq 'font-lock-warning-face (egoge-find-faces "^font-lock"))))
;;;;;;; PHP-mode
;;(load-library "php-mode")
;;(require 'php-mode)
;; .hpp と .h を C++ の拡張子とする(.h の方は余計かも)
(setq auto-mode-alist
(append
'(("\\.php$" . html-mode)
("\\.phps$" . html-mode)
) auto-mode-alist))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 操作に関する設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; スクロールマウスを有効
(global-set-key [mouse-4] 'scroll-down)
(global-set-key [mouse-5] 'scroll-up)
;;;;;;; 指定行にjump
(global-set-key "\C-l" 'goto-line)
;;;;;;; 元に戻す
(global-set-key "\C-u" 'undo)
;;;;;;; Ctrl+H(Backspace)で一文字削除
(global-set-key "\C-h" 'backward-delete-char)
;;;;;;; [delete]で,通常のdelと同じ動作
(global-set-key [delete] 'delete-char)
;;;;;;; 行の先頭で Ctrl-k を押すとその行ごと削除
(setq kill-whole-line t)
;;;;;;; 1行づつスクロールする
(setq scroll-conservatively 1)
;;;;;;; デフォルトのタブ幅を 4 に設定
(setq-default tab-width 4)
;;;;;;; インデントして、次の行に移動する
(defun indent-and-next-line ()
(interactive)
(indent-according-to-mode)
(next-line 1))
;;;;;;; F-5でコンパイル
(global-set-key [f5] 'compile)
(setq compilation-window-height 10)
;;;;;;; .x .F .pl ファイルを読み込んだ時のモード設定
;;(setq auto-mode-alist (cons (cons "\\.pl$" 'c-mode) auto-mode-alist))
;;;;;;; perl と java における tab キーのインデントの深さ
(add-hook 'perl-mode-hook '(lambda ()
(setq tab-width 4) ; タブ記号のインデント深さ
) t)
(add-hook 'java-mode-hook '(lambda ()
(setq tab-width 4) ; タブ記号のインデント深さ
) t)
;;;;;;; C 言語モードの設定
(add-hook 'c-mode-hook '(lambda ()
(cond ((boundp 'MULE)
(load "c-mode.el")
))
(setq c-basic-offset 8)
(setq c-tab-width 8)
(setq c-argdecl-indent 0) ; 関数の引数行のインデント
; 但し引数行で明示的にタブを押さない
; 場合は、インデントしない
; (setq c-auto-newline t) ; 自動改行
(setq c-auto-newline nil) ; 自動改行
(setq c-continued-statement-offset 0) ; { を書く時のインデント
; (setq c-continued-statement-offset 4) ; { を書く時のインデント
(setq c-indent-level 8) ; { を書いた後のインデント
(setq c-label-offset -4) ; ラベルの深さ
(setq c-tab-always-indent t) ; タブ記号を押した時にユーザーが
; 任意にタブ記号を入れることは不可
(setq tab-width 8) ; タブ記号のインデント深さ
(setq c-brace-imaginary-offset 0) ; 不明
(setq c-brace-offset 0) ; 不明
) t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 編集補助・補完
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; last modified: が指定した場所にあれば,修正時に変更
(require 'time-stamp)
;; 日本語で日付を入れたくないのでlocaleをCにする
(defun time-stamp-with-locale-c ()
(let ((system-time-locale "C"))
(time-stamp)
nil))
;; time-stampの実行よりも前に定義しておく必要がある。
;; (if (not (memq 'time-stamp-with-locale-c write-file-hooks)) ;; 21.4 以降
;; (add-hook 'write-file-hooks 'time-stamp-with-locale-c)) ;; 21.4
(if (not (memq 'time-stamp-with-locale-c write-file-hooks)) ;; 21.3 以前
(setq write-file-hooks
(cons 'time-stamp-with-locale-c write-file-hooks))) ;; 21.3
;;(add-hook 'before-save-hook 'time-stamp) ;; Emacs 21.4 以降
(if (not (memq 'time-stamp write-file-hooks)) ;; Emacs 21.3 以前
(setq write-file-hooks ;; 21.3
(cons 'time-stamp write-file-hooks))) ;; 21.3
(setq time-stamp-active t)
(setq time-stamp-start "[Ll]ast[ \-][Mm]odified:")
(setq time-stamp-format " %04y/%02m/%02d (%3a) %02H:%02M:%02S %Z by %U")
(setq time-stamp-end "$") ;; End of file
;;(setq time-stamp-end " \\|$") ;; Space or End of line
(setq time-stamp-line-limit 10) ;; ファイルの先頭から10行以内を探す
;;(setq time-stamp-line-limit -4) ;; ファイルの後ろから 4行以内を検索
;;;;;;;; Information タグの挿入(ファイル名。全文から検索。)
(defun set-information-tag ()
(let ((buffer-file-name (buffer-file-name))
(tostr (concat "Information-tag: " buffer-file-name)))
(save-excursion
(goto-char (point-min))
(while (re-search-forward
"Information-tag:[ A-Za-z0-9\\./\\-_]*$" nil t)
(replace-match tostr nil t)))))
(add-hook 'write-file-hooks 'set-information-tag)
;;;;;;;; 先頭が#!から始まる場合,実行権限をつけて保存
(add-hook 'after-save-hook
'executable-make-buffer-file-executable-if-script-p)
;;;;;;;; 補完用Lispのロード (M-xなどのミニバッファを使うもののみ)
;;(load "complete")
;;;;;;;; 常時補完可能なものを表示する
(icomplete-mode 1)
;;;;;;;; 単語単位で補完する (e.g. p_h -> public_htmlm, _.-)
(partial-completion-mode 1)
;;;;;;;; 大文字と小文字を含めて補完する
(setq completion-ignore-case t)
;;;;;;;; C-jで補完 通常はM-/
(global-set-key "\C-j" 'dabbrev-expand)
;;;;;;;; M-C-jで補完リスト表示
(global-set-key "\M-\C-j" 'dabbrev-completion)
;;;;;;;; 補完の便利設定 ???? C-modeでは無効っぽい(それ以外では有効)
;;;;; \C-iは,Tabを意味する。
;;(define-key completion-list-mode-map "\C-i" 'next-completion)
;;(define-key completion-list-mode-map "\M-\C-i" 'previous-completion)
;;(define-key completion-list-mode-map "f" 'next-completion)
;;(define-key completion-list-mode-map "b" 'previous-completion)
;;(define-key completion-list-mode-map "n" 'next-line)
;;(define-key completion-list-mode-map "p" 'previous-line)
;;(define-key completion-list-mode-map " " 'scroll-up)
;;(define-key completion-list-mode-map [del] 'scroll-down)
;;(define-key completion-list-mode-map [backspace] 'scroll-down)
;;(define-key completion-list-mode-map "q" 'delete-completion-window)
;;;;;;;; shell-modeで上下で補完したい
(setq shell-mode-hook
(function (lambda ()
(define-key shell-mode-map [up] 'comint-previous-input)
(define-key shell-mode-map [down] 'comint-next-input))))
;;;;;;;; 前回編集していた場所を記憶
(load "saveplace")
(setq-default save-place t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; そのほかの設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; 動作を快適にする(値が大きいほど,ガーベジコレクションの頻度低下)
;; default: 400,000
(setq gc-cons-threshold 5242880)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lisp アプリケーションの設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Mewの設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'mew "mew" nil t)
(autoload 'mew-send "mew" nil t)
;;; Mew-Makefile の etcdir で指定したディレクトリ
(setq mew-icon-directory "/usr/local/lib/emacs/etc/Mew")
(if (boundp 'read-mail-command)
(setq read-mail-command 'mew))
(autoload 'mew-user-agent-compose "mew" nil t)
(if (boundp 'mail-user-agent)
(setq mail-user-agent 'mew-user-agent))
(if (fboundp 'define-mail-user-agent)
(define-mail-user-agent
'mew-user-agent
'mew-user-agent-compose
'mew-draft-send-message
'mew-draft-kill
'mew-send-hook))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; For Global
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq load-path (cons "/usr/home/osada_ns" load-path))
(autoload 'gtags-mode "gtags" "" t)
(global-set-key "\C-cg" 'gtags-mode)
(global-set-key "\C-cv" 'gtags-visit-rootdir)
(global-set-key "\C-ct" 'gtags-find-tag)
(global-set-key "\C-cr" 'gtags-find-rtag)
(global-set-key "\C-cs" 'gtags-find-symbol)
(setq gtags-rootdir "/usr/home/osada_ns/ns-allinone-2.28/ns-2.28")
(setq gtags-select-mode-hook
'(lambda ()
(local-set-key "\C-m" 'gtags-select-tag)
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Spell Checker: aspell (要インストール)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; aspellらしい(スペルチェッカー)
(setq ispell-program-name "aspell")
;;; 日本語を無視して,英語のスペルチェックを実施する.
(eval-after-load "ispell"
'(setq ispell-skip-region-alist (cons '("[^\000-\377]")
ispell-skip-region-alist)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; W3M
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;(require 'w3m-load)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CSS mode requires css-mode.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'css-mode "css-mode")
(setq auto-mode-alist
(cons '("\\.css\\'" . css-mode) auto-mode-alist))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; バイナリエディタとして使う
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun YAMA-file-binary-p (file &optional full)
"Return t if FILE contains binary data. If optional FULL is non-nil,
check for the whole contents of FILE, otherwise check for the first
1000-byte."
(let ((coding-system-for-read 'binary)
default-enable-multibyte-characters)
(with-temp-buffer
(insert-file-contents file nil 0 (if full nil 1000))
(goto-char (point-min))
(and (re-search-forward
"[\000-\010\016-\032\034-\037]"
nil t)
t))))
(defadvice find-file (around YAMA-find-file (file &optional wild))
(if (and
(condition-case nil (YAMA-file-binary-p file)(error))
(y-or-n-p "バイナリデータとして編集しますか?")
)
(hexl-find-file file)
ad-do-it
))
(ad-activate 'find-file)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 使用していないアプリケーションたち
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; hogememoの設定
(autoload 'hogememo "hogememo" "HogeMemo" t nil)
(define-key esc-map "m" 'hogememo)
;; navi2ch
(autoload 'navi2ch "navi2ch" "Navigator for 2ch for Emacs" t)
(setq navi2ch-mona-enable t)