home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / vmsnet / tpu / 487 < prev    next >
Encoding:
Internet Message Format  |  1992-11-10  |  2.3 KB

  1. Path: sparky!uunet!mcsun!sunic!dkuug!datani!ht
  2. From: ht@datani.dk
  3. Newsgroups: vmsnet.tpu
  4. Subject: Re: Procedure to matchup (){}[]  ???
  5. Message-ID: <1992Nov11.085850.108@datani.dk>
  6. Date: 11 Nov 92 07:58:50 GMT
  7. References: <1992Nov8.053543.383@wsuhub.uc.twsu.edu>
  8. Organization: Datani A/S, Copenhagen, Denmark
  9. Lines: 76
  10.  
  11. In article <1992Nov8.053543.383@wsuhub.uc.twsu.edu>, ldgiltne@wsuhub.uc.twsu.edu (Lawrence Giltner) writes:
  12. > Before I spend a lot of time reinventing the wheel:
  13. > Does anybody have a procedure to pair up parenthesis, brackets, and
  14. > braces.  I would like to put the cursor on one of ()[]{} and let the
  15. > program figure out which direction it has to search and if found, then
  16. > marks/selects all the text between them, including the ()[]{}.
  17. I have one that finds the corresponding paren, brac. or whatever, but it does
  18. not select the text between - mind you that is easy: just press select
  19. before you find the matching thingymagig.
  20.  
  21. ---------
  22. procedure find_bracket
  23. local
  24.   cur_ch,
  25.   this_ch,
  26.   br_list,
  27.   br_num,
  28.   pat,
  29.   level,
  30.   here,
  31.   there,
  32.   direction;
  33.  
  34.   cur_ch := get_info(get_info(BUFFER, 'current'), 'character');
  35.   br_list := "()[]{}<>+;!!??";
  36.   br_num := INDEX(br_list, cur_ch);
  37.  
  38.   if br_num = 0
  39.   then
  40.     MESSAGE ("Not on a bracket");
  41.   else
  42.     br_num := ((br_num+1)/2)*2 -1;
  43.     if br_num = INDEX(br_list, cur_ch)
  44.     then
  45.       direction:= FORWARD;
  46.     else
  47.       direction:= REVERSE;
  48.     endif;
  49.  
  50.     pat := ANY(SUBSTR(br_list, br_num, 2));
  51.     level := 1;
  52.     here := mark(NONE);
  53.  
  54.     loop
  55.       if direction = FORWARD
  56.       then
  57.         move_horizontal(1);
  58.       else
  59.         move_horizontal(-1);
  60.       endif;
  61.       there := search_quietly(pat, direction);
  62.       exitif there = 0;      
  63.       position(there);
  64.       this_ch := get_info(get_info(BUFFER, 'current'), 'character');
  65.       if this_ch = cur_ch
  66.       then
  67.           level := level + 1;
  68.       else
  69.           level := level - 1;
  70.       endif;                               
  71.       exitif level = 0;
  72.     endloop;
  73.     if there = 0 then
  74.       position(here);
  75.       message ("Matching bracket not found");
  76.     endif;
  77.   endif;
  78. endprocedure
  79.  
  80. ---
  81. compile it and bind it to a key of your choice.
  82. ---
  83. Henrik Tougaard             Postmaster, News-Reader and general dogsbody
  84. Datani A/S, Software Consultants
  85. Copenhagen, Denmark         Only my own opinions........
  86.