Created
March 15, 2020 20:15
-
-
Save codecoll/335f1c4bf45482bd70832589e96362c6 to your computer and use it in GitHub Desktop.
Emacs - Always highlight matching parent (use inline overlay if out of screen)
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
(defun my-show-paren-for-line-start () | |
(interactive) | |
(add-hook 'post-command-hook 'my-show-paren-for-line-setup-overlay t t)) | |
(defun my-show-paren-for-line-stop () | |
(interactive) | |
(remove-hook 'post-command-hook 'my-show-paren-for-line-setup-overlay t)) | |
(setq my-show-paren-for-line-overlay (make-overlay (point) (point))) | |
(overlay-put my-show-paren-for-line-overlay | |
'face '(background-color . "cyan")) | |
(delete-overlay my-show-paren-for-line-overlay) ;; hide it | |
(setq my-show-paren-for-line-out-of-sight-overlay (make-overlay (point) (point))) | |
(delete-overlay my-show-paren-for-line-out-of-sight-overlay) ;; hide it | |
(defun my-show-paren-for-line-setup-overlay () | |
(if (and (looking-at ".*))\\s-*$") | |
(not (eq (char-before) ?\)))) | |
(let (out-of-sight) | |
(save-excursion | |
(ignore-errors | |
(end-of-line) | |
(backward-sexp) | |
(if (< (point) (window-start)) | |
(progn | |
(beginning-of-line) | |
(skip-syntax-forward " ") | |
(setq out-of-sight (buffer-substring (point) (line-end-position))) | |
(let ((max 20)) | |
(if (> (length out-of-sight) 20) | |
(setq out-of-sight (concat (substring out-of-sight 0 20) | |
"..."))))) | |
(move-overlay my-show-paren-for-line-overlay (point) (1+ (point)))))) | |
(when out-of-sight | |
(move-overlay my-show-paren-for-line-out-of-sight-overlay | |
(1- (line-end-position)) | |
(line-end-position)) | |
(overlay-put | |
my-show-paren-for-line-out-of-sight-overlay | |
'after-string | |
(propertize (concat " ;; " out-of-sight " ") | |
'face 'font-lock-comment-face))) | |
(add-hook 'pre-command-hook 'my-show-paren-for-line-hide-overlay t t)))) | |
(defun my-show-paren-for-line-hide-overlay () | |
(delete-overlay my-show-paren-for-line-overlay) | |
(delete-overlay my-show-paren-for-line-out-of-sight-overlay) | |
(remove-hook 'pre-command-hook 'my-show-paren-for-line-hide-overlay t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment