Send via SMS

Saturday, January 14, 2006

Emacsに色をつける

インデントに応じて色を変えると便利かと思ったのだが、 こういうことをするためには 文字ごとに属性を設定しなければならないらしい。 面倒なのでやる気がうせたが一応作ってみた。
(setq indent-colors
     '(
       "DarkSeaGreen1"
       "DarkSeaGreen2"
       "DarkSeaGreen3"
       "DarkSeaGreen4"
       "SeaGreen1"
       "SeaGreen2"
       "SeaGreen3"
       "SeaGreen4"
       "PaleGreen1"
       "PaleGreen2"
       "PaleGreen3"
       ))

(defun set-indent-color ()
 (let (symbol face indent)
   (setq indent (% (indent-level) (length indent-colors)))
   (setq symbol (make-symbol (concat "indent" (format "%d" indent))))
   (setq face (make-face symbol))
   (set-face-foreground face "black")
   (set-face-background face (indent-color indent))
   (save-excursion
     (let (start end)
       (beginning-of-line)
       (setq start (point))
       (end-of-line)
       (setq end (point))
       (if (looking-at "\n") (setq end (1+ (point))))
       (put-text-property start end 'face face)
       ))
   ))

(defun set-indent-colors ()
 (save-excursion
   (let (old new (done nil))
     (goto-char 1)
     (setq old (point))
     (while (not done)
       (set-indent-color)
       (forward-line)
       (setq new (point))
       (setq done (= old new))
       (setq old new)
       )
   )))

(defun indent-color (indent)
 (let (c)
   (setq c (nth indent indent-colors))
   (if (null c)
       (setq c "white"))
   c
   ))

(defun indent-level ()
 (save-excursion
   (progn
     (beginning-of-line)
     (re-search-forward "[^ \t]" nil t)
     (backward-char)
     (current-column)
     )))

1 Comments:

Masatake YAMATO said...

インデントの深さで制御構造を与えるpythonのコードにはうってつけかもしれないと思いました。

4:35 AM  

Post a Comment

Links to this post:

Create a Link

<< Home