逆引きxyzzy lisp(テキスト) - circleratio/xyzzy GitHub Wiki

目次

テキストに属性を設定する(色、書体など)

設定、変更する

(set-text-attribute 1 10 'attr1 :bold t)
=> t

(modify-text-attributes 'attr1 :foreground 1 :strike-out t :underline t)
=> t

属性を調べる

list-text-attributes の結果は set-text-attributes に apply させることができる。

(list-text-attributes)
=> ((1 10 attr1 :foreground 1 :underline t :strike-out t))

(find-text-attribute-point 5)
=> 1
   10
   attr1
   1
   nil
   nil
   t
   t
   nil
   nil

削除する

(delete-text-attributes 'attr1)
=> t

(delete-text-attribute-point 5)
=> nil

(clear-all-text-attributes)
=> t

指定した正規表現にマッチした部分に色を付ける

(defun highlight-pattern (regexp color)
  (interactive)
  (delete-text-attributes 'all)
  (goto-char (point-min))
  (while (scan-buffer regexp :regexp t)
    (let ((from (point))
          (to (+ (point) (length (match-string 0)))))
      (set-text-attribute from to 'all :foreground color :bold t))
    (forward-char)))

(highlight-pattern ":[a-z]+" 4)
⚠️ **GitHub.com Fallback** ⚠️