無駄に長い .emacs を書いてみる

Emacs Lisplisp でいいんだろか。Plamo Linux 1.3 あたりにあった .emacs を使い続けてる。コメントが大量にあるから削除するかな。

;; -*- coding: iso-2022-7bit -*-
; これをしておけば、強制的に .emasc は jis で扱われるらしい
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  PJE-0.1 ユーザ設定ファイルサンプル for emacs(mule)
;;                       MATSUMOTO Shoji (shom@i.h.kyoto-u.ac.jp)
;;            just a bit adjusted by M.KOJIMA
;;                            Time-stamp: <2006-12-27 08:23:51 rin>
;;
;;  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PJE の Emacs(Mule) を利用するために必要な設定です。
;; (その他便利に利用するための設定はこのファイルの最後の
;;  「その他の設定」にあります)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(setq user-mail-address "rin@maaya.jp")
(setq user-full-name "Susumu Miwa")
(setq debug-on-error t)
(show-paren-mode)

(autoload 'server-edit "server" nil t)
(server-edit)

(defconst running-UNIX    (or (equal system-type 'gnu/linux) ;; linux
			      (equal system-type 'berkeley-unix) ;; SunOS
                              (equal system-type 'usg-unix-v)))  ;; Solaris

(defconst running-MacOS ( or ( equal system-type 'darwin)))

(defconst running-Emacs (and running-UNIX
                               (or (= emacs-major-version 20)
				   (= emacs-major-version 21)
				   (= emacs-major-version 22)
			       )))
(defconst running-XEmacs  (featurep 'xemacs))
(defconst running-Mule2.3 (and running-UNIX (= emacs-major-version 19)))

(defconst running-Meadow  (featurep 'meadow))


;;; 日本語環境
(cond
 (running-Meadow
  (set-language-environment "Japanese")
  (setq default-input-method "MW32-IME")
  (setq-default mw32-ime-mode-line-state-indicator "[--]")
  (setq mw32-ime-mode-line-state-indicator-list '("[--]" "[あ]""[--]"))
  (toggle-input-method)             ;;;; 起動時は IME OFF
  (mw32-ime-initialize)

 (create-fontset-from-request
   "myfontset"
   '((width . 9)
     (height . 18)
     (fixed . t)
     (italic . nil))
   '(
     (family . "Lucida Console")
     (family . "MS ゴシック")
     ))
 (create-fontset-from-request
   "hanyan"
   '((width . 9)
     (height . 18)
     (fixed . t)
     (italic . nil))
   '(
     (family . "OCR A Extended")
     (family . "MS ゴシック")
     ))

; (w32-query-get-logfont)

  (setq initial-frame-alist 
	'((foreground-color . "snow")
	  (background-color . "black")
	  (width . 80) (height . 25)
	  (top . 10) (left . 30)
	  ;;(menu-bar-lines . 1)
	  (vertical-scroll-bars . t)
	  (font . "myfontset") 
	  )
	)

  )
 (running-Mule2.3
;;; 漢字コードの指定 for mule19(Emacs20 では不要)
  (set-display-coding-system *euc-japan*unix)
  (set-keyboard-coding-system *euc-japan*unix)
  (set-default-file-coding-system *euc-japan*unix)
  )
 (running-Emacs 
  (set-language-environment "Japanese")
  (set-default-coding-systems 'euc-japan)
  (setq process-coding-system-alist '(("zsh" . euc-jp)))

  )
 (running-MacOS
  (set-language-environment 'Japanese)
  (set-default-coding-systems 'euc-jp)
  (set-buffer-file-coding-system 'euc-jp)
  (set-terminal-coding-system 'euc-jp-mac)
  (set-file-name-coding-system 'utf-8)
  (set-clipboard-coding-system 'sjis-mac)
  (set-keyboard-coding-system 'sjis-mac)
  (setq process-coding-system-alist '(("zsh" . euc-jp)))

  ;; ことえり
  ;;(utf-translate-cjk-mode 1)

  )

 (running-XEmacs
  ;; ...
  )
;; (running-MuleWin32
  ;; ...
;;  )
 (t   (message "running unknown Emacs"))
)


(toggle-input-method) ;; default to ASCII  
(global-set-key "\C-l" 'toggle-input-method)

;;; マクロサーチパスの追加
(setq load-path 
      (append 
       '("~/usr/local/share/emacs/site-lisp")
       '("/usr/pkg/share/emacs/site-lisp/w3m")
       '("/usr/pkg/share/emacs/site-lisp/apel")
       '("/usr/pkg/share/emacs/21.4/site-lisp/emu")
       '("/usr/pkg/share/emacs/site-lisp/ruby-mode")
       load-path))

;; マーク領域を色付け
(setq transient-mark-mode t)

;;; gzipされた日本語のinfoを見る
(auto-compression-mode t)

;; anthy
(when (locate-library "anthy")
  (load-file "/usr/local/share/emacs/site-lisp/anthy/leim-list.el")
  (load-library "anthy")
  (setq default-input-method "japanese-anthy")

  (setq anthy-wide-space " ")
  (global-set-key "\C-l" 'toggle-input-method))

;; TAB を使わない
(setq-default indent-tabs-mode nil)

;; TAB を 2 にする
( setq tab-width 2 )


;;;;
;; Ruby mode
;;;;
(require 'font-lock)
(autoload 'ruby-mode "ruby-mode")
(setq auto-mode-alist
      (append (list (cons "\\.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)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; その他の設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; ステータスラインに時間を表示する
(display-time)

;;; X 版 Mule の設定
(if (eq window-system 'x)
    (progn
      
      ;; カラー表示
      (setq hilit-mode-enable-list  nil
	    hilit-background-mode   'light
	    ;;hilit-background-mode   'dark
	    hilit-inhibit-hooks     nil
	    hilit-inhibit-rebinding nil)
      (require 'hilit19)

      ;;スクロールバーを消す
      ;;(scroll-bar-mode -1)

      ))

;;; 最終更新日の自動挿入
;;;   ファイルの先頭から 8 行以内に Time-stamp: <> または
;;;   Time-stamp: " " と書いてあれば、セーブ時に自動的に日付が挿入されます
(if (not (memq 'time-stamp write-file-hooks))
    (setq write-file-hooks
          (cons 'time-stamp write-file-hooks)))

;;
;; a2ps 用のフィルタ。
;; M-x print-buffer でカレントバッファの内容を
;; M-x print-region で選択している領域の部分を印刷できるらしい。
;;
;; Mew では Summary モードで 印刷したいメールにカーソルを合わせて
;; 「#」を叩く。

(setq lpr-switches '("-Pa2ps"))

;;;;;; C-mode で関数呼出と中カッコに色をつける
(font-lock-add-keywords 'c-mode
  '(("\\<\\([A-Za-z_][A-Za-z0-9_]*\\)(" 1 font-lock-function-call-face)
    ("[{}]" . font-lock-braces-face)
  )
  'append)

;;; 東京
(setq calendar-latitude 35.35)
(setq calendar-longitude 139.44)
(setq calendar-location-name "Tokyo, JP")

;; 日本
(setq calendar-time-zone +540)
(setq calendar-standard-time-zone-name "JST")
(setq calendar-daylight-time-zone-name "JST")


;; fontset 
(if nil
    (setq default-frame-alist
	  (append
	   '((line-space . "0") (width . 80) (height . 50)
	     (font . "fontSet-shinonome-marumoji-12"))
	   default-frame-alist)))
(if nil
    (setq default-frame-alist
	  (append
	   '((line-space . "0") (width . 80) (height . 50)
	     (font . "fontset-standard"))
	   default-frame-alist)))

;;
;; Subject: (ELF:01512) Re: 光る dabbrev-expand
;; From: Hideyuki SHIRAI (白井秀行) <shirai@rdmg.mgcs.mei.co.jp>
;; Date: Wed, 03 Apr 2002 21:33:06 +0900 (JST)
;;

(defvar dabbrev-expand-ad-overlay nil)
(defvar dabbrev-expand-ad-face 'highlight)
;; (defvar dabbrev-expand-ad-time 3)

(defadvice dabbrev-expand (after dabbrev-expand-ad activate)
  (let* ((start dabbrev--last-expansion-location)
	 (len (length dabbrev--last-expansion))
	 (buf (or dabbrev--last-buffer (current-buffer)))
	 (cbuf (current-buffer))
	 (cwin (selected-window))
	 end str lstart lend)
    (save-excursion
      (cond
       ((and (eq buf cbuf) (> start (point)))
	(setq end start)
	(setq start (- end len)))
       ((eq buf cbuf)
	(setq end (+ start len)))
       (t 
	(set-buffer buf)
	(setq end start)
	(setq start (- end len))))
      (if (and (get-buffer-window buf)
	       (select-window (get-buffer-window buf))
	       (pos-visible-in-window-p start)
	       (pos-visible-in-window-p end))
	  (progn
	    ;; overlay
	    (if dabbrev-expand-ad-overlay
		(move-overlay dabbrev-expand-ad-overlay start end)
	      (setq dabbrev-expand-ad-overlay (make-overlay start end)))
	    (overlay-put dabbrev-expand-ad-overlay 'evaporate t)
	    (overlay-put dabbrev-expand-ad-overlay 'face dabbrev-expand-ad-face))
	;; 一行表示
	(save-excursion
	  (save-restriction
	    (widen)
	    (goto-char start)
	    (setq str (buffer-substring-no-properties start end))
	    (setq lstart (progn (beginning-of-line) (point)))
	    (setq lend (progn (end-of-line) (point)))
	    (if (and (> emacs-major-version 20) (not (featurep 'xemacs)))
		(put-text-property 0 (length str) 'face dabbrev-expand-ad-face str)
	      (setq str (concat " *" str "* ")))
	    (message "%s(%d): %s%s%s"
		     (buffer-name buf)
		     (count-lines (point-min) start)
		     (buffer-substring-no-properties lstart start)
		     str
		     (buffer-substring-no-properties end lend)))))
      (select-window cwin)
      (add-hook 'pre-command-hook 'dabbrev-expand-ad-done))))

(defun dabbrev-expand-ad-done ()
  (remove-hook 'pre-command-hook 'dabbrev-expand-ad-done)
  (when dabbrev-expand-ad-overlay
    (delete-overlay dabbrev-expand-ad-overlay)))

;;
;; To: ELF@ml.gentei.org
;; Subject: (ELF:01128) 続: auto-save-visited-file-name
;; From: Katsumi Yamaoka <yamaoka@jpl.org>
;; Date: Thu, 12 Jul 2001 12:27:16 +0900
;;

(defvar auto-save-buffers-regexp ""
  "*Regexp that matches `buffer-file-name' to be auto-saved.")

(defun auto-save-buffers ()
  "Save buffers if `buffer-file-name' matches `auto-save-buffers-regexp'."
  (let ((buffers (buffer-list))
	buffer)
    (save-excursion
      (while buffers
	(set-buffer (car buffers))
	(if (and buffer-file-name
		 (buffer-modified-p)
		 (not buffer-read-only)
		 (string-match auto-save-buffers-regexp buffer-file-name)
		 (file-writable-p buffer-file-name))
	    (save-buffer))
	(setq buffers (cdr buffers))))))

(run-with-idle-timer 1 t 'auto-save-buffers)


;; C-x M で ~/memo/ChangeLog を開く
;; UNIX MAGAZINE 2002/01 横着プログラミング
(defun memo ()
  (interactive)
   (add-change-log-entry
    nil
    (expand-file-name "~/memo/ChangeLog")))
(define-key ctl-x-map "C" 'memo)


;;
;; だんだん色褪せる via 入門 Meadow/Emacs pp213-214
;; http://www.amazlet.com/browse/ASIN/4274065189/
;;
;; tomato 
;; /usr/local/share/emacs/21.3.50/etc/rgb.txt
;;   255   0 255		magenta
;;   255  99  71		tomato
;;

(setq highlight-changes-colours
      (let ((r 255) (g 0) (b 255) ;; init "magenta" value
            ret)
        (while (> (+ r g b) 0)
	  (setq ret (append ret (list (format "$%02x%02x%02x" r g b))))
	  (setq r (* (/ r 10) 8)
                g (* (/ g 10) 8)
                b (* (/ b 10) 8)))
	  ret))



;; ref. dired バッファを編集 ― 一括リネーム wdired
;; http://www.bookshelf.jp/soft/meadow_25.html#SEC292
(require 'wdired)
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; このファイルに間違いがあった場合に全てを無効にします
(put 'eval-expression 'disabled nil)