Created
April 12, 2012 10:59
-
-
Save leque/2366512 to your computer and use it in GitHub Desktop.
行中で最初に現れた括弧と対応する閉じ括弧を(薄く)ハイライトする(編集には未対応)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 行中で最初に現れた括弧と対応する閉じ括弧を(薄く)ハイライトする | |
;;; (jit-lock-register #'dehighlight-paren) | |
;;; で動くつもり | |
(defvar paren-face 'paren-face) | |
(make-face 'paren-face) | |
(set-face-foreground 'paren-face "grey90") | |
(defun dehighlight-paren-1 (pos) | |
(add-text-properties pos (1+ pos) | |
`(font-lock-face ,paren-face | |
rear-nonsticky t))) | |
(defun dehighlight-paren-rl () | |
(save-excursion | |
(let ((close (point))) | |
(forward-char) | |
(backward-sexp) | |
(when (catch 'tag | |
(while (not (bolp)) | |
(backward-char) | |
(when (eq (syntax-class (syntax-after (point))) 4) | |
(throw 'tag nil))) | |
t) | |
(dehighlight-paren-1 (point)) | |
(dehighlight-paren-1 close))))) | |
(defun dehighlight-paren-lr () | |
(save-excursion | |
(let ((open (point))) | |
(forward-sexp) | |
(backward-char) | |
(dehighlight-paren-1 open) | |
(dehighlight-paren-1 (point))))) | |
(defun dehighlight-paren (start end) | |
(save-excursion | |
(goto-char start) | |
(while (< (point) end) | |
(forward-char) | |
(let ((mode 'open)) | |
(case (syntax-class (syntax-after (point))) | |
((4) | |
(when (not (eq mode 'close)) | |
(dehighlight-paren-lr)) | |
(forward-line)) | |
((5) | |
(setq mode 'close) | |
(dehighlight-paren-rl))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment