2012年2月6日月曜日

.emacs.elの設定(Linux)


;; -*- coding: utf-8 -*-

;;; Language
(set-language-environment "Japanese")
(set-terminal-coding-system 'utf-8)
(setq file-name-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(setq coding-system-for-read 'mule-utf-8)
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)

(when window-system
  (progn
    (set-default-font "VL ゴシック-14")
    (set-fontset-font (frame-parameter nil 'font)
                      'japanese-jisx0208
                      '("VL ゴシック" . "unicode-bmp"))))


(load-library "anthy")
(setq default-input-method "japanese-anthy")

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(column-number-mode t)
 '(current-language-environment "Japanese")
 '(eshell-ask-to-save-history (quote always))
 '(eshell-history-size 1000)
 '(eshell-ls-dired-initial-args (quote ("-h")))
 '(eshell-ls-exclude-regexp "~\\'")
 '(eshell-ls-initial-args "-h")
 '(eshell-modules-list (quote (eshell-alias eshell-basic eshell-cmpl eshell-dirs eshell-glob eshell-hist eshell-ls eshell-pred eshell-prompt eshell-rebind eshell-script eshell-smart eshell-term eshell-unix eshell-xtra)))
 '(eshell-prefer-to-shell t nil (eshell))
 '(eshell-stringify-t nil)
 '(eshell-term-name "ansi")
 '(eshell-visual-commands (quote ("vi" "top" "screen" "less" "lynx" "ssh" "rlogin" "telnet")))
 '(inhibit-startup-screen t)
 '(kill-whole-line t)
 '(partial-completion-mode t)
 '(safe-local-variable-values (quote ((numbered-outline-begin-number . 1) (encoding . sjis) (bug-reference-url-format . "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s") (encoding . sjis-unix) (encoding\. sjis-dos) (c-set-style . "stroustrup"))))
 '(show-paren-mode t)
 '(tab-width 4)
 '(tool-bar-mode nil)
 '(transient-mark-mode t)
 )

;; emacs-server
(server-start)


;; =============================================================================
;; キーバインド
;; =============================================================================
(global-set-key "\C-h" 'backward-delete-char)
(global-set-key "\M-?" 'help-for-help)
(global-set-key [f1] 'help-for-help)
(global-set-key "\M-g" 'goto-line) ;; M-g で指定行へ移動
(global-set-key "\C-^" 'next-error)
(global-set-key "\M-h" 'backward-kill-word)
(global-set-key [hiragana-katakana] 'toggle-input-method)
(global-set-key [muhenkan] 'toggle-input-method)
;;(global-set-key "\M-." 'migemo-dabbrev-expand)
(define-key global-map "\C-m" 'newline-and-indent) ;; 改行キーでオートインデント
(setq indent-line-function 'indent-relative-maybe) ;;インデント方法. お好みで. .
;; C-x p で C-x oの逆の動作
(define-key ctl-x-map "p"
  #'(lambda (arg) (interactive "p") (other-window (- arg))))


(defun eshell/clear ()
  "Clear the current buffer, leaving one prompt at the top."
  (interactive)
  (let ((inhibit-read-only t))
    (erase-buffer)))

;; =============================================================================
;; 編集
;; =============================================================================

;;iswitchb
(iswitchb-mode t)
(defun iswitchb-possible-new-buffer (buf)
  "Possibly create and visit a new buffer called BUF."
  (interactive)
  (message (format
            "No buffer matching `%s', "
            buf))
  (sit-for 1)
  (call-interactively 'find-file buf))

(defun iswitchb-buffer (arg)
  "Switch to another buffer.
The buffer name is selected interactively by typing a substring.  The
buffer is displayed according to `iswitchb-default-method' -- the
default is to show it in the same window, unless it is already visible
in another frame.
For details of keybindings, do `\\[describe-function] iswitchb'."
  (interactive "P")
  (if arg
      (call-interactively 'switch-to-buffer)
    (setq iswitchb-method iswitchb-default-method)
    (iswitchb)))

;; =============================================================================
;; バックアップ関連
;; =============================================================================
;; 番号つきバックアップファイル
;; Emacsが作るバックアップファイルをfilename~というのから
;; filename.~n~にする
(setq version-control t)
;; 古いものをいくつ残すか
(setq kept-old-versions 5)
;; 新しいものをいくつ残すか
(setq kept-new-versions 5)
;; バックアップファイルを上書きするときに警告を出す
(setq trim-versions-without-asking t)
;; #filename というバックアップファイルを作らない
(setq auto-save-default t)
;;;バックアップファイル「(ファイル名)~」を作成するか指定
(setq make-backup-files t)
;; バックアップファイルの設定
(setq backup-by-copying t)
;;;バックアップファイルを特定のディレクトリにセーブする
(setq backup-directory-alist
      (cons (cons "\\.*$" (expand-file-name "~/.backup/"))
            backup-directory-alist))
;; 古いものを消すときに聞かずに消す
(setq delete-old-versions t)

;; =============================================================================
;; scratch buffer 以外をまとめてタブに表示する
;; =============================================================================
(require 'cl)
(when (require 'tabbar nil t)
  (setq tabbar-buffer-groups-function
        (lambda (b) (list "All Buffers")))
  (setq tabbar-buffer-list-function
        (lambda ()
          (remove-if
           (lambda(buffer)
             (find (aref (buffer-name buffer) 0) " *"))
           (buffer-list))))
  (tabbar-mode))

;;M-]で次のタブ、M-[で前のタブに移動
(global-set-key "\M-]" 'tabbar-forward)
(global-set-key "\M-[" 'tabbar-backward)



;; =============================================================================
;; 開発
;; =============================================================================
;; GDBの設定
(setq gdb-many-windows t)
(windmove-default-keybindings)
(setq windmove-wrap-around t)
;; Ini, batモード
(require 'generic-x)
;; moccur-edit
(require 'moccur-edit)
;; moccur-grep-findで.svnを無視する
(setq dmoccur-exclusion-mask
      (append '("\\~$" "\\.svn\\/\*") dmoccur-exclusion-mask))

;; C#モード
;; (autoload 'csharp-mode "csharp-mode" "C# editing mode." t)
;; (add-to-list 'auto-mode-alist '("\\.cs$" . csharp-mode))
;; (add-hook 'csharp-mode-hook (lambda ()
;;                               (setq c-basic-offset 4
;;                                     tab-width 4
;;                                     indent-tabs-mode t)))

;; Makefile
(add-to-list 'auto-mode-alist '("\\.mak$" . makefile-mode))

;; Dotモード
;;(load "graphviz-dot-mode.el")

;; PHPモード
(autoload 'php-mode "php-mode")
(setq auto-mode-alist
      (cons '("\\.php\\'" . php-mode) auto-mode-alist))
(setq php-mode-force-pear t)

;; xml
(add-to-list 'auto-mode-alist '("\\.\\(xml\\|mcxml\\|xsd\\|arxml\\|cmxml\\)\\'" . nxml-mode))

(add-hook 'nxml-mode-hook
          (lambda ()
            (setq nxml-slash-auto-complete-flag t)
            (setq nxml-child-indent 2)
            (setq indent-tabs-mode t)
            (setq tab-width 2)))
;; Python
(autoload 'python-mode "python-mode" "Python Mode." t)
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))

(add-hook 'python-mode-hook
          (lambda ()
            (set (make-variable-buffer-local 'beginning-of-defun-function)
                 'py-beginning-of-def-or-class)
            (setq outline-regexp "def\\|class ")
            (setq indent-tabs-mode t)
            ))


;; GNU GLOBAL(gtags) gtags.el
;; (autoload 'gtags-mode "gtags" "" t)
;; (global-set-key "\M-t" 'gtags-find-tag)    ;関数の定義元へ
;; (global-set-key "\M-r" 'gtags-find-rtag)   ;関数の参照先へ
;; (global-set-key "\M-s" 'gtags-find-symbol) ;変数の定義元/参照先へ
;; (global-set-key "\C-t" 'gtags-pop-stack)   ;前のバッファに戻る
;; ;;
;; (add-hook 'c-mode-hook
;;           (function
;;            (lambda ()
;;              (gtags-mode 1)
;;              (cygwin-mount-activate)
;;              )))


;; CScope
(require 'xcscope)

;; =============================================================================
;; 表示
;; =============================================================================
;; タブ, 全角スペース、改行直前の半角スペースを表示する
(when (require 'jaspace nil t)
  (when (boundp 'jaspace-modes)
    (setq jaspace-modes (append jaspace-modes
                                (list 'php-mode
                                      'yaml-mode
                                      'javascript-mode
                                      'ruby-mode
                                      'text-mode
                                      'fundamental-mode
                                      'python-mode
                                      'c-mode
                                      'c++-mode
                                      'dot-mode
                                      'nxml-mode
                                      'html-mode
                                      )
                                )))
  (when (boundp 'jaspace-alternate-jaspace-string)
    (setq jaspace-alternate-jaspace-string "□"))
  (when (boundp 'jaspace-highlight-tabs)
    (setq jaspace-highlight-tabs ?^))
  (add-hook 'jaspace-mode-off-hook
            (lambda()
              (when (boundp 'show-trailing-whitespace)
                (setq show-trailing-whitespace nil))))
  (add-hook 'jaspace-mode-hook
            (lambda()
              (progn
                (when (boundp 'show-trailing-whitespace)
                  (setq show-trailing-whitespace t))
                (face-spec-set 'jaspace-highlight-jaspace-face
                               '((((class color) (background light))
                                  (:foreground "blue"))
                                 (t (:foreground "green"))))
                (face-spec-set 'jaspace-highlight-tab-face
                               '((((class color) (background light))
                                  ;;                                  (:foreground "red"
                                  :background "gray26"
                                  :strike-through nil
                                  :underline nil))
                               (t (:foreground "purple"
                                               :background "unspecified"
                                               :strike-through nil
                                               :underline nil))))
              (face-spec-set 'trailing-whitespace
                             '((((class color) (background light))
                                (:foreground "red"
                                             :background "unspecified"
                                             :strike-through nil
                                             :underline nil))
                               (t (:foreground "purple"
                                               :background "unspecified"
                                               :strike-through nil
                                               :underline nil)))))))

;; =============================================================================
;; 現在開いているファイルのファイル名を、Windows形式(「\」で区切る)
;; でクリップボードにコピーします。
;; =============================================================================
(defun clipboard-to-buffername ()
  (interactive)
  (unless (equal (buffer-file-name) nil)
    (kill-new
     (buffer-file-name))))
;; =============================================================================
;; 余分な空白を削除する
;; =============================================================================
(defun trim-buffer ()
  "Delete excess white space."
  (interactive)
  (save-excursion
    ;; 行末の空白を削除する
    (goto-char (point-min))
    (while (re-search-forward "[ \t]+$" nil t)
      (replace-match "" nil nil))
    ;; ファイルの終わりにある空白行を削除する
    (goto-char (point-max))
    (delete-blank-lines)
                                        ;    ;; タブに変換できる空白は変換する
                                        ;    (mark-whole-buffer)
                                        ;    (tabify (region-beginning) (region-end))
    ))



;; =============================================================================
;; C-mode
;; =============================================================================
(add-hook 'c-mode-common-hook
          '(lambda ()
             (c-set-style "stroustrup")
             (setq tab-width 4)
             (setq c-basic-offset 4)
             (setq indent-tabs-mode t)
             (setq c-lineup-close-paren 8)
             ;;(c-set-offset 'arglist-intro  c-lineup-arglist-intro-after-paren)
             ;;(c-set-offset 'arglist-close  c-lineup-arglist)
             ;;          (c-set-offset 'arglist-cont-nonempty +)
             ;;          (c-set-offset 'arglist-cont 4)
             ;;          (c-set-offset 'statement-cont 0)
             ;;          (c-set-offset 'substatement-open 0)
             ;;          (c-set-offset 'block-open 0)
             ;;          (c-set-offset 'statement-case-open 0)
             ))


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


;; ============================================================
;;  use tramp
;; ============================================================
(require 'tramp)

(setq tramp-default-method "ssh")

;; Setting for working with remote host

(add-to-list 'tramp-default-proxies-alist
             '("se-srv-nanami.*" "root" "/ssh:nanami@%h:"))

;; MarkdownMode
(autoload 'markdown-mode "markdown-mode.el"
  "Major mode for editing Markdown files" t)
(setq auto-mode-alist
      (cons '("\\.text" "\\.markdown" . markdown-mode) auto-mode-alist))

0 件のコメント:

コメントを投稿