Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs: evaluate blink-matching-open when cursor highlights a parenthesis

Recently while editing lisp code in emacs, I have been frustrated in tracking matching parenthesis. (show-paren-mode t) helps when the matching parenthesis is visable within the buffer along with its match, and (setq blink-matching-paren t) is helpful when writing the matching parenthesis. Is there a way to hook show-paren-mode so that the blink-mathing-open function evaluates as part of the "show" process? In this manner, I can place the cursor up to a parenthesis and know what it matches against without deleting and retyping it.

Thanks,

SetJmp

like image 689
Setjmp Avatar asked May 12 '11 19:05

Setjmp


2 Answers

Try this

(defadvice show-paren-function (after blink activate)
  (when (= ?\) (char-before (point)))
    (blink-matching-open)))

Or, just use C-M-b and C-M-f to move back and forth between the point and the corresponding parenthesis.

like image 190
huaiyuan Avatar answered Nov 09 '22 03:11

huaiyuan


My favorite paren package is mic-paren, which shows you the matching paren like you describe - it even works when the matching paren is offscreen (it shows some info in the echo area).

Download and put somewhere in your load-path, and add this to your .emacs:

(require 'mic-paren)
(paren-activate)

There are a number of configuration options you can choose from, read the comments at the top of the package.

like image 32
Trey Jackson Avatar answered Nov 09 '22 04:11

Trey Jackson