Thread View: vmsnet.tpu
1 messages
1 total messages
Started by George D. Greenwade
Mon, 09 Nov 1992 16:32
RE: Procedure to matchup (){}[] ???
Author: George D. Greenwade
Date: Mon, 09 Nov 1992 16:32
Date: Mon, 09 Nov 1992 16:32
129 lines
5652 bytes
5652 bytes
On 8 Nov 92 05:35:43 CST, ldgiltne@wsuhub.uc.twsu.edu (Lawrence Giltner)
asked:
> Does anybody have a procedure to pair up parenthesis, brackets, and braces.
> I would like to put the cursor on one of ()[]{} and let the program figure
> out which direction it has to search and if found, then marks/selects all
> the text between them, including the ()[]{}.
>
> Is there a TPU procedure for this? TPU v2.6 on VMS v5.5.
>
> I wrote a procedure like this for VDE and would like the same convenience.
Taken shamelessly from my EFE code, I attach efe$find_match and
efe$find_matching. This set of two procedures allows you to place the
cursor on the opening delimiter, (, [, {, or <, and find the matching
closing delimiter. This function is defined as Gold/X in EFE. While I
haven't coded it in, it should be relatively trivial to do a backward
search, starting on the closing delimiter to find the opening delimiter
(copy efe$find_matching to something such as efe$find_matching_reverse,
change the search from forward to reverse in the copied procedure, add a
few extra if/endif statements near the start of efe$find_match pointing to
to efe$find_matching_reverse if the delimiter is a closer, etc.).
If you rename efe$find_match to something such as eve_match_delimiter, you
should be able to place the cursor on the opening delimiter, then use
DO/MATCH DELIMITER.
Regards, George
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
George D. Greenwade, Ph.D. Bitnet: BED_GDG@SHSU
Department of Economics and Business Analysis THEnet: SHSU::BED_GDG
College of Business Administration Voice: (409) 294-1266
P. O. Box 2118 FAX: (409) 294-3612
Sam Houston State University Internet: bed_gdg@SHSU.edu
Huntsville, TX 77341 bed_gdg%SHSU.decnet@relay.the.net
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure efe$find_match ! Find matching enclosures
local the_char, ! Character we want to match
original_position, ! Where we presently are (mark)
original_character, ! What we are trying to match
find_character, ! Character we are searching for
found_target, ! Where we are going (mark)
response; ! Check to go to first mark
original_position := mark(reverse);
original_character := current_character;
if original_character = "(" then find_character := ")" ;
else
if original_character = "[" then find_character := "]" ;
else
if original_character = "{" then find_character := "}" ;
else
if original_character = "<" then find_character := ">" ;
! EFE.TPU 25-APR-1991 18:18 PAGE 35
else message("Current character is not a valid starting delimiter. " +
"Must be (,[,{, or < .");
return;
endif;
endif;
endif;
endif;
if original_character = "(" then efe$find_matching("(",")");
else
if original_character = "[" then efe$find_matching("[","]");
else
if original_character = "{" then efe$find_matching("{","}");
else
if original_character = "<" then efe$find_matching("<",">");
endif;
endif;
endif;
endif;
if current_character <> find_character then
message(find_character + ' not found!');
position(original_position);
return;
endif;
found_target := mark(bold);
set(screen_update,on);
update(current_window);
EVE$PROMPT_STRING("",response,
"Return to original (boxed) search position? [Yes] ","");
edit(response,UPPER);
if SUBSTR(response,1,1) = "Y" then position(original_position);
else
if SUBSTR(response,1,1) = "" then position(original_position);
endif;
endif;
set(screen_update,on);
endprocedure; !efe$find_match
! EFE.TPU 25-APR-1991 18:18 PAGE 36
procedure efe$find_matching(match_left,match_right)
local next_close, ! Marks next closing paren
next_open, ! Marks next open paren
next_close_mark,
next_open_mark,
temp_mark;
on_error ! Ignore search fails
endon_error;
loop
move_horizontal (1);
next_close := search (match_right,forward);
if next_close = 0 then
return (0);
else
temp_mark := mark(none);
position (next_close);
next_close_mark := mark(none);
position (temp_mark);
endif;
next_open := search (match_left,forward);
if next_open <> 0 then
position (next_open);
next_open_mark := mark(none);
if next_open_mark < next_close_mark then
if (not efe$find_matching(match_left,match_right)) then
return (0);
endif;
else
position (next_close);
exitif 1;
endif;
else
position (next_close);
exitif 1;
endif;
endloop;
return (1);
endprocedure; !efe$find_matching
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads