[forget it] A request or maybe its already there? lazarus / 9-Editor ---------------------------------------------------------------------- jamie · 2024-10-29 00:40 Feature request or show me where it is?  At times I am deep in a long list of code in a procedure where the VAR section is out of site! I need to add a variable to my local list of that procedure as I go along but it requires me to scroll up and set it or use the bookmarks so I can return.  The auto-complete code to do this just does not seem to work well in- place so I have a much better idea that would allow for one to view what is currently listed in the VAR section and add a new variable without leaving the location of my current editing spot.   It would be nice to use a Hot-Key or control sequence to popup a dial window with the current list of the variables in that block, I suppose we could have tree structure to show the global variable section of the unit, too, or even maybe some local procedures to that block.   I use Code-Explorer but that does not cut the mustard as it does not allow you to insert a new variable on the fly. Also, it does not really give you a good view of your variables.  This needs to show the VAR section block and allow you to insert a new variable and check against duplicates etc.  and when closing the dialog could even elect to auto-insert that new variable in-place where you were! How a bout it? ---------------------------------------------------------------------- Josh · 2024-10-29 00:52 Hi If you put a valid statement with new var name ie fred:='gt'; place the cursor on fred, right click->refactoring->declare variable, it then asks where you want to declare it and its type Alt-O R D if its already defined you get a message ---------------------------------------------------------------------- jamie · 2024-10-29 01:16 Ok, it would be nice to also see the current list of variables there, too. let's see, create a variable that may or may not exist, who knows, right click, then right click again, hum... I still would like to see the whole list there and so I can simply insert as if it was a mini editor. I'll take your suggestions under advisement in any case! My Right-Click+Refactoring does not show an option to declare a variable.. Sorry. I still want the to popup window in place that shows the current local list and able to insert what I want. ---------------------------------------------------------------------- Josh · 2024-10-29 01:35 hi if i right click the fred part, refactoring, declare variable or ALT+O then press R then press D if anchordocking then you can see a list of vars in the procedure on the right in code explorer. if not anchor docking open code explorer ---------------------------------------------------------------------- 440bx · 2024-10-29 01:38 I often run into the problem you described... here is how I solve it... First, I often set a bookmark to the beginning of the "var" section. Second and, most important, I usually have 2 editor windows open side by side.  The left side shows the code part, the right side shows the "var" part.  That way, I only have to switch from one window to the other to declare the variable and, that gives you a full page of already declared variables.  (see the attachement.) Also, I do the same using the editor I use when I am really coding (instead of just making minor adjustments - usually when testing/debugging - which is when I use the Lazarus editor.)  Effectively, I always 2 editors running with side by side windows showing different parts of a function/procedures.  The main editor usually has several dozen windows open, some belonging to the project I'm working on and many other windows from other projects that I copy/paste code from. I find having a file showing in two different editing windows to be the most convenient solution because the text isn't jumping around to another location.  Everything stays put, which makes it much easier to deal with. HTH. ---------------------------------------------------------------------- LV · 2024-10-29 12:03 I’d like to share my decision. It may seem naive, but it’s convenient for me. I have code blocks containing a long list of variables, which I transferred to *.inc files included using the directive {$I somevarlist.inc}. The source code editor features tabs for the module I'm working on and tabs for the *.Inc files. With just one click of the mouse, I can easily switch between the tabs! Quote from: jamie on October 29, 2024, 02:16:40 amI still want the to popup window in place that shows the current local list and able to insert what I want. this is also possible ---------------------------------------------------------------------- n7800 · 2024-10-31 20:39 Just to be clear, there are some atypical cases: there can be several "var" sectionssections can be separated by large nested proceduresthey can be very large, especially if they contain array initializationthey can contain single-line comments and even multi-line ones ---------------------------------------------------------------------- n7800 · 2024-10-31 20:44 Quote from: jamie on October 29, 2024, 02:16:40 amMy Right- Click+Refactoring does not show an option to declare a variable.. You need to install the "Cody" package for it. ---------------------------------------------------------------------- 440bx · 2024-10-31 20:45 @n7800, All of those are possibilities that are encountered sooner or later.  I find that multiple "var" sections and multi-line comments in "var" sections are fairly common (they are common in my code.) That's why I like having a second window and using bookmarks.  That way all the movement occurs in that secondary window and not in the main window where I am editing code. ---------------------------------------------------------------------- n7800 · 2024-10-31 20:57 By the way, there is a similar function "Source > Complete Code" [Ctrl+Shift+C], which can also create a declaration for a variable. It does this without asking for the type and location, but this is often not needed, so it can be even more convenient. There is also a function "Search > Find start of Code Block" [Ctrl+Q, M]. It is enough to press several times to end up at the main "begin" at the beginning of the function, before which the "var" section is usually located. To go back, you can use the cursor history ("Jump back") by pressing [Alt+Left] several times. ---------------------------------------------------------------------- n7800 · 2024-10-31 21:11 I think the best option would be a keyboard shortcut for quickly switching to the "var" section of the current procedure (or switching between them, if there are several). Unlike dialog/popup windows, it allows you to see the original variables (with comments), edit them, continue using any shortcuts and feature of the editor - completion, scrolling, folding, etc. After editing, you can easily go back using "Jump back" [Alt+Left]. This command can even be placed in the editor toolbar, for quick access with the mouse. However, the question arises - is it worth creating the same commands for quick transition to other sections (type, const)? ---------------------------------------------------------------------- n7800 · 2024-10-31 21:11 By the way, can I ask the author of the topic to choose a better title for the topic? )) For example: "Feature request: Quick way to declare a variable" or something like that... ---------------------------------------------------------------------- Fibonacci · 2024-10-31 21:51 Ultimate solution/idea: inline variables + shortcut to move them to the var section At least Refactoring -> Declare variable should detect the variable name in the current line, without having to place the cursor on the specific word you want as a variable name ---------------------------------------------------------------------- mas steindorff · 2024-10-31 22:33 I tend to always use the same Var name for locals so I have the basics covered by memory. I is an integer, str:string, ftmp :double; ... Then when I need to expand , I add a "lv_" to the name so that code completion can kick in.  When the Var/Const/types are defined outside of the function, I use the two window approach. ---------------------------------------------------------------------- Fibonacci · 2024-10-31 22:42 Quote from: Fibonacci on October 31, 2024, 10:51:22 pmAt least Refactoring -> Declare variable should detect the variable name in the current line, without having to place the cursor on the specific word you want as a variable name How about that? Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i diff --git a/components/codetools/ide/declarevardlg.pas b/components/codetools/ide/declarevardlg.pasindex 326c7cbc08..103604e36a 100644--- a/components/codetools/ide/declarevardlg.pas+++ b/components/codetools/ide/declarevardlg.pas@@ -137,6 +137,7 @@ var   IsKeyword: boolean;   NewExprType: TExpressionType;   IsSubIdentifier: boolean;+  x, oldx: integer; begin   Result:=false;   NewType:='';@@ -147,6 +148,22 @@ begin   ExistingDefinition:=CleanFindContext;   PossibleContexts:=nil; +  oldx := -1;+  try+  x := Pos(':=', SourceEditorManagerIntf.ActiveEditor.CurrentLineText)-1;+  while x > 0 do begin+    // find first non-space+    if SourceEditorManagerIntf.ActiveEditor.CurrentLineText[x] <> ' ' then break;+    dec(x);+  end;+  inc(x);+  // found var name, move cursor onto it+  if x >= 0 then begin+    // save old X and return here later+    oldx := SourceEditorManagerIntf.ActiveEditor.CursorTextXY.X;+    SourceEditorManagerIntf.ActiveEditor.CursorTextXY := TPoint.Create(x, SourceEditorManagerIntf.ActiveEditor.CursorTextXY.Y);+  end;+   if (Pa rseTilCursor(Tool,CleanPos,CursorNode,Handled,true,@CodePos)<>cupeSucc ess)   and not Handled then begin     ErrorNotAtAnIdentifier;@@ -193,6 +210,10 @@ begin         ErrorNotAtAnIdentifier;     end;   end;+  finally+    if oldx <> -1 then+      SourceEditorManagerIntf.ActiveEditor.CursorTextXY := TPoint.Create(oldx, SourceEditorManagerIntf.ActiveEditor.CursorTextXY.Y);+  end; end;  { TCodyClipboardDeclareVar } ---------------------------------------------------------------------- mas steindorff · 2024-10-31 22:51 what key strokes are you using? alt O,R,D do not work with my v3.4 ---------------------------------------------------------------------- Fibonacci · 2024-10-31 22:54 Quote from: mas steindorff on October 31, 2024, 11:51:41 pmwhat key strokes are you using? alt O,R,D do not work with my v3.4 I use Ctrl+U ---------------------------------------------------------------------- mas steindorff · 2024-10-31 23:07 I see that ctrl +U is used for indents stuff.  I'll need to poke around a bit to find this in my windows version of the IDE. thanks ---------------------------------------------------------------------- Fibonacci · 2024-10-31 23:09 Quote from: mas steindorff on November 01, 2024, 12:07:29 amI see that ctrl +U is used for indents stuff.  I'll need to poke around a bit to find this in my windows version of the IDE. thanks Make a backup and override it all, you dont use 99% of the hotkeys ---------------------------------------------------------------------- n7800 · 2024-11-01 03:50 Quote from: Fibonacci on October 31, 2024, 11:42:20 pmQuote from: Fibonacci on October 31, 2024, 10:51:22 pmAt least Refactoring -> Declare variable should detect the variable name in the current line, without having to place the cursor on the specific word you want as a variable name How about that? ... Congratulations, you invented [Ctrl+Shift+C] )))) Unfortunately, programming languages ​​are too complex for such simple parsing, so you need to use CodeTools to implement it correctly. Your patch in this example it tries to create a variable declaration from a string constant: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  func('i := 123'); s := 'text';end;  and in this it does not work at all: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  func('i :=:= 123'); s := 'text';end;  EDITED: Fixed typo. ---------------------------------------------------------------------- Fibonacci · 2024-11-01 03:56 Quote from: n7800 on November 01, 2024, 04:50:17 amCongratulations, you invented [Ctrl+Shift+C] )))) Wow it does work Quote from: n7800 on November 01, 2024, 04:50:17 amUnfortunately, programming languages ​​are too complex for such simple parsing Obviously. It was quick test-fix for personal use. ---------------------------------------------------------------------- n7800 · 2024-11-01 07:01 Quote from: Fibonacci on November 01, 2024, 04:56:49 amObviously. It was quick test-fix for personal use. Sure, I understand )) However, such an addition to "Declare variable" would really be nice. Maybe someone will look at the code [Ctrl+Shift+C] and pull out this part from there. ---------------------------------------------------------------------- LV · 2024-11-01 14:37 A straightforward way to do what the OP wants is to use Jump History (Ctrl+Alt+J). With just one click in the Jump History window, we can go from declaring a variable to using it in a procedure far down in the code and back again. Variables can be added or removed. Updated: Based on my research and tests, @440bx suggests the best approach. ---------------------------------------------------------------------- n7800 · 2024-11-02 01:08 Quote from: LV on November 01, 2024, 03:37:56 pmA straightforward way to do what the OP wants is to use Jump History (Ctrl+Alt+J). With just one click in the Jump History window, we can go from declaring a variable to using it in a procedure far down in the code and back again. Variables can be added or removed. Updated: Based on my research and tests, @440bx suggests the best approach. I already mentioned the jump history feature [Alt+Left]: Quote from: n7800 on October 31, 2024, 09:57:08 pmThere is also a function "Search > Find start of Code Block" [Ctrl+Q, M]. It is enough to press several times to end up at the main "begin" at the beginning of the function, before which the "var" section is usually located. To go back, you can use the cursor history ("Jump back") by pressing [Alt+Left] several times. ---------------------------------------------------------------------- LV · 2024-11-02 07:05 Quote from: n7800 on November 02, 2024, 02:08:59 amQuote from: LV on November 01, 2024, 03:37:56 pmA straightforward way to do what the OP wants is to use Jump History (Ctrl+Alt+J). With just one click in the Jump History window, we can go from declaring a variable to using it in a procedure far down in the code and back again. Variables can be added or removed. Updated: Based on my research and tests, @440bx suggests the best approach. I already mentioned the jump history feature [Alt+Left]: Quote from: n7800 on October 31, 2024, 09:57:08 pmThere is also a function "Search > Find start of Code Block" [Ctrl+Q, M]. It is enough to press several times to end up at the main "begin" at the beginning of the function, before which the "var" section is usually located. To go back, you can use the cursor history ("Jump back") by pressing [Alt+Left] several times. OK, You have made 33 jumps so far. To return to step 23, you need to press (Alt+Left) 10 times. Wouldn’t it be easier to open the jump history window by pressing (Ctrl+Alt+J) and selecting the desired jump with just one click? However, as mentioned earlier, Lazarus provides several options for the user. ---------------------------------------------------------------------- n7800 · 2024-11-02 12:31 Well, after a large number of jumps, it is easier to open the unit again ([Ctrl+Tab] or [Alt+F12]) and go to the procedure [Alt+G]... Of course, everyone chooses for themselves. And for me, pressing [Alt+Left] 10 times (or pressing and holding) is much easier than opening a window, picking up the mouse, scrolling the window, looking for the necessary line, clicking the mouse and putting my hands on the keyboard again. I generally do not like taking my hands off the keyboard )) ---------------------------------------------------------------------- jamie · 2024-11-02 17:13 I would be happy if the CODE EXPLORER would show the local variables, which currently does not seem to work that way.  And while we are using the code explorer, I could insert the variable there and then? A note on using the shift+Ctrl+C, that only works with very simple types, if I want to locally declare a RECORD type I know exists or a non-Standard type like a BYTE, WORD etc. It does not seem to have a way to detect the type I want without issues. ---------------------------------------------------------------------- n7800 · 2024-11-02 17:46 Quote from: jamie on November 02, 2024, 06:13:21 pmI would be happy if the CODE EXPLORER would show the local variables, which currently does not seem to work that way.  And while we are using the code explorer, I could insert the variable there and then? A note on using the shift+Ctrl+C, that only works with very simple types, if I want to locally declare a RECORD type I know exists or a non-Standard type like a BYTE, WORD etc. It does not seem to have a way to detect the type I want without issues. Yes, telepathic abilities are not included there, that's why Refactoring > Declare variable exists )) And I think that this window is more convenient than pasting through Code Explorer (if it were made), especially if you assign a keyboard shortcut to it. ---------------------------------------------------------------------- jamie · 2024-11-04 23:19 Quote from: n7800 on November 02, 2024, 06:46:29 pmQuote from: jamie on November 02, 2024, 06:13:21 pmI would be happy if the CODE EXPLORER would show the local variables, which currently does not seem to work that way.  And while we are using the code explorer, I could insert the variable there and then? A note on using the shift+Ctrl+C, that only works with very simple types, if I want to locally declare a RECORD type I know exists or a non-Standard type like a BYTE, WORD etc. It does not seem to have a way to detect the type I want without issues. Yes, telepathic abilities are not included there, that's why Refactoring > Declare variable exists )) And I think that this window is more convenient than pasting through Code Explorer (if it were made), especially if you assign a keyboard shortcut to it. I'll come up with something myself.  Don't worry, I won't let the door hit me in the xxxx on the way out.