use LTerm_text.stylise_parenthesis
Ignore-this: 89d793e3ecb8b555d195d7cdfeed0610 darcs-hash:20110809063116-c41ad-2ac81c5f65ec52f21883c5c8cb52383f62ba7c4e
This commit is contained in:
parent
1f9576e22c
commit
7a791ae5ef
|
@ -359,91 +359,7 @@ object(self)
|
|||
loop_sharp tokens;
|
||||
|
||||
(* Parenthesis matching. *)
|
||||
|
||||
if not last && Array.length styled > 0 then begin
|
||||
let rec rsearch idx left right depth =
|
||||
if idx >= Array.length styled then
|
||||
None
|
||||
else
|
||||
let ch, _ = styled.(idx) in
|
||||
if ch = right then
|
||||
if depth = 0 then
|
||||
Some idx
|
||||
else
|
||||
rsearch (idx + 1) left right (depth - 1)
|
||||
else if ch = left then
|
||||
rsearch (idx + 1) left right (depth + 1)
|
||||
else
|
||||
rsearch (idx + 1) left right depth
|
||||
in
|
||||
let rec lsearch idx left right depth =
|
||||
if idx < 0 then
|
||||
None
|
||||
else
|
||||
let ch, _ = styled.(idx) in
|
||||
if ch = left then
|
||||
if depth = 0 then
|
||||
Some idx
|
||||
else
|
||||
lsearch (idx - 1) left right (depth - 1)
|
||||
else if ch = right then
|
||||
lsearch (idx - 1) left right (depth + 1)
|
||||
else
|
||||
lsearch (idx - 1) left right depth
|
||||
in
|
||||
let matched =
|
||||
if position = Array.length styled then
|
||||
false
|
||||
else
|
||||
let ch, _ = styled.(position) in
|
||||
match
|
||||
if ch = lparen then
|
||||
rsearch (position + 1) lparen rparen 0
|
||||
else if ch = lbrace then
|
||||
rsearch (position + 1) lbrace rbrace 0
|
||||
else if ch = lbracket then
|
||||
rsearch (position + 1) lbracket rbracket 0
|
||||
else if ch = rparen then
|
||||
lsearch (position - 1) lparen rparen 0
|
||||
else if ch = rbrace then
|
||||
lsearch (position - 1) lbrace rbrace 0
|
||||
else if ch = rbracket then
|
||||
lsearch (position - 1) lbracket rbracket 0
|
||||
else
|
||||
None
|
||||
with
|
||||
| Some idx ->
|
||||
let ch, style = styled.(idx) in
|
||||
styled.(idx) <- (ch, LTerm_style.merge styles.style_paren style);
|
||||
true
|
||||
| None ->
|
||||
false
|
||||
in
|
||||
if not matched && position > 0 then
|
||||
let ch, style = styled.(position - 1) in
|
||||
match
|
||||
if ch = lparen then
|
||||
rsearch (position + 1) lparen rparen 0
|
||||
else if ch = lbrace then
|
||||
rsearch (position + 1) lbrace rbrace 0
|
||||
else if ch = lbracket then
|
||||
rsearch (position + 1) lbracket rbracket 0
|
||||
else if ch = rparen then
|
||||
lsearch (position - 2) lparen rparen 0
|
||||
else if ch = rbrace then
|
||||
lsearch (position - 2) lbrace rbrace 0
|
||||
else if ch = rbracket then
|
||||
lsearch (position - 2) lbracket rbracket 0
|
||||
else
|
||||
None
|
||||
with
|
||||
| Some idx ->
|
||||
styled.(position - 1) <- (ch, LTerm_style.merge styles.style_paren style);
|
||||
let ch, style = styled.(idx) in
|
||||
styled.(idx) <- (ch, LTerm_style.merge styles.style_paren style)
|
||||
| None ->
|
||||
()
|
||||
end;
|
||||
if not last then LTerm_text.stylise_parenthesis styled position styles.style_paren;
|
||||
|
||||
(styled, position)
|
||||
|
||||
|
|
Loading…
Reference in New Issue