-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmatch.kex
103 lines (97 loc) · 5.95 KB
/
cmatch.kex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'set novalue on' /* force KEXX and its way of SIGNAL ON NOVALUE */
/* Usage: MACRO CMATCH */
/* Example: DEF S-F3 'MACRO CMATCH' */
/* SYNONYM CMATCH MACRO CMATCH */
/* Purpose: Use Kedit's CMATCH command for REXX and XHTML. */
/* Background: Kedit's CMATCH matches pairs of nested braces, */
/* e.g., with the cursor on a closing '}' press */
/* shift-F3 to execute a CMATCH. This locates the */
/* corresponding opening '{' or reports an error */
/* if brackets are not properly nested. Pressing */
/* shift-F3 again jumps back to '}'. CMATCH also */
/* handles '('..')', '['..']', and '<'..'>' pairs. */
/* REXX match: To get the same effect for 'DO' or 'SELECT' and */
/* 'END' pairs MACRO CMATCH uses procedure RMATCH. */
/* BAK, step 1: RMATCH saves the edited file as BAK-file, KEDIT */
/* automatically removes temporary BAK-files later */
/* when SET BACKUP TEMP is in effect. */
/* LOC, step 2: RMATCH notes the actual cursor position in the */
/* edited file, loads the identical BAK file, and */
/* moves the cursor to the same line and column. */
/* It then locates the begin of the focus word, in */
/* the case of an 'END' the 'E'. */
/* X2C, step 3: Modifying the loaded BAK file copy cannot cause */
/* any problems. RMATCH changes literal braces to */
/* dummy characters, replaces all 'SELECT' or 'DO' */
/* by '{', and all 'END' by '}'. */
/* Command CMATCH can then locate the matching '{' */
/* or '}' as in C-files. It is not necessary to */
/* reset 'CASE M I I' for case insensitive changes */
/* later, the setting only affects the temporarily */
/* loaded =.BAK file. */
/* MSG, step 4: RMATCH notes any CMATCH error message and the */
/* new cursor location, quits the temporary file, */
/* goes to the same location in the edited file, */
/* or shows the noted CMATCH error message. */
/* XHTML match: For XHTML <div> ... </div> and similar pairs of */
/* nested tags almost the same matching strategy */
/* works. Instead of the focus word XMATCH uses */
/* SET WORD ALPHA to find the 'd' in '</div>', and */
/* for XHTML matching is case sensitive. It isn't */
/* necessary to reset WORD ALPHA later, the change */
/* only affects the temporarily loaded =.BAK file. */
/* The list of tags matched by XMATCH is a matter */
/* of taste, simply add what you need often. */
/* Caveats: HTML is not XHTML, and XMATCH does not work for */
/* case insensitive HTML tags. Add a 'CASE M I I' */
/* to XMATCH if you need case insensitive matches. */
/* Installation: Replace 'cmatch' by 'macro cmatch' for S-F3 (or */
/* S+F3 in KeditW terminology). Command CMATCH is */
/* in practice only used with a key, and it is not */
/* required to create SYNONYM CMATCH MACRO CMATCH. */
/* Updated 2017: Use a KeditW32 Language Definition if coloring */
/* is ON excl. the built-in parsers NULL and HTML. */
/* See KHELP for COLORING, PARSER, CMATCH. */
/* See also: KHELP WORD, KHELP BACKUP, KHELP CMATCH */
/* Requires: Kedit 5.0 or KeditW 1.0 (Frank Ellermann, 2008) */
do until 1
if version.1() = 'KEDIT' then leave
if version.2() < 1.5 then leave
if coloring.1() = 'OFF' then leave
if DONTUSE( '*NULL.KLD *HTML.KLD' ) then leave
'command cmatch' ; exit rc
end
end
if sign( wordpos( translate( focusword.1()), 'DO SELECT END' ))
then exit RMATCH()
if sign( wordpos( focusword.1(), 'div pre ol ul p' ))
then exit XMATCH( focusword.1())
'command cmatch' ; exit rc
DONTUSE: return sign( pos( parser.2( coloring.3()), arg( 1 )))
RMATCH: procedure
ROW = line.1() ; COL = column.1() ; BAK = '=:=\=.bak'
'ssave' BAK ; 'kedit' BAK '(noprof' ; if rc <> 0 then return rc
'case M I I' ; 'loc :' ROW 'cl :' COL ; 'cursor column'
'sos startw' ; ONE = ' DO '
'nomsg c' delimit( '{', x2c( 1 )) 'all *' ; TWO = ' END '
'nomsg c' delimit( ONE, left( ' {', length( ONE ))) 'all *'
'nomsg c' delimit( '}', x2c( 2 )) 'all *' ; ONE = ' SELECT '
'nomsg c' delimit( ONE, left( ' {', length( ONE ))) 'all *'
'nomsg c' delimit( TWO, left( ' }', length( TWO ))) 'all *'
'nomsg cmatch' ; MSG = lastmsg.1() ; if rc = 0 then MSG = ''
ROW = line.1() ; COL = column.1()
'qquit' ; 'loc :' ROW 'cl :' COL ; 'cursor column'
if MSG <> '' then 'emsg' MSG ; return MSG <> ''
XMATCH: procedure
ROW = line.1() ; COL = column.1() ; BAK = '=:=\=.bak'
'ssave' BAK ; 'kedit' BAK '(noprof' ; if rc <> 0 then return rc
'word alpha' ; 'loc :' ROW 'cl :' COL ; 'cursor column'
'sos startw' ; if 0 then 'case M I I'
'nomsg c' delimit( '{', x2c( 1 )) 'all *' ; ONE = '<' || arg(1)
'nomsg c' delimit( ONE, left( ' {', length( ONE ))) 'all *'
'nomsg c' delimit( '}', x2c( 2 )) 'all *' ; TWO = '</' || arg(1)
'nomsg c' delimit( TWO, left( ' }', length( TWO ))) 'all *'
'nomsg cmatch' ; MSG = lastmsg.1() ; if rc = 0 then MSG = ''
ROW = line.1() ; COL = column.1()
'qquit' ; 'loc :' ROW 'cl :' COL ; 'cursor column'
if MSG <> '' then 'emsg' MSG ; return MSG <> ''