Skip to content

Instantly share code, notes, and snippets.

@codecoll
Created March 15, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecoll/c861390a518556211388f87914db5023 to your computer and use it in GitHub Desktop.
Save codecoll/c861390a518556211388f87914db5023 to your computer and use it in GitHub Desktop.
Emacs - Always highlight matching parent (use echo area if out of screen)
(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
(defun my-show-paren-for-line-setup-overlay ()
(if (and (looking-at ".*))\\s-*$")
(not (eq (char-before) ?\))))
(save-excursion
(ignore-errors
(end-of-line)
(backward-sexp)
(if (< (point) (window-start))
(message "Matches %s" (buffer-substring (line-beginning-position) (line-end-position)))
(move-overlay my-show-paren-for-line-overlay (point) (1+ (point)))
(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)
(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