.emacsの設定その後

emacs23

始めっぱなしで続かないのはあまり良いこととは思えず久しぶりに更新します。
osもxpからubuntuに乗り換えいろいろあって変わりに変わった.emacsの設定を久しぶりに。

;======================================================================
; 言語・文字コード関連の設定
;======================================================================
(when (equal emacs-major-version 21) (require 'un-define))
(set-language-environment "Japanese")
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(setq file-name-coding-system 'utf-8)
;;
;======================================================================
; Anthy
;    CTRL-\で入力モード切替え
;======================================================================
(load-library "anthy")
(setq default-input-method "japanese-anthy")
;;
;=======================================================================
;フォント
;=======================================================================
(cond (window-system
	(set-default-font "-unknown-IPA モナー ゴシック-normal-normal-normal-*-15-*-*-*-d-0-iso10646-1")
       (progn
         (set-face-font 'default
                        "-unknown-IPA モナー ゴシック-normal-normal-normal-*-15-*-*-*-d-0-iso10646-1")
         (set-face-font 'bold
                        "-unknown-IPA モナー ゴシック-normal-normal-normal-*-15-*-*-*-d-0-iso10646-1")
         (set-face-font 'italic
                        "-unknown-IPA モナー ゴシック-normal-normal-normal-*-15-*-*-*-d-0-iso10646-1")
         (set-face-font 'bold-italic
                        "-unknown-IPA モナー ゴシック-normal-normal-normal-*-15-*-*-*-d-0-iso10646-1")
       )))
;;
;=======================================================================
;フレームサイズ・位置・色など
;=======================================================================
(setq initial-frame-alist
	(append (list
                  '(alpha . (85 15))
;		   '(foreground-color . "white")		;; 文字色
;		   '(background-color . "#333366")		;; 背景色
;		   '(border-color . "black")
;		   '(mouse-color . "white")
;		   '(cursor-color . "white")
		   '(width . 92)				;; フレームの幅
;		   '(width . 192)				;; フレームの幅
		   '(height . 50)				;; フレームの高さ
;		   '(height . 60)				;; フレームの高さ
		   '(top . 0)					;; Y 表示位置
		   '(left . 0)				;; X 表示位置
		   )
		initial-frame-alist))
(setq default-frame-alist initial-frame-alist)
;;
;=======================================================================
; Misc
;=======================================================================
(mouse-wheel-mode)						;;ホイールマウス
(global-font-lock-mode t)					;;文字の色つけ
(setq line-number-mode t)					;;カーソルのある行番号を表示
(auto-compression-mode t)					;;日本語infoの文字化け防止
(set-scroll-bar-mode 'right)					;;スクロールバーを右に表示
(global-set-key "\C-z" 'undo)					;;UNDO
(setq frame-title-format					;;フレームのタイトル指定
	(concat "%b - emacs@" system-name))

;(display-time)							;;時計を表示
;(global-set-key "\C-h" 'backward-delete-char)			;;Ctrl-Hでバックスペース
;(setq make-backup-files nil)					;;バックアップファイルを作成しない
;(setq visible-bell t)						;;警告音を消す
;(setq kill-whole-line t)					;;カーソルが行頭にある場合も行全体を削除
;(when (boundp 'show-trailing-whitespace) (setq-default show-trailing-whitespace t))	;;行末のスペースを強調表示



;; common ------------------------------------------------------------;
;; ※フォント確認用S式:(frame-parameter nil 'font)
;; タイトルバーにファイル名を表示
;;(setq frame-title-format "%b")
;;; タイトルバーにファイル名を表示する
(setq frame-title-format (format "emacs@%s : %%f" (system-name)))

;; タブバー非表示
(setq elscreen-display-tab nil)

;; ツールバー非表示
(tool-bar-mode nil)

;; バッファ名をディレクトリ名に変更
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
;; uniquify でバッファ名を変更しないものを正規表現で指定
(setq uniquify-ignore-buffers-re "*[^*]+*")
;; ファイル名が重複してない場合も常にディレクトリ名を表示するよう指定
(setq uniquify-min-dir-content 1)

;; スクロールバーを右側に表示する
(set-scroll-bar-mode 'right)

;; デフォルトモード設定
(setq auto-mode-alist (cons '("\\.html?$" . html-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.tpl?$" . html-mode) auto-mode-alist))

;; 選択範囲を色付け
(transient-mark-mode 1)

;; 終了時に自動生成されているオートセーブファイルを削除する
(setq delete-auto-save-files t)

;; 対応する括弧をハイライト表示行う
(show-paren-mode 1)

;; カーソルの位置を表示する
(column-number-mode t)
(line-number-mode t)

;; モードラインに時間を表示する
(display-time)

;; 現在の関数名をモードラインに表示
(which-function-mode t)

;; 行の折り返し表示をする
(setq truncate-lines nil)
(setq truncate-partial-width-windows nil)

;; バックスペースキーの制御
(global-set-key "\C-h" 'delete-backward-char)

;; 起動時の画面を表示しない
;;(setq inhibit-startup-message t)

;; 入力モードによるカーソル色の指定
(defvar anthy-cursor-color-alist
  '(("hiragana" . "Red")
    ("katakana" . "goldenrod")
    ("alphabet" . "royalblue")
    ("walphabet" . "orchid")
    ("hankaku_kana" . "lime green")))
(defun anthy-adjust-cursor-color ()
  (set-cursor-color
   (if anthy-minor-mode
       (cdr (assoc anthy-current-rkmap anthy-cursor-color-alist))
     (frame-parameter nil 'foreground-color))))
(add-hook 'post-command-hook 'anthy-adjust-cursor-color)

;; iswitchb
(iswitchb-mode t)

;; 自動セーブとバックアップファイルを無効にする
(setq make-backup-files nil)
(setq auto-save-default nil)

;;; バックアップファイルを作らない
(setq backup-inhibited t)

;; タブ幅を 4 に設定
(setq tab-width 2)
(setq-default tab-width 2)
;; タブ幅の倍数を設定
(setq tab-stop-list
  '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60))
;; タブではなくスペースを使う
(setq-default indent-tabs-mode nil)
;; (setq indent-line-function 'indent-relative-maybe)
;; インデント幅を指定
(setq c-basic-offset 4)

;; yankのシステムへのコピー
(cond (window-system
       (setq x-select-enable-clipboard t)
       ))

;; 矩形選択の設定
(autoload 'sense-region-on "sense-region"
          "System to toggle region and rectangle." t nil)
(sense-region-on)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; color-grep                                          ;;
;; (require 'color-grep)                                  ;;
;; ;; grep バッファを kill 時に,開いたバッファを消さない ;;
;; (setq color-grep-sync-kill-buffer nil)                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; grep-edit
(require 'grep-edit)

;; lgrep設定
(setq grep-command "lgrep -n -Oe ")
(setq grep-program "lgrep")

;; igrep設定
(autoload 'igrep "igrep"
  "*Run `grep` PROGRAM to match EXPRESSION in FILES..." t)
(autoload 'igrep-find "igrep"
  "*Run `grep` via `find`..." t)
(autoload 'dired-do-igrep "igrep"
  "*Run `grep` on the marked (or next prefix ARG) files." t)
(autoload 'igrep-insinuate "igrep"
  "Define `grep' aliases for the corresponding `igrep' commands." t)
(autoload 'igrep-visited-files "igrep"
  "*Run `grep` ... on all visited files." t)
(autoload 'dired-do-igrep-find "igrep"
  "*Run `grep` via `find` on the marked (or next prefix ARG) directories." t)
(autoload 'Buffer-menu-igrep "igrep"
  "*Run `grep` on the files visited in buffers marked with '>'." t)
(setq igrep-program "lgrep")
(setq igrep-expression-option "-n -Oe")

;; scratchバッファの制御
(defun my-make-scratch (&optional arg)
  (interactive)
  (progn
    ;; "*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 'kill-buffer-query-functions
          ;; *scratch* バッファで kill-buffer したら内容を消去するだけにする
          (lambda ()
            (if (string= "*scratch*" (buffer-name))
                (progn (my-make-scratch 0) nil)
              t)))
(add-hook 'after-save-hook
          ;; *scratch* バッファの内容を保存したら *scratch* バッファを新しく作る
          (lambda ()
            (unless (member (get-buffer "*scratch*") (buffer-list))
              (my-make-scratch 1))))

;; commentの設定
(defconst comment-styles
  '((plain	. (nil nil nil nil))
    (indent	. (nil nil nil t))
    (indent-or-triple
                . (nil nil nil multi-char))
    (aligned	. (nil t nil t))
    (multi-line	. (t nil nil t))
    (extra-line	. (t nil t t))
    (box	. (nil t t t))
    (box-multi	. (t t t t)))
  "Comment region styles of the form (STYLE . (MULTI ALIGN EXTRA INDENT)).
STYLE should be a mnemonic symbol.
MULTI specifies that comments are allowed to span multiple lines.
ALIGN specifies that the `comment-end' markers should be aligned.
EXTRA specifies that an extra line should be used before and after the
  region to comment (to put the `comment-end' and `comment-start').
INDENT specifies that the `comment-start' markers should not be put at the
  left margin but at the current indentation of the region to comment.
If INDENT is `multi-char', that means indent multi-character
  comment starters, but not one-character comment starters.")
;; comment-style (indent, multi-line, box)
(setq comment-style 'box)

;; jaspace -----------------------------------------------------------;
(require 'jaspace)
(setq jaspace-modes (append jaspace-modes
                            (list 'text-mode
                                  'Emacs-Lisp-mode
                                  'php-mode
                                  'ruby-mode
                                  'fundamental-mode)))
;; 全角空白を表示させる。
(setq jaspace-alternate-jaspace-string "□")
;; 改行記号を表示させる。
(setq jaspace-alternate-eol-string "↓\n")
;; タブ記号を表示。
(setq jaspace-highlight-tabs t)  ; highlight tabs

;; linum -------------------------------------------------------------;
;; 行番号の表示(不要なスペースが出来るので無効化)
;(require 'linum)
;(global-linum-mode 1)
;(defvar my-linum-min-width 1)
;(setq linum-format
;      (lambda (line)
;        (let ((fmt (format
;                    "%%%dd"
;                    (max
;                     my-linum-min-width
;                     (length (number-to-string
;                              (count-lines (point-min) (point-max))))))))
;          (propertize (format fmt line) 'face 'linum))))

;; color-theme -------------------------------------------------------;
(require 'color-theme)
(color-theme-initialize)
(color-theme-arjen)

;; install-elisp -----------------------------------------------------;
(require 'install-elisp)
(setq install-elisp-repository-directory "/usr/share/emacs23/site-lisp")

;; auto-install ------------------------------------------------------;
(require 'auto-install)
(setq auto-install-directory "/usr/share/emacs23/site-lisp/")
;;(auto-install-update-emacswiki-package-name t)
(auto-install-compatibility-setup)

;; magit -------------------------------------------------------------;
(require 'magit)

;; psvn --------------------------------------------------------------;
(require 'psvn)

;; gtags -------------------------------------------------------------;
(when (locate-library "gtags")
  (require 'gtags)
)

;; anything ----------------------------------------------------------;
(require 'anything)
(require 'anything-config)
(require 'anything-match-plugin)
(require 'anything-gtags)
(require 'anything-etags)

;;(setq anything-sources
;;      '(anything-etags-c-source-etags-select))

(setq anything-sources (list anything-c-source-buffers
                             anything-c-source-bookmarks
                             anything-c-source-recentf
                             anything-c-source-file-name-history
                             anything-c-source-locate
                             anything-c-source-emacs-commands
;;                             anything-c-source-etags-select
                             ))
;;(setq anything-sources (list anything-source-buffers
;;                             anything-source-bookmarks
;;                             ;;anything-source-recentf
;;                             anything-source-file-name-history
;;                             anything-source-locate-r
;;                             anything-source-complex-command-history))
;;(setq anything-type-actions (list anything-actions-buffer
;;                                  anything-actions-file
;;                                  anything-actions-sexp))

(define-key anything-map "\C-p" 'anything-previous-line)
(define-key anything-map "\C-n" 'anything-next-line)
(define-key anything-map "\C-v" 'anything-next-page)
(define-key anything-map "\M-v" 'anything-previous-page)
(global-set-key [?\C-;] 'anything)
(global-set-key [?\M-y] 'anything-show-kill-ring)

;; auto-complete -----------------------------------------------------;
(require 'auto-complete)
(global-auto-complete-mode t)
(setq ac-auto-start nil)
(global-set-key "\M-/" 'ac-start)
(define-key ac-complete-mode-map "\M-n" 'ac-next)
(define-key ac-complete-mode-map "\M-p" 'ac-previous)

;; ac-dabbrev --------------------------------------------------------;
(require 'ac-dabbrev)
;;(setq ac-sources
;;      (list ac-source-dabbrev))
(setq ac-sources '(ac-source-abbrev
                   ac-source-words-in-buffer
                   ac-source-dabbrev))


;; for php -----------------------------------------------------------;
(load-library "php-mode")
(require 'php-mode)

(add-hook  'php-mode-hook
           (lambda ()
             (require 'php-completion)
             (php-completion-mode t)
             (define-key php-mode-map (kbd "C-o") 'phpcmp-complete)
;;             (when (require 'auto-complete nil t)
;;               (make-variable-buffer-local 'ac-sources)
;;               (add-to-list 'ac-sources 'ac-source-php-completion)
;;               (auto-complete-mode t))
             ))

;; ;; for ruby ----------------------------------------------------------;
;; ;; ruby-mode
;; (autoload 'ruby-mode "ruby-mode"
;;   "Mode for editing ruby source files" t)
;; (setq auto-mode-alist
;;       (append '(("\\.rb$" . ruby-mode)) auto-mode-alist))
;; (setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
;;                                      interpreter-mode-alist))
;; (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")
;; (add-hook 'ruby-mode-hook
;;           '(lambda () (inf-ruby-keys)))
;; 
;; ;; ruby-electric
;; (require 'ruby-electric)
;; (add-hook 'ruby-mode-hook '(lambda () (ruby-electric-mode t)))
;; 
;; ;; rubydb
;; (autoload 'rubydb "rubydb3x"
;;   "run rubydb on program file in buffer *gud-file*.
;; the directory containing file becomes the initial working directory
;; and source-file directory for your debugger." t)
;; 
;; ;; rails
;; (defun try-complete-abbrev (old)
;;   (if (expand-abbrev) t nil))
;; (setq hippie-expand-try-functions-list
;;       '(try-complete-abbrev
;;         try-complete-file-name
;;         try-expand-dabbrev))
;; (setq rails-use-mongrel t)
;; (require 'cl)
;; (require 'rails)

;; ;; ruby-block
;; (require 'ruby-block)
;; (ruby-block-mode t)
;; ;; ミニバッファに表示し, かつ, オーバレイする.
;; (setq ruby-block-highlight-toggle t)

;; ;; エラーラインの変更
;; (set-face-background 'flymake-errline "DarkRed")

;; (require 'rcodetools)
;; (setq rct-find-tag-if-available nil)
;; (defun ruby-mode-hook-rcodetools ()
;;   (define-key ruby-mode-map "\C-co" 'rct-complete-symbol)
;;   (define-key ruby-mode-map "\C-c\C-t" 'ruby-toggle-buffer)
;;   (define-key ruby-mode-map "\C-c\C-d" 'xmp)
;;   (define-key ruby-mode-map "\C-c\C-f" 'rct-ri))
;; (add-hook 'ruby-mode-hook 'ruby-mode-hook-rcodetools)

;; (require 'anything-rcodetools)
;; (setq rct-get-all-methods-command "PAGER=cat fri -l")
;; ;; See docs
;; (define-key anything-map "\C-z" 'anything-execute-persistent-action)
;; ;;(define-key anything-map [(control ?;)] 'anything-execute-persistent-action)
;; (setq ri-ruby-script "/usr/share/emacs23/site-lisp/ri-emacs.rb")
;; (autoload 'ri "/usr/share/emacs23/site-lisp/ri-ruby.elc" nil t)

;;(require 'auto-complete-ruby)
;;(add-hook 'ruby-mode-hook
;;          (lambda ()
;;            (setq ac-omni-completion-sources '(("\\.\\=" ac-source-rcodetools)))))