home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / gnu / emacs / help / 3734 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.3 KB  |  38 lines

  1. Path: sparky!uunet!olivea!hal.com!decwrl!sun-barr!male.EBay.Sun.COM!exodus.Eng.Sun.COM!exodus!jsc
  2. From: jsc@saxon.Eng.Sun.COM (John Cooper)
  3. Newsgroups: gnu.emacs.help
  4. Subject: Re: Matching Parenthesis
  5. Message-ID: <JSC.92Aug14135854@saxon.Eng.Sun.COM>
  6. Date: 14 Aug 92 20:58:54 GMT
  7. References: <1992Aug13.222811.12442@cbfsb.cb.att.com>
  8.     <KEVIN.92Aug14095203@buffalobill.edscom.demon.co.uk>
  9. Distribution: usa
  10. Organization: SunSoft, Inc., Mountain View, CA
  11. Lines: 23
  12. NNTP-Posting-Host: saxon
  13. In-reply-to: kevin@edscom.demon.co.uk's message of 14 Aug 92 09:52:03 GMT
  14.  
  15. > "Kevin" == Kevin Broadey <kevin@edscom.demon.co.uk> writes:
  16.  
  17.     Kevin>    Can someone give me a method in emacs to achieve the
  18.     Kevin>    equivalent of vi's "%" command that helps match
  19.     Kevin>    parenthesis in a given file.
  20.  
  21. If you like things a little more 'electric', try this:
  22.  
  23. (defun match-paren (arg)
  24.   "Go to the matching parenthesis if on parenthesis otherwise insert %."
  25.   (interactive "p")
  26.   (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
  27.     ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
  28.     (t (self-insert-command (or arg 1)))))
  29.  
  30. (global-set-key "%"             'match-paren)
  31.  
  32. This means if the cursor is over a parenthesis, hitting % will move to
  33. the matching paren, otherwise it will insert a % .
  34.  
  35.     --- John.
  36. --
  37.     --- John
  38.