Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display line of matching bracket in the minibuffer

When I type a close bracket in emacs, the minibuffer shows the line that contains the matching open bracket. Is there a way to display the matching line of a bracket, parenthesis etc in the minibuffer without deleting the bracket and retyping it?

like image 492
Dan Avatar asked Nov 27 '12 00:11

Dan


3 Answers

I assume you have turned on show-paren-mode so matching parens are highlighted:

(show-paren-mode t)

Then this will show the matching line if the paren is off the screen:

(defadvice show-paren-function (after my-echo-paren-matching-line activate)
  "If a matching paren is off-screen, echo the matching line."
  (when (char-equal (char-syntax (char-before (point))) ?\))
    (let ((matching-text (blink-matching-open)))
      (when matching-text
        (message matching-text)))))
like image 93
scottfrazer Avatar answered Sep 27 '22 20:09

scottfrazer


You can do M-x blink-matching-open RET and if you like to use it often, bind it to a key.

like image 44
Stefan Avatar answered Sep 27 '22 19:09

Stefan


scotfrazer's answer works great for parens, braces etc, but if you need to match ruby def...end or class...end delimiters (or similar in other languages) this answer from emacs.stackexchange works great:

(defvar match-paren--idle-timer nil)
(defvar match-paren--delay 0.5)
(setq match-paren--idle-timer 
     (run-with-idle-timer match-paren--delay t #'blink-matching-open))

The matching (off-page) delimiter will be highlighted if you pause the cursor on a delimiter for .5 seconds or longer.

like image 44
blaedj Avatar answered Sep 27 '22 19:09

blaedj