Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Parentheses When Inside Them - Emacs

In emacs there is a mode show-paren-mode which colors the opposite matching parenthesis when the cursor is on the other. I wrote an example explaining show-paren-mode:

( <-colored  colored-> )| <-cursor 

However it does not work when the cursor is not on the parenthesis:

( <-not colored    cursor inside->|    not colored-> )

How can I enable this? I find that when performing slurpage and barfage in paredit I cannot keep track of the parentheses very well because they are not colored unless I am on them.

This is optimal:

( <-colored    cursor inside->|    colored-> )

Edit: Thanks to the comment by @lawlist I have resolved this issue.

like image 349
Spenser Truex Avatar asked Jan 18 '16 02:01

Spenser Truex


1 Answers

This works well for me (more recent Emacs version (than 25?) may be required for the new advice implementation):

(define-advice show-paren-function (:around (fn) fix)
  "Highlight enclosing parens."
  (cond ((looking-at-p "\\s(") (funcall fn))
        (t (save-excursion
             (ignore-errors (backward-up-list))
             (funcall fn)))))
like image 58
huaiyuan Avatar answered Nov 08 '22 15:11

huaiyuan