按《让fpc/lazarus支持中文变量/过程/函数/中文控件名称》增加中文变量支持后,lazarus使用中文变量等代码补全时,列表框没对应的中文变量的:
找到procedure InitCharTable;(lazarus 3.4在63行)
解决方法:
要修改以下3个文件,打开相应文件,添加红字代码,修改后重新编译lazarus就可以。
找到procedure InitCharTable;(lazarus 3.4在63行)
procedure InitCharTable; var c:char; begin for c:=low(char) to high(char) do case c of 'a'..'z','A'..'Z','_',#$80..#$FF:CharTable[c]:=ctWordBegin; '0'..'9':CharTable[c]:=ctWord; else CharTable[c]:=ctNone; end; end;
2、\lazarus\ide\sourceeditor.pp
找到procedure TSourceEditor.StartWordCompletionBox;(lazarus 3.4在5420行)
procedure TSourceEditor.StartWordCompletionBox; var TextS: String; LogCaret: TPoint; i: Integer; TextS2: String; Completion: TSourceEditCompletion; begin if (FEditor.ReadOnly) then exit; Completion := Manager.DefaultCompletionForm; if (Completion.CurrentCompletionType<>ctNone) then exit; Completion.CurrentCompletionType:=ctWordCompletion; TextS := FEditor.LineText; LogCaret:=FEditor.LogicalCaretXY; Completion.Editor:=FEditor; i := LogCaret.X - 1; if i > length(TextS) then TextS2 := '' else begin while (i > 0) and (TextS[i] in ['a'..'z','A'..'Z','0'..'9','_',#$80..#$FF]) do dec(i); TextS2 := Trim(copy(TextS, i + 1, LogCaret.X - i - 1)); end; Completion.Execute (TextS2, Manager.GetScreenRectForToken(FEditor, FEditor.CaretX-length(TextS2), FEditor.CaretY, FEditor.CaretX-1)); end;
3、\lazarus\components\synedit\syncompletion.pas
找到function IsIdentifierChar(p: PChar): boolean; inline;(lazarus 3.4在481行),在对应的位置添加红色代码
function IsIdentifierChar(p: PChar): boolean; inline; {$IF FPC_FULLVERSION >= 20701} var u: UnicodeString; i: Integer; L: SizeUInt; {$ENDIF} begin Result := p^ in ['a'..'z','A'..'Z','0'..'9','_',#$80..#$FF]; if Result then exit; {$IF FPC_FULLVERSION >= 20701} if p^ <= #127 then exit; i := UTF8CodepointSize(p); SetLength(u, i); // wide chars of UTF-16 <= bytes of UTF-8 string if ConvertUTF8ToUTF16(PWideChar(u), i + 1, p, i, [toInvalidCharToSymbol], L) = trNoError then begin SetLength(u, L - 1); if L > 1 then Result := TCharacter.IsLetterOrDigit(u, 1); end; {$ENDIF} end;
修改后中文也可以使用代码补全功能(Ctrl+W):
分类:
Lazarus
标签:
lazarus/fpc中文支持
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~