-更新日-: "2003年01月19日"

2. .emacs の小技

初期化ファイル .emacs をいじって、自分好みにしちゃおう。

[TOP] [Windows で Unix Like] [戻る]
;; オープニングメッセージを表示しない
(setq inhibit-startup-message t)
;; バックアップファイルを作成しない
;; 危険なので、注意して下さい
(setq make-backup-files nil)
;; オートセーブファイルを作成しない
;; 危険なので、注意して下さい
(setq auto-save-default nil)
(setq auto-save-list-file-name nil)
(setq auto-save-list-file-prefix nil)
;; C-k 1回で行全体を削除する
(setq kill-whole-line t)
;; バッファの最後で next-line しても新しい行を挿入しない
(setq next-line-add-newlines nil)
;; 1行づつスクロールする
(setq scroll-conservatively 1)
;; 対応する括弧をハイライトする
(show-paren-mode 1)
;; カーソル位置の桁数をモードライン行に表示する
(column-number-mode 1)
;; カーソル位置の行数をモードライン行に表示する
(line-number-mode 1)
;; リージョンを色付きにする
(transient-mark-mode 1)
;; 予約語を色分けする
(global-font-lock-mode t)
;; C-x C-b でバッファリストを開く時に、ウィンドウを分割しない
(global-set-key "\C-x\C-b" 'buffer-menu)
;; モードライン行の色の設定
;; NTEmacs では設定しない方が格好いい(^^ゞ
(set-face-foreground 'modeline "black")
(set-face-background 'modeline "green")
;; directory list の設定 (Dired mode の時 [↑]キーでジャンプが選択できる)
(setq file-name-history 
      '("~/"
	"c:/cygwin/home"
        "c:/cygwin/usr/local"))
;; 対応する括弧にジャンプする (C-t にキーバインドしてます)
;; byte-compile するとエラーが出ますが、大丈夫でしょう。(^^ゞ
(progn
  (defvar com-point nil
    "Remember com point as a marker. \(buffer specific\)")
  (set-default 'com-point (make-marker))
  (defun getcom (arg)
    "Get com part of prefix-argument ARG."
    (cond ((null arg) nil)
	  ((consp arg) (cdr arg))
	  (t nil)))
  (defun paren-match (arg)
    "Go to the matching parenthesis."
    (interactive "P")
    (let ((com (getcom arg)))
      (if (numberp arg)
	  (if (or (> arg 99) (< arg 1))
	      (error "Prefix must be between 1 and 99.")
	    (goto-char
	     (if (> (point-max) 80000)
		 (* (/ (point-max) 100) arg)
	       (/ (* (point-max) arg) 100)))
	    (back-to-indentation))
	(cond ((looking-at "[\(\[{]")
	       (if com (move-marker com-point (point)))
	       (forward-sexp 1)
	       (if com
		   (paren-match nil com)
		 (backward-char)))
	      ((looking-at "[])}]")
	       (forward-char)
	       (if com (move-marker com-point (point)))
	       (backward-sexp 1)
	       (if com (paren-match nil com)))
	      (t (error ""))))))
  (global-set-key "\C-t" 'paren-match))
;; タイトルバーに日時を表示する
(setq display-time-day-and-date t
      display-time-12hr-format t)
(setq display-time-string-forms
      '((if display-time-day-and-date
	    (format "%s/%s/%s " year month day)
	  "")
	(format "%s:%s%s"
		(if display-time-24hr-format 24-hours 12-hours)
		minutes
		(if display-time-24hr-format "" am-pm))))
(display-time)
(cond (window-system
       (setq frame-title-format
	     '((multiple-frames "")
	       display-time-string))
       (remove-hook 'global-mode-string 'display-time-string)))
;; カーソル行をウィンドウの1行目にする (C-x C-l にキーバインドしてます。)
(defun line-to-top-of-window ()
  "Move the line point is on to top of window."
  (interactive) 
  (recenter 0))
(global-set-key "\C-x\C-l" 'line-to-top-of-window)
;; isearch に入った後、C-d と押すと次の一文字を拾ってきます。
;; C-d と押した数だけ次の文字を拾ってきます。
;; 白井さん作です。
(defun isearch-yank-char ()
  "Pull next character from buffer into search string."
  (interactive)
  (isearch-yank-string
   (save-excursion
     (and (not isearch-forward) isearch-other-end
          (goto-char isearch-other-end))
     (buffer-substring (point) (1+ (point))))))
(define-key isearch-mode-map "\C-d" 'isearch-yank-char)

行の折り返しを表す`\'を他の文字に変更する
1行で表示できない場合、行末に `$' や `\' が付くのですが、何となくいやなので、 `↓'に変更します。
他に、`^M' や `^L' などの `^'が上付きの `c'になります。
[meadow-users-jp: 3549] で知りました。
ただし、bitmap-muleが必要です。

;; 行の折り返しを表す`\'を他の文字に変更する。
(defsubst set-standard-display-slot (slot glyph)
  (set-display-table-slot standard-display-table slot glyph))
(defsubst bitmap-compose-char (string)
  (string-to-char (bitmap-compose string)))

(let ((slot-glyph-alist '((wrap . "00000808080808080808082A1C080000")
			  (truncation . "0000000000002442FF42240000000000")
			  (escape . "00001C223C201C000000000000000000")
			  (control . "00001C222020221C0000000000000000")))
      slot-glyph slot glyph)
  (while (setq slot-glyph (pop slot-glyph-alist))
    (setq slot (car slot-glyph))
    (setq glyph (bitmap-compose-char (cdr slot-glyph)))
    (set-standard-display-slot slot glyph)))

Emacs21.1 に特有な設定
;; cursor の blink を止める
(blink-cursor-mode 0)
;; active でない window の空 cursor を出さない
(setq cursor-in-non-selected-windows nil)

Meadow の起動を早くする
.emacs が大きくなってくると起動が遅くなります。(そう感じるのは非力な計算機を使っている私だけかもしれませんが)
で、.emacs をバイトコンパイルすると読込みが早くなります。
Emacs 20.4 から .emacs.el を初期化ファイルに使用できるので、簡単です。
つまり、.emacs と .emacs.el の両方があると、.emacs.el が読込まれるようです。で、さらに .emacs.elc が あると .emacs.el の替わりに .emacs.elc が読まれるということらしいです。
方法その1
初期化ファイルを .emacs から .emacs.el に変えてバイトコンパイルするだけです。
  1. C-x C-f ~/.emacs.el で読込んでおいて、
  2. M-x (Escape x) byte-compile-file でバイトコンパイル
方法その2
上の方法を .emacs.el が変更されてたら、自動的に行います。
  1. .emacs.el の最初に下記を記入します。
  2. 方法その1と同様にまず .emacs.el をバイトコンパイルします。 すると、.emacs.el が変更されている(正確には .emacs.elc より新しい)と、自動的にバイトコンパイルして終了します。 2度目から Meadow が起動します。
    **注意**
    以降、設定は .emacs.el に書込まないと反映されません。
(defvar init "~/.emacs.el")
(and (boundp 'init)
     (stringp init)
     (file-newer-than-file-p init "~/.emacs.elc")
     (let ((mode-line-format "")
	   (mode-line-inverse-video nil))
	  (message  "wait! Your %s needs recompiling..." init)
	  (sit-for 1)
	  (byte-compile-file init)
	  t)
     (kill-emacs))

[TOP] [Windows で Unix Like]
http://www.yumi-chan.com/
Last Modified: Sun, 19 Jan 2003 17:41:05 +0900