Home > Archives > 2007年03月17日

2007年03月17日

Emacs Lisp をいじるの覚書 - プロパティというか face というか

テキストのプロパティは get-text-property で手に入る.face もプロパティなので (get-text-property (point) 'face) でカーソル位置の face がわかる.カーソル位置の face が適当な face だったら処理をするとかを次のように書ける.

(if (let ((prop (get-text-property (point) 'face))) (or (eq 'line-number-face prop) (eq 'over-under-full-face prop)))
 (しょり~))

これの場合 'line-number-face か 'over-under-full-face だったらなにかすると.

face の指定時に mouse-face を付けてあげるとマウスに反応して face を変えられる.font-lock-defaults に渡す font-lock-keywords のなかで,

(cons "\\(.*full ..box.*\\)\\(line.*\\)"
    '((1 over-under-full-face)
      (2 line-number-face)))

とか書くところを

(cons "\\(.*full ..box.*\\)\\(line.*\\)"
  '((1 (progn
        (set-text-properties (match-beginning 1) (match-end 1)
			    '(mouse-face highlight))
         'over-under-full-face))
    (2 (progn
         (set-text-properties (match-beginning 2) (match-end 2)
 			    '(mouse-face highlight))
          'line-number-face))))

のようにプロパティを設定する関数 set-text-properties を呼ぶようにする.よくわからんが 1 とか 2 とかの数字はマッチした subexpression の番号らしい.あとは,マウスが押されたときに関数を呼ぶように mode の設定のとこで

(local-set-key [mouse-1] 'hogehoge-suru-function)

とか設定しとけばいいみたい.

Home > Archives > 2007年03月17日

Search
Feeds

Page Top