Now with attachment! 😀

On Tue, Aug 20, 2019 at 6:48 PM Darius Blaszyk <dhkblas...@gmail.com> wrote:

> Hi!
>
> Attached a (still) naive patch that implements automatic completion upon
> keypress. It's already giving me a big boost in productivity so I thought I
> might share it here. It would be good to make the identifier invocation a
> bit smarter. For instance I would like to prevent invocation in case the
> word is part of a string or comment. Also it should auto hide after the
> first character gets deleted by backspace. Any tips or hints how to use the
> codetools to get the required information is appreciated!
>
> Rgds, Darius Blaszyk
>
> On Fri, Aug 16, 2019 at 10:55 PM Martin Frb via lazarus <
> lazarus@lists.lazarus-ide.org> wrote:
>
>> On 16/08/2019 19:07, Darius Blaszyk via lazarus wrote:
>> > Hi,
>> >
>> > I know about code completion in the IDE and it works perfectly!
>> > However, to invoke it I need to press CRTL-space every time which is
>> > somewhat cumbersome. Is there a setting in the IDE that would invoke
>> > completion automatically on keypress?
>> >
>> It can auto invoke after you enter a dot "form1."
>> But otherwise not.
>>
>> See https://bugs.freepascal.org/view.php?id=33054
>> --
>> _______________________________________________
>> lazarus mailing list
>> lazarus@lists.lazarus-ide.org
>> https://lists.lazarus-ide.org/listinfo/lazarus
>>
>
Index: ide/editoroptions.pp
===================================================================
--- ide/editoroptions.pp	(revision 61726)
+++ ide/editoroptions.pp	(working copy)
@@ -1406,6 +1406,7 @@
   TEditorOptions = class(TIDEEditorOptions)
   private
     FBlockTabIndent: Integer;
+    fAutoShowCompletion: Boolean;
     FCompletionLongLineHintInMSec: Integer;
     FCompletionLongLineHintType: TSynCompletionLongHintType;
     FMiddleTabClickClosesOthersModifier: TShiftState;
@@ -1702,6 +1703,8 @@
       write FAutoRemoveEmptyMethods default False;
     property CompletionLongLineHintInMSec: Integer
              read FCompletionLongLineHintInMSec write FCompletionLongLineHintInMSec;
+    property AutoShowCompletion: Boolean
+             read fAutoShowCompletion write fAutoShowCompletion;
   published
     property CompletionLongLineHintType: TSynCompletionLongHintType
              read FCompletionLongLineHintType write FCompletionLongLineHintType
@@ -5006,6 +5009,11 @@
       XMLConfig.GetValue('EditorOptions/CodeTools/AutoRemoveEmptyMethods', False);
     FCompletionLongLineHintInMSec :=
       XMLConfig.GetValue('EditorOptions/CodeTools/CompletionLongLineHintInMSec', 0);
+
+    fAutoShowCompletion :=
+      XMLConfig.GetValue('EditorOptions/CodeTools/AutoShowCompletion', False);
+    DebugLn('TEditorOptions: Load Editor option AutoShowCompletion %s', [BoolToStr(fAutoShowCompletion, True)]);
+
     FCompletionLongLineHintType := DefaultCompletionLongLineHintType;
     XMLConfig.ReadObject('EditorOptions/CodeTools/CompletionLongLineHintType',
                          Self, Self, 'CompletionLongLineHintType');
@@ -5207,6 +5215,13 @@
     XMLConfig.SetDeleteValue(
       'EditorOptions/CodeTools/CompletionLongLineHintInMSec',
       FCompletionLongLineHintInMSec, 0);
+
+    DebugLn('TEditorOptions: Write Editor option AutoShowCompletion %s', [BoolToStr(fAutoShowCompletion, True)]);
+    XMLConfig.SetDeleteValue(
+      'EditorOptions/CodeTools/AutoShowCompletion',
+      fAutoShowCompletion, False);
+
+
     XMLConfig.WriteObject('EditorOptions/CodeTools/CompletionLongLineHintType',
                          Self, nil, 'CompletionLongLineHintType');
 
Index: ide/frames/editor_codetools_options.lfm
===================================================================
--- ide/frames/editor_codetools_options.lfm	(revision 61726)
+++ ide/frames/editor_codetools_options.lfm	(working copy)
@@ -16,10 +16,10 @@
     AnchorSideLeft.Control = AutoCompletionDelayLabel
     AnchorSideLeft.Side = asrBottom
     AnchorSideTop.Control = AutoCompletionDelayLabel
-    Left = 172
-    Height = 15
-    Top = 156
-    Width = 83
+    Left = 212
+    Height = 17
+    Top = 168
+    Width = 107
     BorderSpacing.Left = 20
     Caption = 'AutoDelayLabel'
     ParentColor = False
@@ -32,7 +32,7 @@
     AnchorSideRight.Side = asrBottom
     Left = 0
     Height = 3
-    Top = 56
+    Top = 60
     Width = 634
     Anchors = [akTop, akLeft, akRight]
     BorderSpacing.Top = 6
@@ -42,9 +42,9 @@
     AnchorSideLeft.Control = Owner
     AnchorSideTop.Control = Owner
     Left = 6
-    Height = 19
+    Height = 21
     Top = 6
-    Width = 210
+    Width = 263
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoRemoveEmptyMethodsOnSave'
@@ -55,9 +55,9 @@
     AnchorSideTop.Control = AutoDisplayFuncProtoCheckBox
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 19
-    Top = 87
-    Width = 198
+    Height = 21
+    Top = 93
+    Width = 245
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoToolTipSymbToolsCheckBox'
@@ -68,9 +68,9 @@
     AnchorSideTop.Control = AutoRemoveEmptyMethodsOnSave
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 19
-    Top = 31
-    Width = 179
+    Height = 21
+    Top = 33
+    Width = 225
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoCompleteBlockCheckBox'
@@ -81,9 +81,9 @@
     AnchorSideTop.Control = AutoToolTipSymbToolsCheckBox
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 19
-    Top = 112
-    Width = 182
+    Height = 21
+    Top = 120
+    Width = 230
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoToolTipExprEvalCheckBox'
@@ -96,8 +96,8 @@
     AnchorSideRight.Control = Owner
     AnchorSideRight.Side = asrBottom
     Left = 6
-    Height = 30
-    Top = 172
+    Height = 39
+    Top = 186
     Width = 622
     Frequency = 250
     Max = 4000
@@ -116,9 +116,9 @@
     AnchorSideTop.Control = DbgToolTipAutoCastClass
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 15
-    Top = 156
-    Width = 146
+    Height = 17
+    Top = 168
+    Width = 186
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoCompletionDelayLabel'
@@ -131,8 +131,8 @@
     AnchorSideRight.Control = Owner
     AnchorSideRight.Side = asrBottom
     Left = 6
-    Height = 30
-    Top = 276
+    Height = 39
+    Top = 312
     Width = 622
     Frequency = 250
     Max = 4000
@@ -150,9 +150,9 @@
     AnchorSideTop.Control = AutoHintDelayTrackBar
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 15
-    Top = 260
-    Width = 148
+    Height = 17
+    Top = 294
+    Width = 188
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'CompletionDropDownLabel'
@@ -162,10 +162,10 @@
     AnchorSideLeft.Control = CompletionDropDownLabel
     AnchorSideLeft.Side = asrBottom
     AnchorSideTop.Control = CompletionDropDownLabel
-    Left = 174
-    Height = 15
-    Top = 260
-    Width = 177
+    Left = 214
+    Height = 17
+    Top = 294
+    Width = 225
     BorderSpacing.Left = 20
     Caption = 'CompletionDropDownDelayLabel'
     ParentColor = False
@@ -177,12 +177,12 @@
     AnchorSideBottom.Control = Owner
     AnchorSideBottom.Side = asrBottom
     Left = 6
-    Height = 23
-    Top = 308
+    Height = 29
+    Top = 353
     Width = 220
     BorderSpacing.Left = 6
     BorderSpacing.Top = 2
-    ItemHeight = 15
+    ItemHeight = 0
     Style = csDropDownList
     TabOrder = 7
   end
@@ -192,9 +192,9 @@
     AnchorSideTop.Control = CompletionDropDownHint
     AnchorSideTop.Side = asrCenter
     Left = 232
-    Height = 15
-    Top = 312
-    Width = 171
+    Height = 17
+    Top = 359
+    Width = 216
     BorderSpacing.Around = 6
     Caption = 'CompletionDropDownHintLabel'
     ParentColor = False
@@ -204,9 +204,9 @@
     AnchorSideTop.Control = AutoToolTipExprEvalCheckBox
     AnchorSideTop.Side = asrBottom
     Left = 26
-    Height = 19
-    Top = 131
-    Width = 159
+    Height = 21
+    Top = 141
+    Width = 198
     BorderSpacing.Left = 20
     Caption = 'DbgToolTipAutoCastClass'
     TabOrder = 8
@@ -215,9 +215,9 @@
     AnchorSideLeft.Control = Owner
     AnchorSideTop.Control = ToolTipBevel
     Left = 6
-    Height = 19
-    Top = 62
-    Width = 191
+    Height = 21
+    Top = 66
+    Width = 241
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoDisplayFuncProtoCheckBox'
@@ -228,9 +228,9 @@
     AnchorSideTop.Control = AutoCompletionDelayTrackBar
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 15
-    Top = 208
-    Width = 106
+    Height = 17
+    Top = 231
+    Width = 135
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoHintDelayLabel'
@@ -243,8 +243,8 @@
     AnchorSideRight.Control = Owner
     AnchorSideRight.Side = asrBottom
     Left = 6
-    Height = 30
-    Top = 224
+    Height = 39
+    Top = 249
     Width = 622
     Frequency = 250
     Max = 4000
@@ -262,12 +262,25 @@
     AnchorSideLeft.Control = AutoHintDelayLabel
     AnchorSideLeft.Side = asrBottom
     AnchorSideTop.Control = AutoHintDelayLabel
-    Left = 132
-    Height = 15
-    Top = 208
-    Width = 92
+    Left = 161
+    Height = 17
+    Top = 231
+    Width = 117
     BorderSpacing.Left = 20
     Caption = 'AutoHDelayLabel'
     ParentColor = False
   end
+  object AutoShowCompletionDropDown: TCheckBox
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = CompletionDropDownHint
+    AnchorSideTop.Side = asrBottom
+    Left = 6
+    Height = 21
+    Top = 388
+    Width = 243
+    BorderSpacing.Left = 6
+    BorderSpacing.Top = 6
+    Caption = 'AutoShowCompletionDropDown'
+    TabOrder = 10
+  end
 end
Index: ide/frames/editor_codetools_options.pas
===================================================================
--- ide/frames/editor_codetools_options.pas	(revision 61726)
+++ ide/frames/editor_codetools_options.pas	(working copy)
@@ -45,6 +45,8 @@
     AutoHintDelayTrackBar: TTrackBar;
     AutoDisplayFuncProtoCheckBox: TCheckBox;
     AutoHintDelayLabel: TLabel;
+    AutoRemoveEmptyMethodsOnSave1: TCheckBox;
+    AutoShowCompletionDropDown: TCheckBox;
     DbgToolTipAutoCastClass: TCheckBox;
     CompletionDropDownHintLabel: TLabel;
     CompletionDropDownHint: TComboBox;
@@ -105,6 +107,8 @@
   CompletionDropDownHint.Items.Add(lisCompletionLongLineHintTypeRightOnly);
   CompletionDropDownHint.Items.Add(lisCompletionLongLineHintTypeLittleLeft);
   CompletionDropDownHint.Items.Add(lisCompletionLongLineHintTypeFullLeft);
+
+  AutoShowCompletionDropDown.Caption := lisAutoShowCompletion;
 end;
 
 procedure TEditorCodetoolsOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
@@ -123,6 +127,7 @@
     CompletionDropDownHintTrackBar.Position := CompletionLongLineHintInMSec;
     CompletionDropDownHint.ItemIndex := ord(CompletionLongLineHintType);
 
+    AutoShowCompletionDropDown.Checked := AutoShowCompletion;
   end;
   AutoCompletionDelayTrackBarChange(nil);
 end;
@@ -142,7 +147,7 @@
 
     CompletionLongLineHintInMSec := CompletionDropDownHintTrackBar.Position;
     CompletionLongLineHintType := TSynCompletionLongHintType(CompletionDropDownHint.ItemIndex);
-
+    AutoShowCompletion := AutoShowCompletionDropDown.Checked;
   end;
 end;
 
Index: ide/lazarusidestrconsts.pas
===================================================================
--- ide/lazarusidestrconsts.pas	(revision 61726)
+++ ide/lazarusidestrconsts.pas	(working copy)
@@ -2040,6 +2040,7 @@
   lisDelayForCompletionBox = 'Delay for completion box';
   lisDelayForHints = 'Delay for hints';
   lisDelayForCompletionLongLineHint = 'Delay for long line hints in completion box';
+  lisAutoShowCompletion = 'Automatic code completion';
   lisCompletionLongLineHintType = 'Show long line hints';
   lisCompletionLongLineHintTypeNone = 'Never';
   lisCompletionLongLineHintTypeRightOnly = 'Extend right only';
Index: ide/sourceeditor.pp
===================================================================
--- ide/sourceeditor.pp	(revision 61726)
+++ ide/sourceeditor.pp	(working copy)
@@ -5743,6 +5743,11 @@
     OnKeyDown(Sender, Key, Shift);
 
   IDECommandList.PostponeUpdateEvents;
+
+  // very crude invokaion of identifier completion
+  if EditorOpts.AutoShowCompletion then
+    if (chr(Key) in ['a'..'z', 'A'..'Z']) and (Shift <> [ssCtrl]) and (Shift <> [ssAlt]) and (Shift <> [ssAltGr]) then
+      StartIdentCompletionBox(false,false);
 end;
 
 procedure TSourceEditor.EditorKeyUp(Sender: TObject; var Key: Word;
-- 
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to