home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!hal.com!decwrl!sun-barr!male.EBay.Sun.COM!exodus.Eng.Sun.COM!exodus!jsc
- From: jsc@saxon.Eng.Sun.COM (John Cooper)
- Newsgroups: gnu.emacs.help
- Subject: Re: Matching Parenthesis
- Message-ID: <JSC.92Aug14135854@saxon.Eng.Sun.COM>
- Date: 14 Aug 92 20:58:54 GMT
- References: <1992Aug13.222811.12442@cbfsb.cb.att.com>
- <KEVIN.92Aug14095203@buffalobill.edscom.demon.co.uk>
- Distribution: usa
- Organization: SunSoft, Inc., Mountain View, CA
- Lines: 23
- NNTP-Posting-Host: saxon
- In-reply-to: kevin@edscom.demon.co.uk's message of 14 Aug 92 09:52:03 GMT
-
- > "Kevin" == Kevin Broadey <kevin@edscom.demon.co.uk> writes:
-
- Kevin> Can someone give me a method in emacs to achieve the
- Kevin> equivalent of vi's "%" command that helps match
- Kevin> parenthesis in a given file.
-
- If you like things a little more 'electric', try this:
-
- (defun match-paren (arg)
- "Go to the matching parenthesis if on parenthesis 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)))))
-
- (global-set-key "%" 'match-paren)
-
- This means if the cursor is over a parenthesis, hitting % will move to
- the matching paren, otherwise it will insert a % .
-
- --- John.
- --
- --- John
-