Insert AHK Command/Function Parameters (with Search/Auto-Complete)

Discuss features, issues, about Editors for AHK
User avatar
boiler
Posts: 2351
Joined: 21 Dec 2014, 02:44

Insert AHK Command/Function Parameters (with Search/Auto-Complete)

06 May 2017, 11:43

Intro:
This tool provides automatic insertion of the parameter definitions for AutoHotkey's commands, functions, and directives (will be referred to simply as commands for brevity).
  • It will auto-complete the command name using either of two incremental search modes: match from the beginning of the command name or match anywhere within it.
  • A list of available parameter definitions will be displayed. It will insert the parameter list for that command, allowing you to select among the alternatives if multiple are available.
  • It currently works with Notepad++, SciTE4AutoHotkey, AHK Studio, and AutoGUI. It should work with any editor that accepts pasted text and returns caret positions by adding the editor's WinTitle to the ahk_group.
I'd like to acknowledge Helgef's excellent AHK Hotstrings script which provides similar functionality. This tool is presented as an alternative or an addition to it. I can certainly see both being used as they each have their strengths, and either one can be invoked when desired. Many thanks to jeeswg and Helgef for their development of the command/parameters list, which I've made use of here.

I developed this tool so that it would include auto-complete in a parameter insertion tool (I'm too lazy to type long command names) and because the hotstrings-based tool works very slowly in the main place that I use it: in Notepad++ with auto-complete enabled. This is because a hotstring (and Send command) is basically typing out the text, so Notepad++'s auto-complete tries to suggest words for it as it types, causing it to operate very slowly. This tool pastes the text into your editor, making it immediate and eliminating this issue.

Usage:
  • Press CapsLock to invoke the command/function search, which will match from the start of the names:
    Image
  • Alternatively, press Shift + CapsLock so that command/function search will match anywhere:
    Image
    (You can of course change CapsLock and +CapsLock to any other hotkeys you wish.)
  • Use up/down arrow keys to navigate the matched entries or keep typing until the desired command is highlighted.
  • Press Enter to insert the command function name and to display its parameter definition(s).
  • If there is more than one parameter definition available, use the up/down arrow keys to select and press Enter to insert the parameters.
  • Press Escape at any time to exit without inserting the selection.
Download:
Insert AHK Parameters.ahk
(19.32 KiB) Downloaded 142 times
Helgef
Posts: 2674
Joined: 17 Jul 2016, 01:02
Contact:

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

06 May 2017, 17:43

Very nice! :bravo:
The editbox solution is really smart I think, it solves all problems of tracking what is being typed.

I have worked on a similar script, but that project has spawned so many sidetracks that I'm not sure where it is going now :lol:

Anyways, great job and thanks for sharing.
User avatar
boiler
Posts: 2351
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

07 May 2017, 10:44

Thanks! Glad you like it. I know the feeling about the sidetracks. :D

One of the throw-ins I added was the alternate incremental search mode where it matches anywhere, but I think maybe it should be the primary mode under the main hotkey. Sometimes I remember part of a command's name but not how it starts, like the various trim commands/functions (AutoTrim, LTrim, RTrim StringTrimLeft, etc.).
Helgef
Posts: 2674
Joined: 17 Jul 2016, 01:02
Contact:

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

07 May 2017, 11:29

Yes match anywhere is very nice.
It is very easy to modify and add to this script. Five minute effort, here is all gdip_ functions (currently in my user lib)

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus


Paste here:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


The list was generated with this script Insert User Function Definitions -- for Notepad++, specifically see my post :D

Any thought on using the function script for auto-adding functions in current script or something like that? :geek:

Cheers.
User avatar
boiler
Posts: 2351
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

08 May 2017, 20:46

That's a nice addition and a good point in general that anyone can add any library functions to this that they want using your technique. :thumbup:
A couple notes to others looking to do the same:
  • It is important to put the text for your additions in its own continuation section as Helgef did, which is to define a variable whose contents are between its own pair parentheses, then concatenate it to the CommandText variable. This is because there is a limit to how many characters a single continuation section can contain, and the main command/function/directive list is pushing that limit. Per the AHK documentation: "A continuation section cannot produce a line whose total length is greater than 16,383 characters."
  • If the text of what you add includes a ";" character, it will cause a minor problem because I chose that character as a delimiter in the list between the name of the command and its parameters.
Helgef wrote:Any thought on using the function script for auto-adding functions in current script or something like that?
This is a good idea, and I have been thinking it would be nice to combine the two, but I haven't yet put any effort into it yet. The one issue I thought about is that it would only work with editors that show the full path in the window title as Notepad++ so it can find the #Include files, but that's okay. It would be a nice project for a rainy day...
User avatar
nnnik
Posts: 2503
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

09 May 2017, 01:59

I think Scite4AutoHotkey and AHKStudio both offer a COMObject to get that sort of data.
Recommends AHK Studio
Guest

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

09 May 2017, 03:01

Useful - Some thoughts:

* CommandText should be separated from the script in its own file(folder?). That way you can modify the script more easily and exchange update without the need to mess with it.

* You can have multiple CommandTexts files, makes it easy to update the externally and reload the script (external script can reload your script to update it)

* Look at Goto/TillaGoto for some code to "find" functions in the current edited file so they can be added dynamically or on "user activated scan" https://github.com/ahkscript/awesome-AutoHotkey/#others (could include a "scan project" so it scans all #includes)

* Also here https://github.com/ahkscript/awesome-AutoHotkey/#others is "quick help in any editor" which could be integrated.

:)
User avatar
boiler
Posts: 2351
Joined: 21 Dec 2014, 02:44

Re: Insert AHK Command/Function Parameters (with Search/Auto-Complete)

09 May 2017, 19:31

@nnik: That should come in handy. Thanks for the info.

@Guest:
I considered whether to put the CommandText data in the script file, and I ended up thinking that a single file might make it more convenient for people. I typically lean towards what you recommended. And your suggestion about them possibly being in a separate folder might be better because then it could read any and all files in that folder, making it easier to manage adding library function definitions as Helgef did. Sounds like a worthwhile change in a future update.

I did briefly look at GotoTilla and TillaGoto but didn't end up reverse engineering their code for that part (although I did look at what they did for their combined edit box/list box). I may revisit them if I do tackle the task of integrating user functions into this, although I may just use what I already do in my other script for that at first since I primarily use Notepad++ at the moment.

Thanks for the link to the context-sensitive help. I have been using Rajat's version of that. I can see how something like that might be worthwhile to tie into this, although I find it works fine as a separate script. I suppose the main reason to do it is to reduce the number of scripts you have running.

Return to “Editors”

Who is online

Users browsing this forum: No registered users and 1 guest