diff --git a/src/ce_dlang.pas b/src/ce_dlang.pas index 6828285c..d0c8ea7e 100644 --- a/src/ce_dlang.pas +++ b/src/ce_dlang.pas @@ -142,6 +142,11 @@ procedure lex(const text: string; list: TLexTokenList; clbck: TLexFoundEvent = n *) function getModuleName(const list: TLexTokenList): string; +(** + * Fills a list with all the modules imported in a tokenized D source. + *) +procedure getImports(const list: TLexTokenList; imports: TStrings); + (** * Compares two TPoints. *) @@ -946,7 +951,7 @@ begin end; {$ENDREGION} -{$REGION Syntactic errors} +{$REGION Utils} function TLexErrorList.getError(index: integer): TLexError; begin Result := PLexError(Items[index])^; @@ -1012,6 +1017,37 @@ begin end; end; +procedure getImports(const list: TLexTokenList; imports: TStrings); +var + i: integer; + imp: boolean; + tok: PLexToken; + itm: string = ''; +begin + for i:= 0 to list.Count-1 do + begin + tok := list[i]; + if (tok^.kind = ltkKeyword) and (tok^.Data = 'import') then + begin + imp := true; + continue; + end; + if not imp then + continue; + // + if (tok^.Data = '=') then + itm := '' + else if (tok^.Data = ';') or (tok^.Data = ':') or (tok^.Data = ',') then + begin + if length(itm) <> 0 then + imports.Add(itm); + itm := ''; + if (tok^.Data = ';') or (tok^.Data = ':') then + imp := false; + end else + itm += tok^.Data; + end; +end; {$ENDREGION} end. diff --git a/src/ce_editor.lfm b/src/ce_editor.lfm index 740e25a7..aaf24a62 100644 --- a/src/ce_editor.lfm +++ b/src/ce_editor.lfm @@ -135,5 +135,9 @@ inherited CEEditorWidget: TCEEditorWidget Caption = 'Save lexical tokens to file...' OnClick = MenuItem5Click end + object MenuItem8: TMenuItem + Caption = 'Save import to file...' + OnClick = MenuItem8Click + end end end diff --git a/src/ce_editor.pas b/src/ce_editor.pas index d857cc2d..587d4bd9 100644 --- a/src/ce_editor.pas +++ b/src/ce_editor.pas @@ -57,6 +57,7 @@ type MenuItem3: TMenuItem; MenuItem5: TMenuItem; MenuItem6: TMenuItem; + MenuItem8: TMenuItem; mnuedRename: TMenuItem; mnuedInvAllNone: TMenuItem; mnuedComm: TMenuItem; @@ -77,6 +78,7 @@ type mnuEditor: TPopupMenu; procedure MenuItem5Click(Sender: TObject); procedure MenuItem6Click(Sender: TObject); + procedure MenuItem8Click(Sender: TObject); procedure mnuedRenameClick(Sender: TObject); procedure mnuedInvAllNoneClick(Sender: TObject); procedure mnuedCommClick(Sender: TObject); @@ -802,6 +804,31 @@ begin end; end; +procedure TCEEditorWidget.MenuItem8Click(Sender: TObject); +var + str: TStringList; +begin + if fDoc.isNil then + exit; + if not fDoc.IsDSource and not fDoc.alwaysAdvancedFeatures then + exit; + with TSaveDialog.Create(nil) do + try + if execute then + begin + str := TStringList.Create; + fTokList.Clear; + lex(fDoc.Text, fTokList, nil, [lxoNoComments]); + getImports(fTOkList, str); + str.SaveToFile(filename); + fTokList.Clear; + str.Free; + end; + finally + free; + end; +end; + procedure TCEEditorWidget.MenuItem6Click(Sender: TObject); begin if fDoc.isNotNil then diff --git a/src/ce_synmemo.pas b/src/ce_synmemo.pas index f838e846..0fd99296 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -1436,8 +1436,6 @@ procedure TCESynMemo.handleStatusChanged(Sender: TObject; Changes: TSynStatusCha begin if scOptions in Changes then begin - //TODO-cLazarus: track changes in http://bugs.freepascal.org/view.php?id=30272 - // and remove this workaround if they fix it. if Beautifier.isNotNil and (Beautifier is TSynBeautifier) then begin if not (eoTabsToSpaces in Options) and not (eoSpacesToTabs in Options) then @@ -1549,7 +1547,6 @@ begin loadCache; fCacheLoaded := true; end; - // TODO-cbugfix: follow http://bugs.freepascal.org/view.php?id=30272 if detectIndentMode then begin case indentationMode(lines) of