Page 1 of 1

#Include: block auto-include

Posted: 27 Mar 2018, 18:57
by jeeswg
[EDIT:] Lower down, I suggest modifying the list of auto-include folders (potentially to 0), rather than blanket enabling/disabling the standard 3.
#Include: block auto-include - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=13&t=46224&p=236575#p236575

- Sometimes when working with my or other people's scripts, I can have problems with getting a script to run because there is a missing function.
- Instead of getting a message saying that the function wasn't found, the script looks for the function in various libraries, some libraries are automatically included, and I get a duplicate function error.
- This could all be avoided if I could block any 'smart' behaviour, whereby the script is prevented from searching in specific folders for functions/libraries.
- (Without such blocking functionality, some script debugging has taken an absolute age.)
- Apologies if I have overlooked any existing functionality. Thanks for reading.

Re: #Include: block auto-include

Posted: 28 Mar 2018, 02:16
by nnnik
I think that you should probably just manage your includes in a smart way.

Re: #Include: block auto-include

Posted: 28 Mar 2018, 05:41
by Flipeador
I think I agree with nnnik :lolno:
So not to create a new topic, I would like to propose two changes:
  • Allow file extension in <LibName> (e.g. <include_file.ahk/txt/ext>). Currently gives error :eh: .
  • Force the use of quotes in #Include FileOrDirName. FileOrDirName must be an expression. Why?
    • For clarity, now that everything is an expression.
    • #If use expression; why some directives should use expressions and others not?. Of course, with this in mind, it should affect all directives.
    • In the Thoughts for v2.0, it says Perhaps remove the strings "On" and "Off" since they don't work intuitively in boolean expressions, and just use true and false, if this is the case, we would only use TRUE/FALSE.
Edit* Well, maybe the second point is not a very good idea, since variables are not allowed (in other directives) and would not make sense. :facepalm: Forget it :lol:

Re: #Include: block auto-include

Posted: 28 Mar 2018, 08:10
by derz00
Can you share some pointers nnnik? Any good tutorials that you recommend? This include stuff isn't easy for me to understand, and the docs page is not very inclusive, or else I'm just not looking right.

I don't understand why directives do not use expression syntax. Maybe it has been discussed somewhere.

Re: #Include: block auto-include

Posted: 28 Mar 2018, 08:20
by nnnik
I think lexikos simply hasn't touched the general directive syntax since AHK v1 or at least not by more than it was neccessary.

#Include is actually very simple.
You write #include and refer to a file that contains code. AutoHotkey.exe then looks for that file and acts as if said code was there instead of the #include.

Code: Select all

#include script.ahk ;will act as if script.ahk is here
This is commonly used to split out pieces of code that you want to use across projects.
Normally you only write entire classes or entire functions inside such a file. Using it in a different way might lead to errors.
Also using a library name with <> and without it's extension will look for that file in specific folders.
These folders can contain libraries and you can access them from any script without problem.

Re: #Include: block auto-include

Posted: 28 Mar 2018, 08:47
by derz00
nnnik wrote:Also using a library name with <> and without it's extension will look for that file in specific folders.
These folders can contain libraries and you can access them from any script without problem.
What defines a library?
  1. A .ahk file with function definitions?
  2. Or a file called myFunction.ahk with only the function definition myFunction() ?

Re: #Include: block auto-include

Posted: 28 Mar 2018, 09:00
by nnnik
A file containing code thats meant to be used by other scripts.
This is limited to classes or functions.

Re: #Include: block auto-include

Posted: 17 May 2018, 21:44
by jeeswg
- I thought of a slightly better idea than to simply block any auto-includes.
- The ability to specify which folders to do special searches in, and, if you specify no folders, no special searching is done.
- So, something like #IncludeSearch or #IncludeSpecial (or something else/better).
- It could be that if you use the directive multiple times, it tries the first folder, then the second folder etc.
- Perhaps the directive would override the default searches, rather than add to them.

Re: #Include: block auto-include

Posted: 02 Sep 2018, 04:10
by jeeswg
- Something like #IncludeDirList: specify which folders to check, blank for none, e.g.
#IncludeDirList %A_ScriptDir%\Lib|%A_MyDocuments%\Lib|%A_AhkDir%\Lib|%A_AhkDir%\Lib\ExtraFuncs
- The variable A_AhkDir would be required.

- Some functions can clutter a Lib folder, so it's good to have extra Lib folders.
- I had this in mind, where each AHK v2 function was backported as a separate ahk file.
GitHub - cocobelgica/AutoHotkey-Future: Port of AutoHotkey v2.0-a built-in functions for AHK v1.1+
https://github.com/cocobelgica/AutoHotkey-Future

[EDIT:] @derz00: My functions tutorial has a section on #Include:
jeeswg's functions tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=41823