added additional brace closing option, lexically

This commit is contained in:
Basile Burg 2016-02-02 07:55:15 +01:00
parent d265769009
commit 7b423b5b34
2 changed files with 47 additions and 19 deletions

View File

@ -10,7 +10,7 @@ uses
SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView, SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView,
SynEditMarks, SynEditTypes, SynHighlighterJScript, SynEditMarks, SynEditTypes, SynHighlighterJScript,
ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs, ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs,
ce_sharedres; ce_sharedres, ce_dlang;
type type
@ -24,7 +24,8 @@ type
TBraceAutoCloseStyle = ( TBraceAutoCloseStyle = (
autoCloseNever, autoCloseNever,
autoCloseAtEof, autoCloseAtEof,
autoCloseAlways autoCloseAlways,
autoCloseLexically
); );
TIdentifierMatchOptions = set of TIdentifierMatchOption; TIdentifierMatchOptions = set of TIdentifierMatchOption;
@ -138,6 +139,7 @@ type
fCallTipStrings: TStringList; fCallTipStrings: TStringList;
fOverrideColMode: boolean; fOverrideColMode: boolean;
fAutoCloseCurlyBrace: TBraceAutoCloseStyle; fAutoCloseCurlyBrace: TBraceAutoCloseStyle;
fLexToks: TLexTokenList;
procedure setMatchOpts(value: TIdentifierMatchOptions); procedure setMatchOpts(value: TIdentifierMatchOptions);
function getMouseFileBytePos: Integer; function getMouseFileBytePos: Integer;
procedure changeNotify(Sender: TObject); procedure changeNotify(Sender: TObject);
@ -164,6 +166,7 @@ type
procedure removeBreakPoint(line: integer); procedure removeBreakPoint(line: integer);
function findBreakPoint(line: integer): boolean; function findBreakPoint(line: integer): boolean;
procedure showCallTips(const tips: string); procedure showCallTips(const tips: string);
function lexCanCloseBrace: boolean;
protected protected
procedure DoEnter; override; procedure DoEnter; override;
procedure DoExit; override; procedure DoExit; override;
@ -468,6 +471,7 @@ begin
fDefaultFontSize := 10; fDefaultFontSize := 10;
Font.Size:=10; Font.Size:=10;
SetDefaultCoeditKeystrokes(Self); // not called in inherited if owner = nil ! SetDefaultCoeditKeystrokes(Self); // not called in inherited if owner = nil !
fLexToks:= TLexTokenList.Create;
// //
OnDragDrop:= @ddHandler.DragDrop; OnDragDrop:= @ddHandler.DragDrop;
OnDragOver:= @ddHandler.DragOver; OnDragOver:= @ddHandler.DragOver;
@ -557,6 +561,8 @@ begin
fCompletion.Free; fCompletion.Free;
fBreakPoints.Free; fBreakPoints.Free;
fCallTipStrings.Free; fCallTipStrings.Free;
fLexToks.Clear;
fLexToks.Free;
// //
if fTempFileName.fileExists then if fTempFileName.fileExists then
sysutils.DeleteFile(fTempFileName); sysutils.DeleteFile(fTempFileName);
@ -1072,6 +1078,21 @@ end;
{$ENDREGION --------------------------------------------------------------------} {$ENDREGION --------------------------------------------------------------------}
{$REGION Coedit memo things ----------------------------------------------------} {$REGION Coedit memo things ----------------------------------------------------}
function TCESynMemo.lexCanCloseBrace: boolean;
var
i: integer;
c: integer = 0;
tok: PLexToken;
begin
for i := 0 to fLexToks.Count-1 do
begin
tok := PLexToken(fLexToks[i]);
c += byte((tok^.kind = TLexTokenKind.ltkSymbol) and (tok^.Data = '{'));
c -= byte((tok^.kind = TLexTokenKind.ltkSymbol) and (tok^.Data = '}'));
end;
exit(c > 0);
end;
procedure TCESynMemo.SetHighlighter(const Value: TSynCustomHighlighter); procedure TCESynMemo.SetHighlighter(const Value: TSynCustomHighlighter);
begin begin
inherited; inherited;
@ -1341,12 +1362,19 @@ begin
else else
showCallTips(fCallTipStrings.Text); showCallTips(fCallTipStrings.Text);
end; end;
'{': if fAutoCloseCurlyBrace <> autoCloseNever then '{': case fAutoCloseCurlyBrace of
begin autoCloseAlways:
if fAutoCloseCurlyBrace = autoCloseAlways then
curlyBraceCloseAndIndent(self)
else if (CaretY = Lines.Count) and (CaretX = LineText.length+1) then
curlyBraceCloseAndIndent(self); curlyBraceCloseAndIndent(self);
autoCloseAtEof:
if (CaretY = Lines.Count) and (CaretX = LineText.length+1) then
curlyBraceCloseAndIndent(self);
autoCloseLexically:
begin
fLexToks.Clear;
lex(lines.Text, fLexToks);
if lexCanCloseBrace then
curlyBraceCloseAndIndent(self);
end;
end; end;
end; end;
if fCompletion.IsActive then if fCompletion.IsActive then

View File

@ -470,7 +470,7 @@ Custom macros can be edited in the [options editor][lnk_widg_opts]:
![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/optmacros.png) ![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/optmacros.png)
Note that since version 2, the pre-defined macros are not hardcoded anymore and they can be completly deleted. Note that since version 2, the predefined macros are not hardcoded anymore and they can be completely deleted.
#### Editor options #### Editor options
@ -484,7 +484,7 @@ They cover many aspects of the editor:
![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/editor.options.png) ![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/editor.options.png)
The editor shortcuts are listed here: The shortcuts are editable from the [option editor][lnk_widg_opts], category _Shortcuts, Code editor_:
![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/editor.shortcuts.png) ![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/editor.shortcuts.png)
@ -517,13 +517,13 @@ The _find and replace_ widget allows to find and replace text patterns in the fo
- allow regex: when checked, the search is performed by a regex engine (which doesn't mean that the pattern to find has to be a regex). - allow regex: when checked, the search is performed by a regex engine (which doesn't mean that the pattern to find has to be a regex).
By default <kbd>CTRL</kbd> + <kbd>F</kbd> is used to pass the current identifier to the first field and <kbd>F3</kbd> to execute a search. By default <kbd>CTRL</kbd> + <kbd>F</kbd> is used to pass the current identifier to the first field and <kbd>F3</kbd> to execute a search.
Unless _Find all_ is used, the results are directly visible in the editor. _Find all_ results are displayed in the [messages widget][lnk_widg_msg], with a context and they are clickable.
_Find all_ results are displayed in the [messages widget][lnk_widg_msg] and are clickable.
![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/search2.png)
The scope of _Find all_ can be set, either to the current editor or to the whole project, by clicking the icon at the right. The scope of _Find all_ can be set, either to the current editor or to the whole project, by clicking the icon at the right.
The most recent searches and replacements are saved between each session. Note that to find the declaration of a symbol, <kbd>Ctrl</kbd> + <kbd>MB Left</kbd> or the [symbol list][lnk_widg_symlist] are faster.
Note that to find a symbol, <kbd>Ctrl</kbd> + <kbd>MB Left</kbd> or the [symbol list][lnk_widg_symlist] are faster.
## Library manager widget ## Library manager widget