SciTE4ahk custom intellisense generator follow-up

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

SciTE4ahk custom intellisense generator follow-up

26 Jun 2017, 22:17

This is a follow-up on this thread on the old (closed) forum: https://autohotkey.com/board/topic/1112 ... generator/. I hope the OP XeroByte can see it here.

@XeroByte: Joe Glines recently posted a video tutorial about your script (http://the-automator.com/personalizing- ... tocorrect/). Thanks for sharing BuildUserAhkApi.ahk. This script incredibly improves coding with SciTE4AutoHotkey.

But I have an issue with it. AHK lets you format your script and place brackets around functions, if, loop (etc) quite freely. Unfortunately, my personal coding style for functions differs from the style supported by your script. It seems that my own way of putting curly brackets around my functions is not the way BuildUserAhkApi expects them. For example, this is my formatting for functions:

Code: Select all

MyFunc(var)
; my function description
{
  return var
}
But, based on my tests, BuildUserAhkApi expects this:

Code: Select all

MyFunc(var){
; my function description
  return var
}
Do you think your script can be adapted to support various coding style? If not, I can understand that you shared your script based on your own (and quite widespread) coding style. I just want to assess if I would have to convert (retrofit) my functions and... change my habit ;-)

Jean
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
XeroByte
Posts: 26
Joined: 17 Sep 2014, 01:30

Re: SciTE4ahk custom intellisense generator follow-up

26 Jun 2017, 22:42

Hey Jean,

Thanks for the PM.

Wow, thanks for pointing out that my script has been featured. Honestly i'm a bit shocked :shock:
I wrote this quite a long time ago and I don't think I've made any major edits to it since I posted it. I still heavily rely on it, so I'm really excited to see that other people are interested and find value in it.

I'll take some time hopefully this week to look over my code and see if there's anything I can do to allow for the alternate coding style you pointed out.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

26 Jun 2017, 22:47

Thanks XeroByte. Glad to see you taking a look at it. And to see that PM works on this forum :-)

Jean
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

27 Jun 2017, 05:15

@Jean- Thanks for the mention! I'm glad you bumped it out to the new forum & I hope it gets some awareness as it is really helpful!

@XeroByte- Thank you for your work on this! I heavily rely on my lib folder so I was thinking about adding some functionality to this script to keep track of what has been incorporated / processed and then to automatically run if a new file shows-up in my LIB folder. Would anyone else be interested?

Between this script and the other one I use from lexicos to improve auto-complete, I'm seeing huge increases in my productivity!
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: SciTE4ahk custom intellisense generator follow-up

27 Jun 2017, 06:03

@ JnLlnd
welcome to the club of code aesthetics :) (erm, I'm your counterpart :shifty:)
I'm constantly annoyed that AHK won't allow me to use XeroByte's preferred OTB coding style for an (advanced) => Loop :roll:
No idea why it's possible to set up different comment formats, and/or exclude specific characters from further processing but an opening curly brace is kinda coding Anti OTB "Westwall" :lol:. Meh ... (if someone has a UDF in place to bypass that restriction, I'll owe one's a beer!)

"The One True Brace (OTB) style may optionally be used with normal loops (but not specialized loops such as file-pattern and parsing). For example: ..."

Well, back to the topic. Good luck & may your wish come true :thumbup:
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

27 Jun 2017, 06:13

For non-users you might want to watch this video where i demonstrate its usage (which is a life-saver!)

Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

27 Jun 2017, 09:16

@Bobo: When posting this yesterday, I did not remember this "OTB" style had a name. Doing further research, I found my style is named Allman and is inherited from my Pascal coding early days :-)
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

27 Jun 2017, 10:06

I'm going to name my sloppy-coding "Oscar Madison" and go down in history!!!
Image
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
XeroByte
Posts: 26
Joined: 17 Sep 2014, 01:30

Re: SciTE4ahk custom intellisense generator follow-up

04 Jul 2017, 09:15

Just wanted to give a quick update.

I've put together a new RegEx string to find function definitions and their surrounding comments that should allow for additional coding styles including the examples Jean brought to my attention plus comments immediately prior to a function definition.

Now I just need to insert the RegEx, review the rest of the function and test.

It will still only support the semi-colon single line comments and not the multi-line /* */ comments. I'll ponder this and see if I can manage to get those included as well.
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

04 Jul 2017, 10:42

Thanks for the follow-up XeroByte :-) Can't wait to fill SciTE with all my functions defs !
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

18 Jul 2017, 10:54

Hi,
XeroByte wrote:Now I just need to insert the RegEx, review the rest of the function and test.
Any update on this? No pressure :-) I was just reminded to follow on this with you because of a webinar that Joe is giving this afternoon about SciTE and AHK.

For those interested, you can register (free) here:
https://zoom.us/meeting/register/a9e829 ... 1539e44ee6

Thanks,

Jean
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
XeroByte
Posts: 26
Joined: 17 Sep 2014, 01:30

Re: SciTE4ahk custom intellisense generator follow-up

18 Jul 2017, 15:52

JnLlnd wrote:Any update on this? No pressure :-)
I'm so sorry Jean, life & work have been getting in the way. Thanks for the gentle push :-)

I am committed to doing this, but I apologise if it takes a bit longer.

I did insert the Regex, it required a bit of code rewriting - there are still a few things that I'm not quite happy with. I have actually been using this new version for a week or more now and haven't noticed anything going wrong.

I'll try do some more work on it today and I'll decide if it's worthy of being posted yet.
XeroByte
Posts: 26
Joined: 17 Sep 2014, 01:30

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 08:46

Hi All,

I haven't cleaned this up at all yet - I intend on phasing out the use of Poly's grep() function in favor of the RegExMatchGlobal() function by JustMe.

I have really limited time, so I apologise that I haven't tested this fully and I haven't released a proper blurb on everything - there are a few additional things here such as
  • you can pass in an array of AHK scripts and/or folders
  • Some exclusion lists for any files/functions/labels you don't want added to the intellisense (I added this a while back - I actually want to clean this up a bit). for the moment I've defined them inside the function and not as parameters to the function - I'm trying to think of a better way of doing it.
Please let me know if you run into any bugs or if you have suggestions.

Code: Select all

BuildUserAhkApi(AhkScriptPaths, OverwriteAhkApi:="1", RecurseIncludes:="1", Labels:="1", WrapWidth:="265", AhkApiPath:="ReplaceThisWithFullPathTo\SciTE\user\user.ahk.api", RecursionCall:="0"){	
	; Written by XeroByte
	; Generates the User.ahk.api file to add custom function & label intellisense!
	; to initate: use BuildUserAhkApi(A_ScriptFullPath,1) from the main script
	; Requires: grep() by Titan/Polyethelene https://github.com/camerb/AHKs/blob/master/thirdParty/titan/grep.ahk
	; Requires: RegExMatchGlobal() by Just Me - https://autohotkey.com/board/topic/14817-grep-global-regular-expression-match/page-2
	; Requires: tooltip(),
	; Requires: isDir(),
	; Optionally include TF_Wrap() from the TF Library https://github.com/hi5/TF/blob/master/tf.ahk
	TF_Wrap := "TF_Wrap" ; This is for a workaround to make the script still work even without the TF library - need to call the function dynamically.
	FileExclusionList := "Socket.ahk|DirMenu2-include.ahk"
	FuncExclusionList := "if|While|VarZ_Save|__New|__Delete|__Call|__Get|__Set"
	LabelExclusionList := "FindReplaceErr|MoveCurser"
	if(!IsObject(AhkScriptPaths))
		AhkScriptPaths := Array(AhkScriptPaths)
	for index, AhkScriptPath in AhkScriptPaths
	{
		if(isDir(AhkScriptPath)){
			Loop, %AhkScriptPath%\*.ahk,0,1
			{
				if(InStr("|" FileExclusionList "|", "|" A_LoopFileName "|",false)=0)
					AhkApiText .= BuildUserAhkApi(A_LoopFileLongPath, 0, RecurseIncludes, Labels, WrapWidth, AhkApiPath, 1)
			}
		}else{
			SplitPath,AhkScriptPath,AhkScriptFname
			if(InStr("|" FileExclusionList "|", "|" AhkScriptFname "|",false)=0)
			{
				FileRead, ThisScriptTxt, %AhkScriptPath%
				; Retrieve Functions
					MatchCollection := RegExMatchGlobal(ThisScriptTxt, "m)(?P<PreComment>(?:(?:(?:^[ \t]*;.*)+(?:\r|\n)+)|^[ \t]*\/\*(?:(?!^[ \t]*\*\/)(?:.|\r|\n))+^[ \t]*\*\/(?:\r|\n)+)*)^[ \t]*(?P<FuncDefinition>(?P<FuncName>[a-zA-Z0-9_-]*)\((?P<FuncParams>.*)\))\s*(?P<Comment1>(?:[ \t]*;.*(?:\r|\n)+)*)\{[ \t]*(?P<Comment2>(?:[ \t]*;.*)?(?:(?:(?:\r|\n)+^[ \t]*;.*)|(?:\r|\n)+^[ \t]*\/\*(?:(?!^[ \t]*\*\/)(?:.|\r|\n))+^[ \t]*\*\/)*)")
					For k, v in MatchCollection
					{
						if(InStr("|" FuncExclusionList "|", "|" v[3] "|",0)>0)
							continue
						CustomFunc := v[3] " (" v[4] ")`r`n" v[1] "`r`n" v[5] "`r`n" v[6]
						CustomFunc := StrReplace(CustomFunc,"\","\\")
						CustomFunc := RegExReplace(CustomFunc,"S)(^\s*|\s*$)")
						CustomFunc := RegExReplace(CustomFunc, "^\s*[\r\n]+","")
						if(IsFunc("TF_Wrap"))
							CustomFunc := %TF_Wrap%(CustomFunc, WrapWidth)
						CustomFunc := RegExReplace(CustomFunc,"S)\R+", "\n")
						CustomFunc := RegExReplace(CustomFunc,"S)\t", " ")
						CustomFunc .= "\n; Location: " . RegExReplace(AhkScriptPath,"\\","\\")
						CustomFunc := RegExReplace(CustomFunc,"S)(?:\\n)+ *", "\n")
						;~ CustomFunc := RegExReplace(CustomFunc,"S)(?:\\t)+ *", "\t")
						AhkApiText .= CustomFunc "`n"
					}
					AhkApiText .= "`n"
				; Retrieve Labels
				if(Labels){
			grep(ThisScriptTxt, "mS)^\s*[a-zA-Z0-9_-]+\:\s(\s*;.*?$)*", MatchCollection,1,0,"§")
			loop, parse, MatchCollection, §
					{	
						if(RegExMatch(A_LoopField,"iS)^\s*(" LabelExclusionList ")\:\s")>0)
							continue
						StringReplace, CustomFunc, A_LoopField, \, \\, All
						CustomFunc := RegExReplace(CustomFunc,"mS)(^\s*|\s*$)")
						if(IsFunc("TF_Wrap"))
							CustomFunc := %TF_Wrap%(CustomFunc, WrapWidth)
						CustomFunc := RegExReplace(CustomFunc,"S)\R", "\n")
						CustomFunc := RegExReplace(CustomFunc,"S)\t", "\t")
						StringReplace, CustomFunc, CustomFunc, :, %A_Space%
						AhkApiText .= CustomFunc . "\n; Location: " . RegExReplace(AhkScriptPath,"\\","\\") . "`n"
					}
					AhkApiText .= "`n"
				}
				; Recurse into includes
				if(RecurseIncludes){
			grep(ThisScriptTxt, "imS)^\s*\#include (.*)\s*$", IncludeCollection,1,1,"§")
					AhkScriptFolder := substr(AhkScriptPath,1,InStr(AhkScriptPath,"\",0,0))
			loop, parse, IncludeCollection, §
						AhkApiText .= BuildUserAhkApi((instr(A_LoopField,":")) ? A_LoopField : AhkScriptFolder . A_LoopField, 0, 1, Labels, WrapWidth, AhkApiPath, 1)
				}
			}
		}
	}
	; If this function call is the original function call (and not an autocall by the recursion).
	if(!RecursionCall){
		if(OverwriteAhkApi)
			FileDelete, %AhkApiPath%
		AhkApiText := RegExReplace(AhkApiText, "(\R){2,}","$1$1")
		FileAppend, %AhkApiText%, %AhkApiPath%
		ToolTip("Imported Custom Funcs & Labels from`n" . AhkScriptPath)
	}
	return AhkApiText
}



grep(h, n, ByRef v, s = 1, e = 0, d = "") {
	v =
	StringReplace, h, h, %d%, , All
	Loop
		If s := RegExMatch(h, n, c, s)
			p .= d . s, s += StrLen(c), v .= d . (e ? c%e% : c)
		Else Return, SubStr(p, 2), v := SubStr(v, 2)
}

ToolTip(Message, TimeToDisplay = 500, SleepWhileDisplayed = true){
	; ToolTip, Text, X, Y, WhichToolTip
	ToolTip,%Message% ; display message
	SetTimer,ToolTipClear, Off
	SetTimer,ToolTipClear,-%TimeToDisplay% ; clear tooltip after TimeToDisplay milliseconds
	If SleepWhileDisplayed
		Sleep,%TimeToDisplay% ; sleep before returning
	Return
	
	ToolTipClear: ; clear tooltip
	ToolTip
	Return
}

isDir(FilePattern){
	att := FileExist(FilePattern)
	return att = "" ? "" : InStr(att, "D") = 0 ? 0 : 1
}

RegExMatchGlobal(ByRef Haystack, NeedleRegEx) {
   Static Options := "U)^[imsxACDJOPSUX`a`n`r]+\)"
   NeedleRegEx := (RegExMatch(NeedleRegEx, Options, Opt) ? (InStr(Opt, "O", 1) ? "" : "O") : "O)") . NeedleRegEx
   Match := {Len: {0: 0}}, Matches := [], FoundPos := 1
   While (FoundPos := RegExMatch(Haystack, NeedleRegEx, Match, FoundPos + Match.Len[0]))
      Matches[A_Index] := Match
   Return Matches
}
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 09:22

@ XeroByte- No need to apologize! Thank you for your work on this! I'm looking forward to playing with it! :)
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 09:34

I cant get Scite to recognize C:\Program Files\AutoHotkey\SciTE\user\user.ahk.api
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 09:49

I have the same issue. The script cannot write the file user.ahk.api because it is located under the protected C:\Program Files\ folder (C:\Program Files\AutoHotkey\SciTE\user\user.ahk.api)

Should SciTE be running in a not protexted folder (as the under "Documents")?

And thank you XeroByte for your work!
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 10:28

OK... I'm re-discovering my own SciTE setup! I'm running SciTE under the Program Files protected folder. And my user folder is located under my Documents folder:
C:\Users\Jean\Documents\AutoHotkey\SciTE

I succeeded by setting the default path in function BuildUserAhkApi as:
BuildUserAhkApi(AhkScriptPaths, OverwriteAhkApi:="1", RecurseIncludes:="1", Labels:="1", WrapWidth:="265", AhkApiPath:="C:\Users\Jean\Documents\AutoHotkey\SciTE\user.ahk.api", RecursionCall:="0")

No need to re-install SciTE ;-)

@tank: If you have a setup similar to mine, you just need to find where is your SciTE user folder and edit the default value for AhkApiPath in the copy of AhkApiPath.ahk in your Lib folder.
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 10:50

Now that I can run it, I found that it indexes the labels well. Unfortunately, no function was indexed. Anybody has the same issue?
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 12:28

Thanks JnLlnd that solved my problem. No i cant duplicate your problem
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: SciTE4ahk custom intellisense generator follow-up

20 Jul 2017, 12:57

@tank: How do you write your functions? My format is:

FunctionName()
; comment
{
}
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], imstupidpleshelp, JoeWinograd, mikeyww, ositoMalvado, Rohwedder, usser and 190 guests