[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: finding matching braces.

From: Michael P. Soulier
Subject: Re: finding matching braces.
Date: Sun, 23 Dec 2001 12:02:28 -0500
User-agent: Mutt/1.3.24i

On 23/12/01 Subhakar K S did speaketh:

> Is it possible in emacs to find a matching (opening /
> closing ) brace of a block in C++ code.
> In vi, I can use SHIFT-% to toggle between the 
> opening and closing braces of a code block.
> void some_func( void )
> {-->opening brace.
>    // do something;
> }--> closing brace. SHIFT-% will take me opening
> brace
> Is this possible with emacs.


Remap the % to do this if it's sitting on a parenthesis, and to call
self-insert-command otherwise. Granted, this means you'll never be
able to insert a % in front of a parenthesis without extra keystrokes,
but how often does that happen?

;; for simulating Vi's % capability
(defun match-paren (arg)
  "Go to the matching paren if on a paren; otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(")(forward-list 1)(backward-char 1))   
        ((looking-at "\\s\)")(forward-char 1)(backward-list 1))
        (t (self-insert-command (or arg 1)))))


Michael P. Soulier <>, GnuPG pub key: 5BC8BE08
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix

Attachment: pgpo1c2nOtx0m.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]