.emacs メモ
現在の.emacsをまとめておく。meadowとも設定を共有。すっごく汚いが、気にしない!
.emacs
メインファイル。一応ファイルはだいたいの機能別に小分けにしてloadしている。
;;;; -*- Emacs-Lisp -*- ;;;; .emacs -- emacs environment file ;; load-pathの設定 (setq load-path (cons "~/.emacs.d/site-lisp" load-path)) ;; load setting files (load "my-dired") (load "my-misc") (load "my-keybinds") (load "my-language") (load "my-layout") (load "my-window") (load "my-color") (load "my-progenv") (load "my-yatex") (load "my-outline") (load "third-party")
my-dired.el
dired-modeの設定。
;;;; -*- Emacs-Lisp -*- ;;;; my-dired.el -- setting for dired-mode ;;;; author: suji_ski ;; 本日,今週,先週更新したファイルに色付け ;; Ref. http://homepage1.nifty.com/blankspace/emacs/dired.html (defface face-file-edited-today '((((class color) (background dark)) (:foreground "GreenYellow")) (((class color) (background light)) (:foreground "magenta")) (t ())) nil) (defface face-file-edited-this-week '((((class color) (background dark)) (:foreground "LimeGreen")) (((class color) (background light)) (:foreground "violet red")) (t ())) nil) (defface face-file-edited-last-week '((((class color) (background dark)) (:foreground "saddle brown")) (((class color) (background light)) (:foreground "maroon")) (t ())) nil) (defvar face-file-edited-today 'face-file-edited-today) (defvar face-file-edited-this-week 'face-file-edited-this-week) (defvar face-file-edited-last-week 'face-file-edited-last-week) (defun my-dired-today-search (arg) "Fontlock search function for dired." (search-forward-regexp (concat "\\(" (format-time-string "%b %e" (current-time)) "\\|"(format-time-string "%m-%d" (current-time)) "\\)" " [0-9]....") arg t)) (defun my-dired-date (time) "Fontlock search function for dired." (let ((now (current-time)) (days (* -1 time)) dateh datel daysec daysh daysl dir (offset 0)) (setq daysec (* -1.0 days 60 60 24)) (setq daysh (floor (/ daysec 65536.0))) (setq daysl (round (- daysec (* daysh 65536.0)))) (setq dateh (- (nth 0 now) daysh)) (setq datel (- (nth 1 now) (* offset 3600) daysl)) (if (< datel 0) (progn (setq datel (+ datel 65536)) (setq dateh (- dateh 1)))) ;;(floor (/ offset 24)))))) (if (< dateh 0) (setq dateh 0)) ;;(insert (concat (int-to-string dateh) ":")) (list dateh datel))) (defun my-dired-this-week-search (arg) "Fontlock search function for dired." (let ((youbi (string-to-int (format-time-string "%w" (current-time)))) this-week-start this-week-end day ;;regexp (flg nil)) (setq youbi (+ youbi 1)) (setq regexp (concat "\\(")) (while (not (= youbi 0)) (setq regexp (concat regexp (if flg "\\|") (format-time-string "%b %e" (my-dired-date youbi)) "\\|" (format-time-string "%m-%d" (my-dired-date youbi)) )) ;;(insert (concat (int-to-string youbi) "\n")) (setq flg t) (setq youbi (- youbi 1)))) (setq regexp (concat regexp "\\)")) (search-forward-regexp (concat regexp " [0-9]....") arg t)) (defun my-dired-last-week-search (arg) "Fontlock search function for dired." (let ((youbi (string-to-int (format-time-string "%w" (current-time)))) this-week-start this-week-end day ;;regexp lyoubi (flg nil)) (setq youbi (+ youbi 0)) (setq lyoubi (+ youbi 7)) (setq regexp (concat "\\(")) (while (not (= lyoubi youbi)) (setq regexp (concat regexp (if flg "\\|") (format-time-string "%b %e" (my-dired-date lyoubi)) "\\|" (format-time-string "%m-%d" (my-dired-date lyoubi)) )) ;;(insert (concat (int-to-string youbi) "\n")) (setq flg t) (setq lyoubi (- lyoubi 1)))) (setq regexp (concat regexp "\\)")) (search-forward-regexp (concat regexp " [0-9]....") arg t)) (add-hook 'dired-mode-hook '(lambda () (font-lock-add-keywords major-mode (list '(my-dired-today-search . face-file-edited-today) '(my-dired-this-week-search . face-file-edited-this-week) '(my-dired-last-week-search . face-file-edited-last-week) ))))
my-misc.el
その他設定。
;;;; -*- Emacs-Lisp -*- ;;;; my-misc.el -- various setting for emacs ;; start-up (setq inhibit-startup-message t) ; startup message の抑制 (setq default-major-mode 'lisp-interaction-mode) ; デフォルトでlisp-interaction-modeが起動するように設定。 ;(setq default-major-mode 'shell-script-mode) ; デフォルトでshell-script-mode (setq default-directory "~/") ; デフォルトディレクトリ ;; web_blowse (setq browse-url-browser-function 'browse-url-generic browse-url-generic-program "google-chrome") ; web_browserをchromeに変更 (setq x-select-enable-clipboard t) ; web browserへコピペできるように (ffap-bindings) ; emacsからurlやfileを開ける (setq require-final-newline t) ; file の最後は 必ず newline で終わる様にする。 (setq next-line-add-newlines nil) ; 文末のカーソルキー下で new line を作らない。 (global-auto-revert-mode t) ; file が他から変更されたら、自動的に読み込む。 (auto-compression-mode t) ; 圧縮されたファイルを読めるようにする (setq scroll-step 1) ; 画面最下行での step 数 (if (display-mouse-p) (mouse-avoidance-mode 'jump)) ; マウス邪魔 (setq kill-whole-line nil) ; \C-kで一気に削除されないようにする。
my-keybind.el
キーバインド設定。
;;;; -*- Emacs-Lisp -*- ;;;; my-keybinds.el -- definition of emacs key-binds (global-set-key [delete] 'delete-char) ; Deleteキーでカーソル位置の文字が消えるようにする (global-set-key "\C-h" 'backward-delete-char) ; C-h キーでカーソルの左の文字が消えるようにする。 (global-set-key "\C-[g" 'goto-line) ; For goto line (global-set-key "\C-x\C-n" 'next-error) (global-set-key "\C-x\C-a" 'shell) (define-key ctl-x-map "p" '(lambda (arg) (interactive "p") (other-window (- arg)))) ; For Ctrl-x p = other-window in the opposite order (global-set-key "\C-cm" 'compile) ; makeを実行 (global-set-key "\M-=" 'count-lines-region) ; リージョンの行数と文字数をカウント. (global-set-key "\C-c\C-a" 'align) ; For align (global-set-key "\C-x\C-b" 'bs-show) ; C-xC-bでのバッファスイッチが簡単にできる ;; swap enter (keyboard-translate ?\C-m ?;) ; ";" = Enter (keyboard-translate ?; ?\C-m) ; Ctrl-m = ";" ;; comment (global-set-key "\C-c\C-c" 'comment-or-uncomment-region) ; regionをcomment/unccoment (global-set-key "\C-c\C-d" 'uncomment-region) ; regionをuncomment ;; change active window size (global-set-key "\M--" 'enlarge-window) ; M-] で active window の高さを広げる。 (global-set-key "\M-^" 'shrink-window) ; M-[ で active window の高さを狭める。 (global-set-key "\M-]" 'enlarge-window-horizontally) ; M-] で active window の幅を広げる。 (global-set-key "\M-[" 'shrink-window-horizontally) ; M-[ で active window の幅を狭める。 ;; \M-系がウィンドウマネージャに食われてるので,他ので代用. (global-set-key "\C-c\C-l" 'lisp-complete-symbol)
my-language.el
日本語入力やフォントなどの設定。
(追記)meadow@windowsでは、デフォルトのIMEと東雲フォントを使うことにした(Ref:http://www.bookshelf.jp/soft/meadow_15.html#SEC110)。
;;;; -*- Emacs-Lisp -*- ;;;; my-language.el -- setting for language and font-code (set-language-environment "japanese") (set-default-coding-systems 'euc-jp) ;標準ではeucを使う ;;;=================================== ;;; ibus-mozc ;;;=================================== (require 'ibus) (add-hook 'after-init-hook 'ibus-mode-on) ; Turn on ibus-mode automatically after loading .emacs (ibus-define-common-key ?\C-\s nil) (ibus-define-common-key ?\C-/ nil) (setq ibus-cursor-color '("limegreen" "white" "blue")) ; Change cursor color depending on ibus status (global-set-key "\C-\\" 'ibus-toggle) (global-set-key "\C-o" 'ibus-toggle) ;;;=================================== ;;; font ;;;=================================== (set-default-font "Inconsolata-11") (set-face-font 'variable-pitch "Inconsolata-11") (set-fontset-font (frame-parameter nil 'font) 'japanese-jisx0208 '("Takaoゴシック" . "unicode-bmp") )
my-layout.el
emacsレイアウトの設定。
;;;; -*- Emacs-Lisp -*- ;;;; my-layout.el -- setting for emacs layout (tool-bar-mode 0) ; tool bar を消す。 (set-scroll-bar-mode nil) ; scrollbar を消す。 ;(set-scroll-bar-mode 'right) ; scrollbar を右に (menu-bar-mode -1) ; menu bar を消す。 (line-number-mode 1) ; 行番号を表示 (setq column-number-mode t) ; 桁番号表示 ;; frame-title に buffer name と system-name, emacs-version を載せる。 (setq frame-title-format `(" %b ", " @ ",(system-name) " -- " ,emacs-version)) ;; ステータスラインに時間を表示する (setq display-time-24hr-format t) ; default nil ex. 8:08am (display-time) ;; mode name が長いと 見たい情報が表示されなくなってしまうので、省略形で表示する。 (add-hook 'lisp-interaction-mode-hook '(lambda () (setq mode-name "Lisp-Int"))) (add-hook 'emacs-lisp-mode-hook '(lambda () (setq mode-name "Elisp"))) ;; 同じファイル名を編集するときのバッファ名をいい感じに (require 'uniquify) (setq uniquify-buffer-name-style 'forward) ;; 文章の折り返し (setq truncate-lines t) (setq truncate-partial-width-windows t)
my-window.el
window操作関連の設定。
;;;; my-window.el -- setting for emacs window ;; shift+カーソルでwindow移動 (windmove-default-keybindings) (setq windmove-wrap-around t) ;; 画面を 2 分割したときの 上下を入れ替える swap screen ;; Ref.http://www.bookshelf.jp/soft/meadow_30.html (defun swap-screen() "Swap two screen,leaving cursor at current window." (interactive) (let ((thiswin (selected-window)) (nextbuf (window-buffer (next-window)))) (set-window-buffer (next-window) (window-buffer)) (set-window-buffer thiswin nextbuf))) (defun swap-screen-with-cursor() "Swap two screen,with cursor in same buffer." (interactive) (let ((thiswin (selected-window)) (thisbuf (window-buffer))) (other-window 1) (set-window-buffer thiswin (window-buffer)) (set-window-buffer (selected-window) thisbuf))) ;; 横分割と縦分割を切り替える ;; Ref.http://www.bookshelf.jp/soft/meadow_30.html (defun window-toggle-division () "ウィンドウ 2 分割時に、縦分割<->横分割" (interactive) (unless (= (count-windows 1) 2) (error "ウィンドウが 2 分割されていません。")) (let (before-height (other-buf (window-buffer (next-window)))) (setq before-height (window-height)) (delete-other-windows) (if (= (window-height) before-height) (split-window-vertically) (split-window-horizontally) ) (switch-to-buffer-other-window other-buf) (other-window -1))) ;; screen(elscreen) (load "elscreen" "ElScreen" t)
my-color.el
テキスト強調や背景色などの設定。
;;;; -*- Emacs-Lisp -*- ;;;; my-color.el -- setting for emacs color ;; Xでのカラー表示 (いつでもカラー強調を使う) (require 'font-lock) (if (not (featurep 'xemacs)) (global-font-lock-mode t) ) ;; tabと行末spaceに色を付ける ;; Ref.:http://homepage1.nifty.com/blankspace/emacs/color.html (defface my-face-b-1 '((t (:background "gray80"))) nil) (defface my-face-u-1 '((t (:foreground "SpringGreen" :underline t))) nil) (defvar my-face-b-1 'my-face-b-1) (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-1 append) ("[ \t]+$" 0 my-face-u-1 append) ))) (ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode) (ad-activate 'font-lock-mode) ;; color-themeを使用 ;; Ref:http://www.bookshelf.jp/soft/meadow_26.html (require 'color-theme) (color-theme-pok-wog) ;; region に色を付いておく。 (setq transient-mark-mode t) ;リージョンをハイライト ;(set-face-foreground 'region "white") ;; mode-line に色を付ける。 ;(set-face-background 'modeline "Blue") ;; cursor (set-cursor-color "red") ; カーソルの色 (blink-cursor-mode t) ; カーソルの点滅あり ;; 対応する括弧を強調表示 & 対応しない場合は 警告する. (require 'paren) (show-paren-mode t) ; 対応する括弧を強調表示. (setq show-paren-ring-bell-on-mismatch t) ; 対応しない括弧を探す。 (setq show-paren-style 'mixed) ; 対応する括弧が画面内になければ、括弧内を強調表示。
my-progenv.el
プログラミング支援機能などの設定。
;;;; -*- Emacs-Lisp -*- ;;;; my-progenv.el -- setting for programming environment ;;============================== ;; global(ソースコード索引) Ref. http://d.hatena.ne.jp/higepon/20060107/1136628498 ;;============================== (autoload 'gtags-mode "gtags" "" t) (setq gtags-mode-hook '(lambda () (local-set-key "\M-t" 'gtags-find-tag) (local-set-key "\M-r" 'gtags-find-rtag) (local-set-key "\M-s" 'gtags-find-symbol) (local-set-key "\C-t" 'gtags-pop-stack) )) ;;============================== ;; gdb(デバッガ) Ref. http://narupon.tdiary.net/20061022.html ;;============================== (setq gdb-many-windows t) (setq gdb-use-separate-io-buffer t) ; "IO buffer" が必要ない場合は nil で ;;============================== ;; ecb(IDE) Ref. http://d.hatena.ne.jp/Tetsujin/20070720/1184861022 ;;============================== (add-to-list 'load-path "~/.emacs.d/site-lisp/ecb-2.40") (load-file "~/.emacs.d/site-lisp/cedet-1.0/common/cedet.elc") (require 'ecb) (defun ecb-toggle () (interactive) (if ecb-minor-mode (ecb-deactivate) (ecb-activate)) ) ;(global-set-key [f2] 'ecb-toggle) ;;============================== ;; For CC-mode ;;============================== (add-hook 'c-mode-common-hook '(lambda () (setq indent-tabs-mode nil) ; indentは空白文字で行う(tabをblankに変換) (define-key c-mode-base-map "\C-m" 'newline-and-indent) ; RETに続けてTABを実行 (c-toggle-auto-hungry-state 1) ; 自動改行 + 欲張り削除 (flyspell-prog-mode) ; 自動 spel check (gtags-mode 1) (gtags-make-complete-list) )) ;; the google C/C++ coding style (load "google-c-style") (add-hook 'c-mode-common-hook '(lambda () (google-set-c-style) (google-make-newline-indent) )) ;;============================== ;; For C-mode ;;============================== (add-hook 'c-mode-hook '(lambda () ;(c-set-style "gnu") (define-key c-mode-map "\C-c\C-d" 'uncomment-region) (define-key c-mode-map "\C-c\C-a" 'align) (c-toggle-auto-hungry-state 1) ; 自動改行 + 欲張り削除 )) ;;============================== ;; For C++-mode ;;============================== (add-hook 'c++-mode-hook '(lambda () ;(c++-set-style "gnu") (define-key c++-mode-map "\C-c\C-d" 'uncomment-region) (define-key c++-mode-map "\C-c\C-a" 'align) (c++-toggle-auto-hungry-state 1) ; 自動改行 + 欲張り削除 )) ;;============================== ;; For shellscript-mode ;;============================== ;; shellscript ( "#!" から始まる file ) は 隠し file を除いて ;; 保存時に自動で実行可能属性をつける。 (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p) ;; (add-hook 'shell-script-mode-hook ;; '(lambda () ;; (setq indent-tabs-mode nil) ; indentは空白文字で行う(tabをblankに変換) ;; (define-key c-mode-base-map "\C-m" 'newline-and-indent) ; RETに続けてTABを実行 ;; (c-toggle-auto-hungry-state 1) ; 自動改行 + 欲張り削除 ;; )) ;;============================== ;; For Matx-mode ;;============================== ;(require 'matx-mode) (autoload 'matx-mode "matx-mode" "Major mode for editing files of MaTX mm files." t) (setq auto-mode-alist (cons' ("\\.mm$" . matx-mode) auto-mode-alist)) (add-hook 'matx-mode-hook '(lambda () (define-key matx-mode-map "\C-c\C-d" 'uncomment-region) )) ;;============================== ;; For Matlab-mode ;;============================== (autoload 'matlab-mode "matlab" "Enter MATLAB mode." t) ;(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t) (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist)) (setq matlab-return-add-semicolon t) ; セミコロン付け忘れ防止 ;;============================== ;; For Elisp-mode ;;============================== (add-hook 'emacs-lisp-mode-hook '(lambda () (setq indent-tabs-mode nil) ; indentは空白文字で行う(tabをblankに変換) ))
my-yatex.el
やてふ設定。
;;;; -*- Emacs-Lisp -*- ;;;; my-yatex.el -- setting for yatex environment ;; *.tex の拡張子を持つファイルを開いた場合、自動的に Yatex を起動 (setq auto-mode-alist (cons (cons "\\.tex$" 'yatex-mode) auto-mode-alist)) (autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t) (setq YaTeX-kanji-code 3) ;(add-hook 'yatex-mode-load-hook (add-hook 'yatex-mode-hook (lambda () (setq YaTeX-kanji-code 3 tex-command "platex" dvi2-command "xdvi-ja -s 10 -watchfile 10" dviprint-command-format "dvips -f %s|lpr -Pdali" YaTeX-use-AMS-LaTeX t) )) (add-hook 'yatex-mode-hook'(lambda ()(require 'font-latex)(font-latex-setup))) ; font (add-hook 'yatex-mode-hook'(lambda ()(setq auto-fill-function nil))) ; 自動改行を無効 (add-hook 'yatex-mode-hook '(lambda ()(reftex-mode t))) ; reftex-mode
third-party.el
webで拾ってきたelispの読み込みと設定。
;;;; -*- Emacs-Lisp -*- ;;;; third-party.el -- load elisp files by third party. ;; 新規にファイルを作成した際に、テンプレートファイルを挿入してくれる ;; Ref:http://www.mcl.chem.tohoku.ac.jp/~nakai/emacs/site-lisp/insert-template.el (load "insert-template") (global-set-key "\C-xt" 'insert-template) ; テンプレートをCtrl+x t で挿入する ;; 修正日時を自動で更新 ;; Ref:http://www.mcl.chem.tohoku.ac.jp/~nakai/emacs/site-lisp/last_update.el (load "last_update") ;; 開括弧を打つと同時に閉括弧を挿入する。また、範囲指定をして対応する括弧で囲う機能もあり ;; Ref:http://www.mcl.chem.tohoku.ac.jp/~nakai/emacs/site-lisp/brackets.el (load "brackets") ;; find-file で補完し損なって新しいファイルを開くのをなんとかしたい ;; Ref:http://www-tsujii.is.s.u-tokyo.ac.jp/~yoshinag/tips/elisp_tips.html (load "avoid-missfile") ;; kill-summary ;; Ref:http://mibai.tec.u-ryukyu.ac.jp/~oshiro/Programs/elisp/kill-summary.el (autoload 'kill-summary "kill-summary" nil t) (define-key global-map "\ey" 'kill-summary) ;; 静的、動的な補完を拡張する ;; Ref:http://www.bookshelf.jp/soft/meadow_34.html (load "abbrev-complete") (setq abbrev-complete-show-completion 'view) ; 補完候補は表示されなくてもよいのでこうする (add-hook 'pre-command-hook (lambda () (setq abbrev-mode nil))) ; abbrev-mode off(勝手に補完されるのは嫌なので) (global-set-key "\C-c\C-i" 'expand-abbrev) ;; さまざまなかたちの補完, インデントをインテリジェントに行う. ;; Ref:http://taiyaki.org/elisp/ac-mode/src/ac-mode.el (autoload 'ac-mode "ac-mode" "Minor mode for advanced completion." t nil) (global-set-key "\C-x\C-i" 'ac-mode) ;; キー操作の繰返し検出 & 実行 ;; Ref:http://pitecan.com/DynamicMacro/ (defconst *dmacro-key* "\C-t" "繰返し指定キー") (global-set-key *dmacro-key* 'dmacro-exec) (autoload 'dmacro-exec "dmacro" nil t) ;; gnuplot-mode ;; Ref. Bruce's Software: Gnuplot-mode http://cars9.uchicago.edu/~ravel/software/gnuplot-mode.html (add-to-list 'load-path "~/.emacs.d/site-lisp/gnuplot-mode.0.6.0") (autoload 'gnuplot-mode "gnuplot" "gnuplot major mode" t) (autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot-mode" t) (setq auto-mode-alist (append '(("\\.gp$" . gnuplot-mode)) auto-mode-alist)) ;; Edit-with-Emacs ;; google-chromeのテキストエリアをemacsで編集 (require 'edit-server) (add-to-list 'network-coding-system-alist '(9292 utf-8 . utf-8)) ; 文字化け対策 (edit-server-start) (require 'elscreen-edit-server) ; elscreenとの協調 ;; emacs-evernote-mode ;; emacsからevernoteを編集 (require 'evernote-mode) (global-set-key "\C-cec" 'evernote-create-note) (global-set-key "\C-ceo" 'evernote-open-note) (global-set-key "\C-ces" 'evernote-search-notes) (global-set-key "\C-ceS" 'evernote-do-saved-search) (global-set-key "\C-cew" 'evernote-write-note) (global-set-key "\C-ceM" 'evernote-change-edit-mode) ;; moinmoin-mode (require 'moinmoin-mode) ;;------------------------------ ;; twittering-mode ;; Ref:http://twmode.sourceforge.net/ja/ ;;------------------------------ (add-to-list 'load-path "~/.emacs.d/site-lisp/twittering-mode-1.0.0") (require 'twittering-mode) (setq twittering-username "suji_ski") ;(setq twittering-icon-mode t) (setq twittering-jojo-mode t) ;; タイムラインのフォーマット変更 (defun twittering-mode-hook-func () (set-face-bold-p 'twittering-username-face t) (set-face-foreground 'twittering-username-face "DeepSkyBlue3") (set-face-foreground 'twittering-uri-face "LightBlue3") (define-key twittering-mode-map (kbd "F") 'twittering-favorite)) (setq twittering-status-format "%i %S(%s), %@:\n%FILL[ ]{%T // from %l%r%R}\n ") (add-hook 'twittering-mode-hook 'twittering-mode-hook-func) (setq twittering-retweet-format " QT @%s: %t") (let ((km twittering-mode-map)) (define-key km "\C-c\C-t" 'twittering-set-current-hashtag) nil)