2012年2月6日月曜日

.emacsの設定(for NT)

;; keyset
(global-set-key "\C-h" 'backward-delete-char) ;C-h as BackSpace
(global-set-key "\M-?" 'help-for-help)        ;M-? as help
;;(global-set-key "\C-q" 'dabbrev-expand)
(global-set-key "\C-m" 'newline-and-indent)
(global-set-key "\M-g" 'goto-line)

;;(global-set-key "\C-q" 'quoted-insert)       ;C-q original
(defun buffer-menu-other-window-move ()
  (interactive)
  (buffer-menu-other-window)
  (next-window))
(global-set-key "\C-x\C-b" 'buffer-menu-other-window-move)
(defun other-window-or-split ()
  (interactive)
  (when (one-window-p)
    ;;(split-window-horizontally)
    (split-window-vertically)
    )
  (other-window 1))
;;(global-set-key "\C-t" 'other-window-or-split)

;; パスの設定
(let* ((cygwin-root "c:/cygwin")
       (cygwin-bin (concat cygwin-root "/bin")))
  ;;(setenv "HOME" (concat cygwin-root "/home/eric"))
  (setenv "PATH" (concat cygwin-bin ";" (getenv "PATH")))
  (setq exec-path (cons cygwin-bin exec-path))
  (setq shell-file-name "bash")
  (setq explicit-shell-file-name "bash")
  (add-hook 'comint-mode-hook 'ansi-color-for-comint-mode-on))


(cd "~")                            ;start on home directory
(setq-default indent-tabs-mode nil) ;When pushing [TAB],  input WhiteSpaces.

;; 滑らかなスクロール
(setq redisplay-dont-pause t)


;; テーマ
;;(require 'color-theme)
;;(color-theme-initialize)
;;(color-theme-clarity)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 日本語環境の設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set-keyboard-coding-system 'japanese-shift-jis)
(setq default-input-method "W32-IME")
(w32-ime-initialize)

;; UTF-8⇔Legacy Encoding (EUC-JP や Shift_JIS など)をWindowsで変換
;;  http://nijino.homelinux.net/emacs/emacs23-ja.html
(coding-system-put 'euc-jp :encode-translation-table
                   (get 'japanese-ucs-cp932-to-jis-map 'translation-table))
(coding-system-put 'iso-2022-jp :encode-translation-table
                   (get 'japanese-ucs-cp932-to-jis-map 'translation-table))
(coding-system-put 'cp932 :encode-translation-table
                   (get 'japanese-ucs-jis-to-cp932-map 'translation-table))
;; charset と coding-system の優先度設定
(set-charset-priority 'ascii 'japanese-jisx0208 'latin-jisx0201
                      'katakana-jisx0201 'iso-8859-1 'cp1252 'unicode)
(set-coding-system-priority 'utf-8 'euc-jp 'iso-2022-jp 'cp932)
;; East Asian Ambiguous
(defun set-east-asian-ambiguous-width (width)
  (while (char-table-parent char-width-table)
    (setq char-width-table (char-table-parent char-width-table)))
  (let ((table (make-char-table nil)))
    (dolist (range
             '(#x00A1 #x00A4 (#x00A7 . #x00A8) #x00AA (#x00AD . #x00AE)
                      (#x00B0 . #x00B4) (#x00B6 . #x00BA) (#x00BC . #x00BF)
                      #x00C6 #x00D0 (#x00D7 . #x00D8) (#x00DE . #x00E1) #x00E6
                      (#x00E8 . #x00EA) (#x00EC . #x00ED) #x00F0
                      (#x00F2 . #x00F3) (#x00F7 . #x00FA) #x00FC #x00FE
                      #x0101 #x0111 #x0113 #x011B (#x0126 . #x0127) #x012B
                      (#x0131 . #x0133) #x0138 (#x013F . #x0142) #x0144
                      (#x0148 . #x014B) #x014D (#x0152 . #x0153)
                      (#x0166 . #x0167) #x016B #x01CE #x01D0 #x01D2 #x01D4
                      #x01D6 #x01D8 #x01DA #x01DC #x0251 #x0261 #x02C4 #x02C7
                      (#x02C9 . #x02CB) #x02CD #x02D0 (#x02D8 . #x02DB) #x02DD
                      #x02DF (#x0300 . #x036F) (#x0391 . #x03A9)
                      (#x03B1 . #x03C1) (#x03C3 . #x03C9) #x0401
                      (#x0410 . #x044F) #x0451 #x2010 (#x2013 . #x2016)
                      (#x2018 . #x2019) (#x201C . #x201D) (#x2020 . #x2022)
                      (#x2024 . #x2027) #x2030 (#x2032 . #x2033) #x2035 #x203B
                      #x203E #x2074 #x207F (#x2081 . #x2084) #x20AC #x2103
                      #x2105 #x2109 #x2113 #x2116 (#x2121 . #x2122) #x2126
                      #x212B (#x2153 . #x2154) (#x215B . #x215E)
                      (#x2160 . #x216B) (#x2170 . #x2179) (#x2190 . #x2199)
                      (#x21B8 . #x21B9) #x21D2 #x21D4 #x21E7 #x2200
                      (#x2202 . #x2203) (#x2207 . #x2208) #x220B #x220F #x2211
                      #x2215 #x221A (#x221D . #x2220) #x2223 #x2225
                      (#x2227 . #x222C) #x222E (#x2234 . #x2237)
                      (#x223C . #x223D) #x2248 #x224C #x2252 (#x2260 . #x2261)
                      (#x2264 . #x2267) (#x226A . #x226B) (#x226E . #x226F)
                      (#x2282 . #x2283) (#x2286 . #x2287) #x2295 #x2299 #x22A5
                      #x22BF #x2312 (#x2460 . #x24E9) (#x24EB . #x254B)
                      (#x2550 . #x2573) (#x2580 . #x258F) (#x2592 . #x2595)
                      (#x25A0 . #x25A1) (#x25A3 . #x25A9) (#x25B2 . #x25B3)
                      (#x25B6 . #x25B7) (#x25BC . #x25BD) (#x25C0 . #x25C1)
                      (#x25C6 . #x25C8) #x25CB (#x25CE . #x25D1)
                      (#x25E2 . #x25E5) #x25EF (#x2605 . #x2606) #x2609
                      (#x260E . #x260F) (#x2614 . #x2615) #x261C #x261E #x2640
                      #x2642 (#x2660 . #x2661) (#x2663 . #x2665)
                      (#x2667 . #x266A) (#x266C . #x266D) #x266F #x273D
                      (#x2776 . #x277F) (#xE000 . #xF8FF) (#xFE00 . #xFE0F)
                      #xFFFD
                      ))
      (set-char-table-range table range width))
    (optimize-char-table table)
    (set-char-table-parent table char-width-table)
    (setq char-width-table table)))
(set-east-asian-ambiguous-width 2)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 画面設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ウィンドウ(Emacs用語ではframe)設定
(setq default-frame-alist
      (append (list
               ;; サイズ・位置
               '(width . 80)  ; 横幅(文字数)
               '(height . 46) ; 高さ(行数)
               '(top . 50)    ; フレーム左上角 y 座標
               '(left . 50)   ; フレーム左上角 x 座標
               )
              default-frame-alist))

;; 背景色を黒、文字を白、カーソルをグレー
(set-background-color "Black")
(set-foreground-color "White")

;; シンタックスハイライト用
(set-face-bold-p 'font-lock-function-name-face t)

;; erase memubar, scrollbar
;;(menu-bar-mode -1)       ;画面上に出るメニュー(文字)を消す
(tool-bar-mode -1)       ;画面上に出るツールバー(アイコン画像)を消す
                    ;(scroll-bar-mode -1)    ;画面横に出るスクロールバーを消す
(setq inhibit-startup-message t) ;スプラッシュ(起動画面)抑止
(column-number-mode 1)


;; emacs-server
;;(server-start)

;; フォント設定
(set-default-font "Osaka-等幅-11")
;; (set-fontset-font "fontset-default"
;;                   'japanese-jisx0208
;;                   '("Osaka-UI" . "iso10646-1"))
;; (set-fontset-font "fontset-default"
;;                   'katakana-jisx0201
;;                   '("Osaka-UI" . "iso10646-1"))
;; (set-default-font "Courier New-10")
;; (set-fontset-font (frame-parameter nil 'font)
;;           'japanese-jisx0208
;;           '("Osaka-UI" . "unicode-bmp"))
;;(set-default-font "MS ゴシック-10")

;; color
(global-font-lock-mode t)  ;font-lock use-all
(transient-mark-mode t)    ;選択したとき色がつくようにする

;; kill-ring はテキスト属性(色情報など)を保存しなくていい
;;  http://www-tsujii.is.s.u-tokyo.ac.jp/~yoshinag/tips/elisp_tips.html#yankoff
(defadvice kill-new (around my-kill-ring-disable-text-property activate)
  (let ((new (ad-get-arg 0)))
    (set-text-properties 0 (length new) nil new)
    ad-do-it))

;; タブ, 全角スペースを色つき表示する (色名は M-x list-color-displayで調べる)
;;  http://homepage1.nifty.com/blankspace/emacs/color.html
(defface my-face-b-1 '((t (:background "LightGray"))) nil)
(defface my-face-b-2 '((t (:background "gray7"))) nil)
(defvar my-face-b-1 'my-face-b-1)
(defvar my-face-b-2 'my-face-b-2)
(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-b-1 append)
     )))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)

;; IMEのON/OFFでカーソルの色を変える
(set-cursor-color "cyan")
(add-hook 'w32-ime-on-hook
          (function (lambda () (set-cursor-color "LimeGreen"))))
(add-hook 'w32-ime-off-hook
          (function (lambda () (set-cursor-color "cyan"))))

;; elisp変数表示のとき途中で省略しない
(setq eval-expression-print-level nil)
(setq eval-expression-print-length nil)

;; リンクの設定
(setq w32-symlinks-handle-shortcuts t)
(require 'w32-symlinks)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 動作設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; tmp file saving directory
(setq auto-save-list-file-prefix "~/local/.emacs.d/.saves-")

;; backup.file~ location
(setq make-backup-files t)
(setq backup-directory-alist
      (cons (cons "\\.*$" (expand-file-name "~/local/.emacs.d"))
            backup-directory-alist))

;; 前回編集していた場所を記憶し,ファイルを開いた時にそこへカーソルを移動
(require 'saveplace)
(setq-default save-place t)

;; auto-insert LAST-MODIFIED-DATE
(if (not (memq 'time-stamp write-file-hooks))
    (setq write-file-hooks
          (cons 'time-stamp write-file-hooks)))
(setq time-stamp-line-limit 40)
(setq time-stamp-format "%3b %02d %:y")
(setq system-time-locale "C")


;; dabbrev for japanese
(setq case-replace nil)             ;dabbrev exact (upper or lower)case
(setq dabbrev-case-fold-search nil) ;dabbrev exact case
;;  http://www.ysnb.net/meadow/meadow-users-jp/2000/msg00788.html
(defadvice dabbrev-expand (around jword (arg) activate)
  (interactive "*P")
  (let* ((regexp dabbrev-abbrev-char-regexp)
         (dabbrev-abbrev-char-regexp regexp)
         char ch)
    (if (bobp)
        ()
      (setq char (char-before)
            ch (char-to-string char))
      (cond
       ((string-match "[ァ-ヶー]" ch)
        (setq dabbrev-abbrev-char-regexp "[ァ-ヶー]"))
       ((string-match "[ぁ-んー]" ch)
        (setq dabbrev-abbrev-char-regexp "[ぁ-んー]"))
       ((string-match "[亜-瑤]" ch)
        (setq dabbrev-abbrev-char-regexp "[亜-瑤]"))
       ((string-match "[A-Za-z0-9]" ch)
        (setq dabbrev-abbrev-char-regexp "[A-Za-z0-9]"))
       ((eq (char-charset char) 'japanese-jisx0208)
        (setq dabbrev-abbrev-char-regexp
              (concat "["
                      (char-to-string (make-char 'japanese-jisx0208 48 33))
                      "-"
                      (char-to-string (make-char 'japanese-jisx0208 126 126))
                      "]")))))
    ad-do-it))

;; "*Buffer List*" から動的補完する。
;;  Javaのclass名をファイルに付けたらファイルの中でも補完できるように。
(setq dabbrev-ignored-buffer-names '("*Messages*"))

;; beep
(setq visible-bell nil)

;; diff
(setq diff-switches "-u")

;; elisp load-path
(add-to-list 'load-path "~/.emacs.d")

;; cc-mode
(defun my-c-mode-common-hook ()
  (c-set-style "java")
  )
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(add-to-list 'auto-mode-alist '("\\.c\\'" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.cpp\\'" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.pl\\'" . perl-mode))
(add-to-list 'auto-mode-alist '("\\.rb\\'" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))

;;; js2-mode for JavaScript
;;(autoload 'js2-mode "js2" nil t)
;;(add-to-list 'auto-mode-alist '("\.js$" . js2-mode))

;;; actionscript-mode
;;(autoload 'actionscript-mode "actionscript-mode" "Major mode for actionscript." t)
;;(add-to-list 'auto-mode-alist '("\\.as$" . actionscript-mode))

;;; php-mode
;;(autoload 'php-mode "php-mode" nil t)
;;(add-hook 'php-mode-hook
;;          '(lambda () (define-abbrev php-mode-abbrev-table "ex" "extends")))
;;(add-to-list 'auto-mode-alist '("\.php$" . php-mode))

;; Ini, batモード
(require 'generic-x)

;; moccur-edit
(require 'moccur-edit)
;; moccur-grep-findで.svnを無視する
(setq dmoccur-exclusion-mask
      (append
       '("\\~$" "\\.svn\\/\*" "bin\\/\*" "\\.jar$")
       dmoccur-exclusion-mask))



;; scratchのメッセージ表示をしない
(setq initial-scratch-message "")


;; sessionの設定
(require 'session)
(setq inhibit-startup-message t)
(setq session-initialize '(de-saveplace session keys menus places)
      session-globals-include '((kill-ring 50)
                (session-file-alist nil)
                (file-name-history 10000)))
;; これがないと file-name-history に500個保存する前に max-string に達する
(setq session-globals-max-string 100000000)
;; デフォルトでは30!
(setq history-length t)
(add-hook 'after-init-hook 'session-initialize)
;; 前回閉じたときの位置にカーソルを復帰
(setq session-undo-check -1)

;; wdired
(require 'wdired)
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)


;; 行番号表示
(require 'linum)

;; タブ化
;;(require 'tabbar-extension)
;;(tabbar-mode)


(global-set-key [f9] 'linum-mode)
;; メージャーモード/マイナーモードでの指定
(defvar my-linum-hook-name nil)
(global-linum-mode t)

;; textile
(require 'textile-mode)
(add-to-list 'auto-mode-alist '("\.textile$" . textile-mode))

;; Dot-mode
(autoload 'graphviz-dot-mode "graphviz-dot-mode" "GraphViz DOT format" t)
(add-to-list 'auto-mode-alist '("\\.dot$" . graphviz-dot-mode))

;; uniq
(defun uniq-region (beg end)
  "Remove duplicate lines, a` la Unix uniq.
   If tempted, you can just do <<C-x h C-u M-| uniq RET>> on Unix."
  (interactive "r")
  (let ((ref-line nil))
    (uniq beg end
      (lambda (line) (string= line ref-line))
      (lambda (line) (setq ref-line line)))))

(defun uniq-remove-dup-lines (beg end)
  "Remove all duplicate lines wherever found in a file, rather than
   just contiguous lines."
  (interactive "r")
  (let ((lines '()))
    (uniq beg end
      (lambda (line) (assoc line lines))
      (lambda (line) (add-to-list 'lines (cons line t))))))

(defun uniq (beg end test-line add-line)
  (save-restriction
    (save-excursion
      (narrow-to-region beg end)
      (goto-char (point-min))
      (while (not (eobp))
    (if (funcall test-line (thing-at-point 'line))
        (kill-line 1)
      (progn
        (funcall add-line (thing-at-point 'line))
        (forward-line))))
      (widen))))

(defun clipboard-to-buffer-file-name ()
  "Put the current file name on the clipboard"
  (interactive)
  (let ((filename (if (equal major-mode 'dired-mode)
                      default-directory
                    (buffer-file-name))))
    (when filename
      (with-temp-buffer
        (insert filename)
        (clipboard-kill-region (point-min) (point-max)))
      (message filename))))


;;; use groovy-mode when file ends in .groovy or has #!/bin/groovy at start
(autoload 'groovy-mode "groovy-mode" "Groovy editing mode." t)
(add-to-list 'auto-mode-alist '("\.groovy$" . groovy-mode))
(add-to-list 'interpreter-mode-alist '("groovy" . groovy-mode));;; Local Variables:

;; テンポラリバッファを作成し、それをウィンドウに表示します。
(defun create-temporary-buffer ()
  "テンポラリバッファを作成し、それをウィンドウに表示します。"
  (interactive)
  ;; *temp* なバッファを作成し、それをウィンドウに表示します。
  (switch-to-buffer (generate-new-buffer "*temp*"))
  ;; セーブが必要ないことを示します?
  (setq buffer-offer-save nil))
;; C-c t でテンポラリバッファを作成します。
(global-set-key "\C-ct" 'create-temporary-buffer)

0 件のコメント:

コメントを投稿