Question

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?

Was it helpful?

Solution

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)))))

OTHER TIPS

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

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.

You can install the Mic Paren (available on MELPA: M-x package-install mic-paren) and activate it with M-x paren-activate

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top