; elscreen = GNU screenライクなタブ機能
(load "elscreen" "ElScreen" t)
; elscreen + 自動的にスクリーンを作る
(defmacro elscreen-create-automatically (ad-do-it)
  (` (if (not (elscreen-one-screen-p))
	 (, ad-do-it)
       (elscreen-notify-screen-modification 'force-immediately)
       (elscreen-message "New screen is automatically created"))))
(defadvice elscreen-next (around elscreen-create-automatically activate)
  (elscreen-create-automatically ad-do-it))
(defadvice elscreen-previous (around elscreen-create-automatically activate)
  (elscreen-create-automatically ad-do-it))
(defadvice elscreen-toggle (around elscreen-create-automatically activate)
  (elscreen-create-automatically ad-do-it))
; yank-pop-summary = yankのリストを表示
;(autoload 'yank-pop-forward "yank-pop-summary" nil t)
;(autoload 'yank-pop-backward "yank-pop-summary" nil t)
;(global-set-key "¥M-y" 'yank-pop-forward)
;(global-set-key "¥C-¥M-y" 'yank-pop-backward)
; kill-summary.el
;(autoload 'kill-summary "kill-summary" nil t)
;(global-set-key "¥M-y" 'kill-summary)
; browser-kill-ring.el
(require 'browse-kill-ring)
(define-key ctl-x-map "¥C-y" 'browse-kill-ring)
; session.el = 履歴を保存
(when (require 'session nil t)
  (setq session-initialize '(de-saveplace session keys menus)
        session-globals-include '((kill-ring 50)
                                  (session-file-alist 100 t)
                                  (file-name-history 100)))
  (add-hook 'after-init-hook 'session-initialize))
; auto-save-buffers = バッファの自動保存
(require 'auto-save-buffers)
(run-with-idle-timer 0.5 t 'auto-save-buffers) 
(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)
; dired::バッファを新しく開かない
(defun dired-find-alternate-file ()
  "In dired, visit this file or directory instead of the dired buffer."
  (set-buffer-modified-p nil)
  (find-alternate-file (dired-get-filename)))
; dired::lsの環境差異をls-listで吸収したりwdiredで色々
(add-hook 'dired-load-hook
          '(lambda ()
             (load-library "ls-lisp")
             (setq ls-lisp-dirs-first t)
             (setq dired-listing-switches "-AFl")
             (setq find-ls-option '("-exec ls -AFGl {} \\;" . "-AFGl"))
             (setq grep-find-command "find . -type f -print0 | xargs -0 -e grep -ns ")
             (require 'wdired)
; dired::本日変更ファイルを強調
(defface my-face-f-2 '((t (:foreground "GreenYellow"))) nil)
(defvar my-face-f-2 'my-face-f-2)
(defun my-dired-today-search (arg)
  "Fontlock search function for dired."
   (concat (format-time-string "%b %e" (current-time)) " [0-9]....") arg t))
(add-hook 'dired-mode-hook
          '(lambda ()
               '(my-dired-today-search . my-face-f-2)
; dired::windows explorer風isearch
(defvar my-ex-isearch-next      "¥C-r")
(defvar my-ex-isearch-prev      "¥C-e")
(defvar my-ex-isearch-backspace "¥C-h")
(defvar my-ex-isearch-return    "¥C-g")
(defun my-ex-isearch (REGEX1 REGEX2 FUNC1 FUNC2 RPT)
  (let ((input last-command-char)
        (inhibit-quit t)
        (oldpoint (point)) regx str)
      (catch 'END
        (while t
          (funcall FUNC1)
           ;; character
           ((and (integerp input) (>= input ?!)(<= input ?‾)
                 (not (and (>= input ?A)(<= input ?Z))))
            (setq str (concat str (char-to-string input)))
            (setq regx (concat REGEX1 str REGEX2))
            (re-search-forward regx nil t nil))
           ;; backspace
           ((and (integerp input)
                 (or (eq 'backspace input)
                     (= input (string-to-char my-ex-isearch-backspace))))
            (setq str (if (eq 0 (length str)) str (substring str 0 -1)))
            (setq regx (concat REGEX1 str REGEX2))
            (goto-char oldpoint)
            (re-search-forward regx nil t nil))
           ;; next
           ((and (integerp input) (= input (string-to-char my-ex-isearch-next)))
            (re-search-forward regx nil t RPT))
           ;; previous
           ((and (integerp input) (= input (string-to-char my-ex-isearch-prev)))
            (re-search-backward regx nil t nil))
           ;; return
           ((and (integerp input) (= input (string-to-char my-ex-isearch-return)))
            (goto-char oldpoint)
            (message "return")
            (throw 'END nil))
           ;; other command
            (setq unread-command-events (append (list input) unread-command-events))
            (throw 'END nil)))
          (funcall FUNC2)
          (message str)
          (setq input (read-event)))))))
(defun my-dired-isearch()
  (my-ex-isearch "[0-9] " "[^ ¥n]+$" (lambda()(backward-char 3)) 'dired-move-to-filename 2))
(defun my-dired-isearch-define-key (str)
  (let ((i 0))
    (while (< i (length str))
      (define-key dired-mode-map (substring str i (1+ i)) 'my-dired-isearch)
      (setq i (1+ i)))))
(add-hook 'dired-mode-hook
          '(lambda ()
             (my-dired-isearch-define-key "abcdefghijklmnopqrstuvwxyz0123456789_.-+‾#")
; dired::view-mode
(defvar my-view-from-dired-flag nil)
(make-variable-buffer-local 'my-view-from-dired-flag)
(defvar my-binary-file-ext-list
  '("tar" "tar.gz" "mpg" "jpg" "gif" "png"))
(defvar my-binary-file-exp "¥¥.elc$")
(let ((l my-binary-file-ext-list))
  (while l
    (setq my-binary-file-exp
          (concat my-binary-file-exp "¥¥|¥¥." (car l) "$"))
    (setq l (cdr l))))
(defun my-dired-view-file ()
  (unless (or (file-directory-p (dired-get-filename))
              (string-match my-binary-file-exp (dired-get-filename)))
    (view-file (dired-get-filename))
    (setq my-view-from-dired-flag t)))
(defun my-View-next-file-in-dired ()
  (when my-view-from-dired-flag
    (my-dired-next-line 1)
(defun my-View-prev-file-in-dired ()
  (when my-view-from-dired-flag
    (my-dired-previous-line 1)
(add-hook 'dired-mode-hook
          '(lambda ()
             (define-key dired-mode-map "\C-v"      'my-dired-view-file)
(add-hook 'view-mode-hook
          '(lambda ()
             (define-key view-mode-map "N" 'my-View-next-file-in-dired)
             (define-key view-mode-map "P" 'my-View-prev-file-in-dired)
; wdired
(require 'wdired)
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
; mapae::MTフロントエンド
;(require 'mapae "mapae.el")
;(setq mapae-perl-command "/usr/bin/perl")
;(setq mapae-command "/Users/mamutaro/perl/mapae.pl")
;(global-set-key "¥C-cwn" 'mapae-new-post)
;(global-set-key "¥C-cwr" 'mapae-get-recent-post)
;(global-set-key "¥C-cwg" 'mapae-get-post)
;(global-set-key "¥C-cwl" 'mapae-get-recent-titles)
; バッファ移動
(defvar my-ignore-blst            ; 移動の際に無視するバッファのリスト
  '("*Help*" "*Mew completions*" "*Completions*" "*Shell Command Output*"
    "*Buffer List*"))
(defvar my-vblst nil)             ; 移動開始時の buffer list を保存
(defvar my-bslen 15)              ; buffer list 中の buffer name の最長値
(defvar my-blst-display-time 2)   ; buffer list の表示時間
(defface my-cbface                ; buffer list 中の current buffer を示す face
  '((t (:foreground "red" :underline t))) nil)
(defvar my-op-mode) ; 自動設定される変数 (1 前移動 2 次移動 3 ID移動 4 フィルタ)
(defvar my-spliter-alist ; バッファ表示中のバッファ間のスプリッタ
  '((1 . " < ") (2 . " > ") (3 . " ") (4 . " / ")))
(defvar my-prompt-alist ; バッファ表示中のプロンプト
  '((1 . "[<<-] ") (2 . "[->>] ") (3 . "") (4 . "")))
(defun my-visible-buffers (blst &optional reg)
  (if (eq blst nil) '()
    (let ((bufn (buffer-name (car blst))))
      (if (or (= (aref bufn 0) ? )                  ; ミニバッファと
              (not (string-match (or reg "") bufn)) ; reg を含まないバッファと
              (member bufn my-ignore-blst))         ; 無視するバッファには移動しない
          (my-visible-buffers (cdr blst) reg)
        (cons (car blst) (my-visible-buffers (cdr blst) reg))))))
(defun my-buf-id (buf) (format "%s) " (length (memq buf (reverse my-vblst)))))
(defun my-show-buffer-list ()
  (let* ((prompt (cdr (assq my-op-mode my-prompt-alist)))
         (spliter (cdr (assq my-op-mode my-spliter-alist)))
         (len (string-width prompt))
         (str (mapconcat
               (lambda (buf)
                 (let ((bs (copy-sequence (buffer-name buf))))
                   (if (> (string-width bs) my-bslen) ; 切り詰め
                       (setq bs (concat (substring bs 0 (- my-bslen 2)) "..")))
                   (setq len (+ len (string-width (concat bs spliter))))
                   (when (eq buf (current-buffer)) ; 表示中のバッファは強調表示
                     (put-text-property 0 (length bs) 'face 'my-cbface bs))
                   (cond ((> len (frame-width)) ;; frame 幅で適宜改行
                          (setq len (+ (string-width (concat prompt bs spliter))))
                          (concat "\n" (make-string (string-width prompt) ? ) bs))
                         (t (concat (and (= my-op-mode 3) (my-buf-id buf)) bs))))) ; ID
               my-vblst spliter)))
    (cond ((<= my-op-mode 2) ; 単純移動
           (let (message-log-max)
             (message "%s%s" prompt str))
           (if (sit-for my-blst-display-time) (message nil))) ; 表示を消す
          ((= my-op-mode 3) ; バッファの ID を指定して移動
           (let* ((id-str (read-string (concat str "¥nSpecify Buffer ID: ")))
                  (id (string-to-number id-str)))
             (if (and (>= id 1) (<= id (length my-vblst))) ;; 移動できる ID なら
                 (switch-to-buffer (nth (1- id) my-vblst)) ;; 移動する
               ;; 空文字列をIDに指定して、さらにIDを指定しようとしていたら終了
               (unless (and (eq my-op-mode 3) (string= id-str "")) ; (*)
                 (my-show-buffer-list))))) ; さもなければ my-op-mode で再処理
          ((= my-op-mode 4) ; バッファ名を正規表現でフィルタ
           (let* ((reg (read-string (concat str "¥nBuffer-name regexp: "))))
             ;; フィルタで絞込みをかけて移動候補のバッファを再設定
             (setq my-vblst (or (my-visible-buffers my-vblst reg) my-vblst))
             ;; 空文字列で絞込みしていなければ、更新された移動候補の先頭に移動
             (when (not (string= reg "")) (switch-to-buffer (car my-vblst)))
             ;; 空文字列で絞込みして、さらに絞込みをしようとしていたら終了
             (when (or (not (eq my-op-mode 4)) (not (string= reg ""))) ; (*)
               (my-show-buffer-list)))) ; さもなければ my-op-mode に従い再処理
(defun my-operate-buffer (mode)
  (setq my-op-mode mode)
  ;; my-show-buffer-list 中の read-string を潰す↓の exit-minibuffer より先に
  ;; ↑で my-op-mode に mode を指定しておく (*) 時に有効
  (when (window-minibuffer-p (selected-window)) (exit-minibuffer))
  (unless (eq last-command 'my-operate-buffer)  ; バッファリスト初期化
    (setq my-vblst (my-visible-buffers (buffer-list))))
  (when (<= my-op-mode 2)
    (let* ((blst (if (= my-op-mode 2) my-vblst (reverse my-vblst))))
      (switch-to-buffer (or (cadr (memq (current-buffer) blst)) (car blst)))))
  (setq this-command 'my-operate-buffer))
(defun my-sellect-visible-buffers () (interactive) (my-operate-buffer 3))
(defun my-filter-visible-buffers () (interactive) (my-operate-buffer 4))
(global-set-key [?¥C-,] (lambda () (interactive) (my-operate-buffer 1)))
(global-set-key [?¥C-.] (lambda () (interactive) (my-operate-buffer 2)))
(global-set-key [?¥C-@] 'my-sellect-visible-buffers)
(global-set-key [?¥C-¥;] 'my-filter-visible-buffers)
; kill-bufferで変なバッファに行かない
(defun my-kill-buffer (buf)
  (interactive "bKill buffer: ")
  (let* ((blst (my-visible-buffers (buffer-list)))
   (nbuf (or (car (cdr (memq (get-buffer buf) blst))) (car blst))))
    (kill-buffer buf)
    (unless (memq (get-buffer buf) blst) ;; バッファが消えなければ移動しない
      (switch-to-buffer (get-buffer-create nbuf)))))
; *scratch*バッファを消さない
(defun my-make-scratch (&optional arg)
    ;; "*scratch*" を作成して buffer-list に放り込む
    (set-buffer (get-buffer-create "*scratch*"))
    (funcall initial-major-mode)
    (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)
(add-hook 'after-save-hook
          ;; *scratch* バッファの内容を保存したら *scratch* バッファを新しく作る
          (lambda ()
            (unless (member (get-buffer "*scratch*") (buffer-list))
              (my-make-scratch 1))))
; redo
(require 'redo)
(global-set-key "¥C-]" 'redo)
; color-moccur = 検索
(require 'color-moccur)
; moccur-edit = 検索結果バッファでの編集をファイルに反映
(load "moccur-edit")
; migemo
;(load "migemo.el")
; minibuf-isearch
(require 'minibuf-isearch)
; dabbrev-highlight.el = 強調表示付き動的略称展開
(require 'dabbrev-highlight)
; shell-comman.el = 補完が効くように
(require 'shell-command)
;;; shell-mode
; パスワード入力を隠す
(add-hook 'comint-output-filter-functions
; エスケープシーケンスを処理
(autoload 'ansi-color-for-comint-mode-on "ansi-color"
          "Set `ansi-color-for-comint-mode' to t." t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
; mode-info = 変数や関数の説明をInfoを利用して表示する
(require 'mi-config)
(define-key global-map "¥C-hf" 'mode-info-describe-function)
(define-key global-map "¥C-hv" 'mode-info-describe-variable)
(define-key global-map "¥M-." 'mode-info-find-tag)
(require 'mi-fontify)
; ChangeLogのメールアドレス
(setq add-log-mailing-address "KoshigoeSuzuki@gmail.com")
; psvn.el = subversion
;(require 'psvn)
;(define-key svn-status-mode-map "q" 'egg-self-insert-command)
;(define-key svn-status-mode-map "Q" 'svn-status-bury-buffer)
;(define-key svn-status-mode-map "p" 'svn-status-previous-line)
;(define-key svn-status-mode-map "n" 'svn-status-next-line)
;(define-key svn-status-mode-map "<" 'svn-status-examine-parent)
;(add-hook 'dired-mode-hook
;          '(lambda ()
;             (require 'dired-x)
;             ;;(define-key dired-mode-map "V" 'cvs-examine)
;             (define-key dired-mode-map "V" 'svn-status)
;             (turn-on-font-lock)
;             ))
;(setq svn-status-hide-unmodified t)
;(setq process-coding-system-alist
;      (cons '("svn" . utf-8) process-coding-system-alist))
; vc-svn.el = subversion
(add-to-list 'vc-handled-backends 'SVN)
; not create backupfile
(setq make-backup-files nil)
(setq auto-save-default nil)
; window setting
;; region の色
(set-face-background 'region "black")
(set-face-foreground 'region "white")
(if (boundp 'window-system)
    (setq initial-frame-alist
          (append (list
                   '(foreground-color . "black") ;; 文字が白
                   '(background-color . "white") ;; 背景は黒
                   '(border-color     . "black")
                   '(mouse-color      . "black")
                   '(cursor-color     . "black")
                   '(cursor-type      . box)
                   '(menu-bar-lines . 1)
                   ;;15.2 フォントの設定 (2005/05/06) で設定したフォントを使用
                   ;'(font . "my-fontset")
                   ;; 東雲なら shinonome16-fontset などを指定
                   '(vertical-scroll-bars . nil) ;;スクロールバーはいらない
                   '(width . 120) ;; ウィンドウ幅
                   '(height . 65) ;; ウィンドウの高さ
                   '(top . 0) ;;表示位置
                   '(left . 900) ;;表示位置
(setq default-frame-alist initial-frame-alist)
koshigoewiki/開発環境/emacs/emacs.txt · 最終更新: 2006/01/22 20:01 by koshigoebushou
Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki