Library Functions with "ahk2" Extension

Discuss the future of the AutoHotkey language
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Library Functions with "ahk2" Extension

Post by FanaticGuru » 20 Nov 2018, 20:05

I just started using AutoHotkey v2. I plan to continue using both v1 and v2 for quite awhile as I slowly transition. I have both v1 and v2 installed and I set things up to use the ahk2 extension for the v2 scripts.

Got it all working with editing the register so that ahk2 scripts run properly and Windows views it as a valid extension. Got SciTE4AutoHotkey setup to work with both ahk and ahk2 script extensions and know how to run scripts properly when I hit the run button. All that went good and everything is working pretty well with running v1 and v2 side-by-side.

But I hit a snag with library functions. Is there a way to get library functions to work with the ahk2 extension?

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
JoeWinograd
Posts: 2182
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Library Functions with "ahk2" Extension

Post by JoeWinograd » 21 Nov 2018, 11:55

Hi FG,
I also recently started using V2 and want to pass along a suggestion to you, which is...don't use ahk2 as the file type. The first thing I tried was ahkv2...had a problem. Next thing I tried was ahk2...had the same problem. I posted this question on it:
https://autohotkey.com/boards/viewtopic.php?f=5&t=53788

Then this bug report on it:
https://autohotkey.com/boards/viewtopic ... 14&t=53840

As you can see, the problem is due to the 8.3 short file name. I change my AHK V2 file type to ah2 and haven't had a problem since. I don't know if this will affect your work with Library Fucntions, but wanted to make you aware of the issue. Regards, Joe
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Library Functions with "ahk2" Extension

Post by nnnik » 21 Nov 2018, 12:03

Maybe it woduld be good if we can select the extension ahk registers for itself when we install the program.
I would also reccomend the AHK-EXE-SWAPPER and just use .ahk for all ahk files.
Recommends AHK Studio
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Library Functions with "ahk2" Extension

Post by FanaticGuru » 21 Nov 2018, 14:22

nnnik wrote:
21 Nov 2018, 12:03
Maybe it woduld be good if we can select the extension ahk registers for itself when we install the program.
I would also reccomend the AHK-EXE-SWAPPER and just use .ahk for all ahk files.
Yea, I thought it would be nice if you could set the extension some way even if within the script with something like A_Extension or #Extension.

I would not mind setting the extension in the top of all my v2 scripts so the script would know to use "ahk2" or whatever in things like librarys where an extension is not used and the script is assuming the extension.

My understanding is that AHK-EXE-SWAPPER does not really allow you to run both v1 and v2 at the same time. It just allows you to swap your installation back and forth.

The way I have it is with two installs:
C:\Program Files\AutoHotkey
C:\Program Files\AutoHotkeyv2

Then I used RegEdit to associate "ahk" and "ahk2" to the appropriate AutoHotkey.exe in the appropriate folder. That part went pretty smooth and I now have no problem running v1 and v2 scripts at the same time. They also show up nicely in File Explorer with "AutoHotkey Script" and "AutoHotkey Script v2" in the Type column. They are handled basically like two totally independent applications.

I have SciTE4AutoHotkey working with both in a basic way but it is a work in progress. I did not use the stuff already build in related to v2. I just created a new "language" and copied the v1 files to the new language and began tweaked it for v2. So the highlighting is not specific to v2 and the intellisense completion all of that is not completely v2 appropriate. But it loads, saves, and runs v1 and v2 scripts. I took sorta the same approach with SciTE as I did with the install of treating v2 as a totally different application. I barely understand how all the setting files work in SciTE so this barely works. It doesn't help that I have modified SciTE with stuff from Lexikos that I only partially understand. I plan to study up and get a better understanding of SciTE to work better with v2 as a separate language.

If anyone has setup SciTE4AutoHotkey to work nicely with both v1 and v2 at the same time a link to your files would be greatly appreciated. I basically want to be able to have a v1 script on one tab and a v2 script in another tab and have SciTE behave appropriately with both.

Using Windows 10.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
MrDoge
Posts: 151
Joined: 27 Apr 2020, 21:29

Re: Library Functions with "ahk2" Extension

Post by MrDoge » 28 Jan 2021, 18:45

Then I used RegEdit to associate "ahk" and "ahk2" to the appropriate AutoHotkey.exe in the appropriate folder. That part went pretty smooth and I now have no problem running v1 and v2 scripts at the same time.
@FanaticGuru , did you get it to work ?
Is there a way to get library functions to work with the ahk2 extension?

Feature Request: for Libraries of Functions: look for the same extension as the main script.
if script name is "script.ahk2" search in "*.ahk2" for Libraries of Functions"
if script name is "anyName.ah2" search in "*.ah2" for Libraries of Functions"
if script name is "foobar.anyExtension" search in "*.anyExtension" for Libraries of Functions"



for now, using my f5_to_run.ahk, I could detect missing functions and add them "automatically" by reading the error message when I run the script (mainScript.extension)

Code: Select all

Error:  Call to nonexistent function.

Specifically: foobar(args)
here, the missing function is foobar
then I can search in Local Library, Standard Library, and User Library for the file foobar.extension
then I can readFile, then Append either to the end or add it to the front :

Code: Select all

#Include path\to\foobar.extension  (better be a relative path)
but it pollutes the script.
Post Reply

Return to “AutoHotkey Development”