change code hints behavior lazarus / 9-Editor ---------------------------------------------------------------------- dzzie · 2014-03-17 12:13 Hi, Long time programmer, but new to pascal and Lazarus. VERY impressed with the project ! I have enabled the code hints to show me the function prototypes when I mouse over a function name. I would like to change its behavior to instead show when ( is pressed, and hide when the matching ) is entered. I have been digging through the IDE source and think its in TSourceNotebook.ActivateHint/HideHint etc.. Before I really get into it, I figured I should ask if anyone else has a patch for this yet? I also saw TSourceNotebook.HideHintTimer      // TODO: introduce property, to indicate if hint is interactive Which may indicate this feature is planned? worst case scenario, I will set a long delay for it to show, and disable it from hiding until i hit escape. messy but simple... or maybe a pin it button on the hint window (with hotkey to set) Thanks for any thoughts. update: By chance I just stumbled on another post where they mention pressing ctrl+shift+space while between the () of a function to bring up a pinned prototype window. This works for me. ---------------------------------------------------------------------- Martin_fr · 2014-03-17 13:32 I am not sure what you mean by Quotehow when ( is pressed, and hide when the matching ) is entered. I will need to look at the source myself, in order to remember the details. But yes SourceEditor.pp is the right place for the hints show/hide behaviour (the content comes from codetools). A few notes: There are different hints. I assume you speak about the simple mouse-over hint? (There also is a hint, when pressing shift-ctrl-space, while in function arguments) The just mouse-over hint comes in 2 flavours. That is also important to know when trying to understand the code. If you install the package IpproTurboDsgn (or similar) then it changes. The hint will keep open, if the mouse moves towards/over it, but not if the mouse moves away. You can copy and paste from the hint, and follow links that are inside the hint. ---------------------------------------------------------------------- dzzie · 2014-03-17 15:45 having the shift-ctrl-space hint show automatically when I started to enter arguments is what I was really looking for. At time of posting though I only knew of the mouse over hints though. I will check out the package you mention too thanks. ---------------------------------------------------------------------- Martin_fr · 2014-03-17 17:58 ok, you are looking for ecShowCodeContext (can be found in ide\keymapping.pp, if you know the default keys "space" +shift/ctrl) That is triggered for the key combo. You need to find it in SourceEditor. All the below is in SourceEditor --- Then you need to add code to the key handlers for ecChar for "(", ")" and in TSourceEditor.EditorStatusChanged( you cant check, if the caret moved, and if it did, then check, if it moved into a () block. ------------------------ If you implement that with a option in the IDE options, then it cat be added to the main distribution. ---------------------------------------------------------------------- dzzie · 2014-03-18 01:15 ok I have the basic behavior working now. thanks for the info. I played around with putting the code in severla different places, I ended up having to implement the EditorKeyUp event.  KeyDown, was only working if I entered two open parenthesis, the first one must not have been in the buffer that StartShowCodeContext checks yet. Setting just the command to the ecShowCodeContext same effect. The StartShowCodeContext is pretty smart about knowing when to show, so I didnt have to track open/close parenthesis state. Hopefully I am not over-relying on its kindness. It also handles the case where you call another function nested within a functions argument list, switching over to the nested function on new open parenthesis, hiding when closing out, then reopening again for the parent function when you hit comma to goto next argument. Its also nice to handle the comma as a way to just quickly call up the context help when you click into a function. same behavior as vb6. I think VC++ only triggers on open parenthesis which always annoyed me. I will work on the option setting tomorrow. Code: [Select]procedure TSourceEditor.EditorKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin    // StartShowCodeContext has no effect if not within a valid context..    // this must be onKeyup to chars exist in buffer    if (key = 57) and (Shift = [ssShift]) then     //handle possible start of function argument list       SourceNotebook.StartShowCodeContext(true);    if key = 188 then       SourceNotebook.StartShowCodeContext(true);  //handle comma in argument list end; I may have also found a bug with the linker not complaining if its not able to write the exe file. I thought I had changed output file path from running IDE, but it was still trying to compile to same path, so exe was not updating, debugger still launched but symbols no longer matched exe being debugged, lead to very confusing results with debugger showing wrong lines for conditions clearly not met. at least thats the best sense I can make of the condition. I will attach a patch file when complete. ---------------------------------------------------------------------- Martin_fr · 2014-03-18 01:51 Quoteimplement the EditorKeyUp event.  KeyDown, was only working if I entered two open parenthesis You should use the command-handlers. This one is run after the key was processed. Code: [Select]procedure TSourceEditor.UserCommandProcessed(Sender: TObject;   var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer); You check in the "ecChar" section. Code: [Select]The StartShowCodeContext is pretty smart about knowing when to show, so I didnt have to track open/close parenthesis state. Hopefully I am not over-relying on its kindness. Running it always, will be fine on many modern PC, but probably (not verified) uses a lot of extra CPU. Running it always can drain a laptops battery. You may also notice the effect (maybe, maybe not) if you have done a bigger edit and then hold ctrl-z pressed, to undo many steps (disable group undo, so each keystroke is undone on its own) QuoteCode: [Select] (key = 57) and (Shift = [ssShift]) That does not work with local keyboards in some languages. But using ecChar, you can compare directly too '('. Though ecChar can also be triggered by the macro recorder.Need to see how that can be best detected. You could also check, if the highlighter for the file pas: Code: [Select](SyntaxHighlighterType in [lshFreePascal,lshDelphi])) -------------- Personally, I don't see, why use the comm, to open it. Then you can also use shift-ctrl-space. But what might be interesting is: *IF* the hint is open, and the the cursor keys (ecLeft/ecRight) traverse over a ( or ) then it could change. ---------------------------------------------------------------------- dzzie · 2014-03-18 04:07 ok I switched it over to UserCommandProcessed and implemented the option. There is some extra noise in editor_codetools_options.lfm section, I think the editor tweaked it automatically when I opened it maybe a new version IDE thing? Main reason for the comma trigger is so that it can recover from nested calls A( arg0, B(arg1, arg2,) , arg3) --|----------|---------------|   A            B                  A The StartShowCodeContext must track caret because it does auto hide if arrow keys take cursor outside of bounds of argument list.                                                                    Also I was working off of the stable 1.2.0, not the nightly. Hope thats ok this is my first public patch submission. I can redo if not. Patch is quite small. Knowing where to put the code was the hard part. Thanks for all the help! edit: I realized what you mean about arrow keys now, I checked VB6, they dont track arrows, but do also track spaces, so prototype will show if you press space or comma inside argument list. I dont think I will add them as spaces and arrows are extremely common key presses. I also updated patch this morning I forgot to set caption from resource string. ---------------------------------------------------------------------- Martin_fr · 2014-03-18 11:36 Looks ok at first sight. I will go through it and apply it. If you are not yet in the contributors list, with which name would you like to be entered? --- For future ref: Best to post patches on Mantis. that is the preferred way. ---------------------------------------------------------------------- dzzie · 2014-03-18 12:37 I am not on the list yet, name is David Zimmer.  Its really great having the whole language and IDE open source and be able to contribute ideas and see how it all works. The way MS handled vb6 -> .NET left a really bad taste in my mouth, as has Windows 8.  I will look up mantis, I look forward to helping out where I can. -Dave ---------------------------------------------------------------------- Martin_fr · 2014-03-18 12:51 Committed to trunk. I fixed the form layout. All elements must be anchored. Your placement did overlap the elements on my display. ---------------------------------------------------------------------- dzzie · 2014-03-18 13:07 perfect thanks ---------------------------------------------------------------------- Martin_fr · 2014-04-15 14:54 http://forum.lazarus.freepascal.org/index.php?topic=24263.new#new Any ideas? Can you look at suppressing the error behaviour?