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

  1. Path: sparky!uunet!airgun!airgun.wg.waii.com!jct
  2. From: jct@se33.wg2.waii.com (Jim Thompson)
  3. Newsgroups: gnu.emacs.help
  4. Subject: Re: Matching Parenthesis
  5. Message-ID: <JCT.92Aug16090848@se33.wg2.waii.com>
  6. Date: 16 Aug 92 13:08:48 GMT
  7. References: <1992Aug13.222811.12442@cbfsb.cb.att.com>
  8. Sender: news@airgun.wg.waii.com
  9. Distribution: usa
  10. Organization: Western Geophysical Exploration Products
  11. Lines: 25
  12. Nntp-Posting-Host: se33.wg2.waii.com
  13. In-reply-to: anand@cbnewsb.cb.att.com's message of 13 Aug 92 22:28:11 GMT
  14.  
  15. In article <1992Aug13.222811.12442@cbfsb.cb.att.com> anand@cbnewsb.cb.att.com (anand.r.setlur) writes:
  16.  
  17. > Can someone give me a method in emacs to achieve the equivalent of vi's 
  18. > "%" command that helps match parenthesis in a given file.
  19.  
  20. Someone posted this to comp.emacs a few months ago; sorry, but I don't
  21. remember who.  It works as follows: if you're over a paren-type
  22. character and you type '%', it will jump you to the matching character
  23. (if there is one).  If you're not over a paren-type character, it
  24. inserts a '%' as normal:
  25.  
  26. (global-set-key "%" 'match-paren)
  27.   
  28. (defun match-paren (arg)
  29.   "Go to the matching parenthesis if on parenthesis otherwise insert %."
  30.   (interactive "p")
  31.   (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
  32.     ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
  33.     (t (self-insert-command (or arg 1)))))
  34.  
  35. --
  36.    _    Jim Thompson           |  Wanted:
  37.  _| ~-  thompson@wg2.waii.com  |    Nick Park's "Grand Day Out"
  38.  \,  _} Western Geophysical    |    on VHS-format videotape
  39.    \(   Houston, Texas         |  Email me if you know where I can buy it.
  40.