秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  278 随笔 :: 0 文章 :: 308 评论 :: 20万 阅读
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
按《让fpc/lazarus支持中文变量/过程/函数/中文控件名称》增加中文变量支持后,lazarus使用中文变量等代码补全时,列表框没对应的中文变量的:

 解决方法:
要修改以下3个文件,打开相应文件,添加红字代码,修改后重新编译lazarus就可以。

1、\lazarus\ide\wordcompletion.pp
找到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):

 

posted on   秋·风  阅读(265)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示