Enable Function List in Notepad++ for AHK Scripts (with classes now)

Scripting and setups with Notepad++ and AutoHotkey.
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

21 Mar 2017, 02:42

Thanks for adding support for class properties! :thumbup:

If I notice any problems with this, I'll report them
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Problem: Constructor is not detected

21 Mar 2017, 04:23

Within a class the constructor (__New()) is not detected:

Code: Select all

class Test{
	a() {
	}
	__New(_hWnd=-1, _debug=0, _test=0) {		
		return this
	}
}
Omitting the method a() within the class, even the class itself is not detected ....
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

21 Mar 2017, 10:29

Wow pretty embarrassing how long this went without getting caught, it wasn't the constructor that was the problem, I hadn't allowed for negative default values... seeing as how that went unnoticed I'm sure there are others, keep pointing them out to me and I'll add the conditions to the parser.

Fixed:

Code: Select all

			<parser id="ahk_function" displayName="AHK" commentExpr="((/\*.*?\*)/|((?<=[\s]);.*?$))">
				<!-- AutoHotKey Function List -->
				<classRange
					mainExpr="^[ \t]*(class|struct)[ \t]+[\w]+([ \t]+|[ \t]+(extends)[ \t]+)?\w*([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{"
					openSymbole = "\{"
					closeSymbole = "\}"
					displayMode="node">
					<className>
						<nameExpr expr="(class|struct)[\s]+[\w]+"/>
						<nameExpr expr="[\s]+[\w]+"/>
						<nameExpr expr="[\w]+"/>
					</className>
					<function
						mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*(\([^)]*\)|\[[^]]*\])([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$: ])+\d*(?<![\s])::(?=[^\s])?">
						<functionName>
							<funcNameExpr expr="([\w#!^+&<>*~$])+\d*(\([^)]*\)|\[[^]]*\])|([\w#!^+&<>*~$: ])+\d*::?"/>
						</functionName>
					</function>
				</classRange>
				<function
					mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*\([^)]*\)([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$: ])+\d*(?<![\s])::(?=[^\s])?"
					displayMode="$className->$functionName">
					<functionName>
						<nameExpr expr="([\w#!^+&<>*~$])+\d*\([^)]*\)|([\w#!^+&<>*~$: ])+\d*::?"/>
					</functionName>
				</function>
			</parser>
I've tried to just allow anything to be within the ( ... ), but I can't allow function parameters to include ) ( In Classes this is ] for class parameters ) otherwise calling functions consumes everything to the next { and calls it a function. Even with this, you can kind of break it if there is for some reason no ) on a line that could qualify as a function, basically a function call. Seeing as how that would be an error most likely anyway I think its the best option.

**Edited to fix something I broke with the version posted. (sorry I kept editing this version, I keep finding things the change broke)
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

22 Mar 2017, 01:20

Thanks for the fast fix! :dance:
Nightwolf85 wrote:Wow pretty embarrassing how long this went without getting caught, it wasn't the constructor that was the problem, I hadn't allowed for negative default values... seeing as how that went unnoticed I'm sure there are others, keep pointing them out to me and I'll add the conditions to the parser.
I didn't notice, it's the negative default value causing the problem - I just saw there is a problem. If I'll find further problems, I'll let you know. :terms: :D
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

String Authors: within block-comment is detected as hotstring

22 Mar 2017, 04:47

As promised - here I'm again:

Within a blockcomment /* ... */ the String "Authors:" is detected as hotstring and appears in functionlist:

Code: Select all

class Test {
; ******************************************************************************************************************************************
/*
	Class: Test
		Helper class

	Authors:
	<hoppfrosch at [email protected]>: Original
	
	value:
	xxx - ABC
*/	
}
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

22 Mar 2017, 07:10

Yeah, I am aware that block comments don't stop items from being found, but if you read the documentation page for the functionlist (https://notepad-plus-plus.org/features/ ... -list.html) it states that comment sections should be skipped over, but it doesn't for some reason. I'm not sure I can easily change the RegEx to fix this, as I use a line by line search currently.

The workaround is to either put a ; before the Authors: on the line, or since labels aren't allowed to have anything after the colon other than a comment, you can put any text after Authors: and it won't show in the functionlist.

As soon as I have a fix for this, if I can get one, I will post it.
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

22 Mar 2017, 09:06

It's not a big thing for me - just wanted to let you know.

I automatically extract documentation from my sourse using NaturalDocs (ND) - I have to check, whether ND can handle preceeding semicoloms. If not, I'll live with the wrongly detected hotstring within the functionlist ...
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

22 Mar 2017, 18:59

The block comments thing isn't all bad. I'm planning on soon posting a tool in this genre that makes use of the "feature" that function definitions in a comment block are included.
KusochekDobra
Posts: 38
Joined: 25 Apr 2016, 18:00

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

31 Mar 2017, 18:26

Great work! Thank you very much! =)
Отличная и очень нужная работа! Большое спасибо за ваш творческий подход! =)
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

03 Apr 2017, 10:03

Thanks to all involved in this, :clap:
Although hotstring support wasn't stated, it seems to work except for,

Code: Select all

:?:f::fails on hotstrings with ? option
I'm using this version.

Cheers!
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

03 Apr 2017, 21:26

Thank you for the report. I don't use HotStrings very often but I looked through the documentation to make sure there weren't any other characters that weren't covered, looks like ? was all that I was missing.

Fixed:

Code: Select all

			<parser id="ahk_function" displayName="AHK" commentExpr="((/\*.*?\*)/|((?<=[\s]);.*?$))">
				<!-- AutoHotKey Function List -->
				<classRange
					mainExpr="^[ \t]*(class|struct)[ \t]+[\w]+([ \t]+|[ \t]+(extends)[ \t]+)?\w*([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{"
					openSymbole = "\{"
					closeSymbole = "\}"
					displayMode="node">
					<className>
						<nameExpr expr="(class|struct)[\s]+[\w]+"/>
						<nameExpr expr="[\s]+[\w]+"/>
						<nameExpr expr="[\w]+"/>
					</className>
					<function
						mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*(\([^)]*\)|\[[^]]*\])([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(;|if\(|while\(|for\())([^\r\n\t])+\d*(?<![\s])::(?=[^\s])?">
						<functionName>
							<funcNameExpr expr="([\w#!^+&<>*~$])+\d*(\([^)]*\)|\[[^]]*\])|([^\r\n\t])+\d*::?"/>
						</functionName>
					</function>
				</classRange>
				<function
					mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*\([^)]*\)([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(;|if\(|while\(|for\())([^\r\n\t])+\d*(?<![\s])::(?=[^\s])?"
					displayMode="$className->$functionName">
					<functionName>
						<nameExpr expr="([\w#!^+&<>*~$])+\d*\([^)]*\)|([^\r\n\t])+\d*::?"/>
					</functionName>
				</function>
			</parser>
**Edit
Found some HotKeys that weren't being found either, this version allows for anything other than Newlines and Tabs to be a part of a HotKey definition.
Functions and labels are still restricted to be
Word characters:
[a-zA-Z_]
and this set of symbols:
#!^+&<>*~$

Should this be changed at all? I think this restriction is acceptable on Functions and Labels, but it wasn't inclusive enough for HotKeys. (Issue I found was ^!/:: wasn't found because of the slash)
Last edited by Nightwolf85 on 04 May 2017, 08:05, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

05 Apr 2017, 10:14

This fails if there is nothing to the right of the last }.

Code: Select all

class test {
	a(){
	}
}
Putting a single space, or whatever, fixes it. Eg, adding a line break,

Code: Select all

class test {
	a(){
	}
}

Cheers.

Edit:
Nightwolf85 wrote: Fixed:
Thanks for the fix.
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

05 Apr 2017, 16:00

Yeah, I've noticed that as well. I'm honestly not sure how to fix that part, since all the options I have for defining a class range are open and close symbols. I'll play around with it some and post if I have a solution, for now I just go through and make each of my files end with a newline (or like you said at least a space), not ideal but is an easy enough workaround.
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

23 Jun 2017, 08:27

I noticed another bug, not with finding functions and labels, but with displaying them.

If a function had a default value using the := operator it would display as a label in the list. This wasn't a big deal since nothing was missing, but looked strange and so I fixed it:

Code: Select all

			<parser id="ahk_function" displayName="AHK" commentExpr="((/\*.*?\*)/|((?<=[\s]);.*?$))">
				<!-- AutoHotKey Function List -->
				<classRange
					mainExpr="^[ \t]*(class|struct)[ \t]+[\w]+([ \t]+|[ \t]+(extends)[ \t]+)?\w*([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{"
					openSymbole = "\{"
					closeSymbole = "\}"
					displayMode="node">
					<className>
						<nameExpr expr="(class|struct)[\s]+[\w]+"/>
						<nameExpr expr="[\s]+[\w]+"/>
						<nameExpr expr="[\w]+"/>
					</className>
					<function
						mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*(\([^)]*\)|\[[^]]*\])([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(;|if\(|while\(|for\())([^\r\n\t])+\d*(?<![\s])::">
						<functionName>
							<funcNameExpr expr="([\w#!^+&<>*~$])+\d*(\([^)]*\)|\[[^]]*\])|([\w#!^+&<>*~$])+\d*:(?!:)|(?![ ])([^\r\n\t])+\d*::"/>
						</functionName>
					</function>
				</classRange>
				<function
					mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*\([^)]*\)([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(;|if\(|while\(|for\())([^\r\n\t])+\d*(?<![\s])::"
					displayMode="$className->$functionName">
					<functionName>
						<nameExpr expr="([\w#!^+&<>*~$])+\d*\([^)]*\)|([\w#!^+&<>*~$])+\d*:(?!:)|(?![ ])([^\r\n\t])+\d*::"/>
					</functionName>
				</function>
			</parser>
RiseUp
Posts: 28
Joined: 01 Oct 2013, 21:27

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

09 Nov 2017, 17:56

Nightwolf85 wrote:I noticed another bug, not with finding functions and labels, but with displaying them.

If a function had a default value using the := operator it would display as a label in the list. This wasn't a big deal since nothing was missing, but looked strange and so I fixed it:
Hey Nightwolf85, I just wanted to say thank you for all your work on this. I have put this function list ability into play a few minutes ago, and I look forward to taking advantage of it. :D
User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

28 Nov 2017, 12:41

Hello everyone!

Thanks a lot everyone for the effort to improve this function list. I've been absent for several weeks and I am really surprised with the progress in this subject. I will update the first message with the last modification made by Nightwolf85.
Editor: Notepad++
"Those who wait and persist, always achieve."
RobertQuora

Enable Function List in Notepad for AHK Scripts with classes now

14 Feb 2018, 04:29

OK I want try use TNxAutoCompletion with TNxComboBox until there is not a native function but I have a problem.

If I use TNxComboBox with Style = dsDropDown it works, but I need use Style = dsDropDownList because I need the user choose only one of my items, the user cannot add item

Can I do it? How?

план противодействия коррупции на 2018
User avatar
Trogluddite
Posts: 8
Joined: 23 Mar 2018, 06:42

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

24 Mar 2018, 16:48

Thankyou to all contributors, this works beautifully here. :D
It does a better job than some of the built in ones! I might even have a go at improving the one for Ruby now that I've seen how you guys tackled this one (it doesn't handle Ruby classes/modules.)
User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

05 Apr 2018, 12:16

Hi Trogludite,

I'm glad that this thread helped you. If you have any idea to share please feel free.

Regards
Editor: Notepad++
"Those who wait and persist, always achieve."
anotherautohotkeyusr
Posts: 21
Joined: 27 Oct 2015, 18:45

Re: Enable Function List in Notepad++ for AHK Scripts (with classes now)

09 Mar 2019, 23:00

For my future reference, I edited the parser so that it is valid XML:

Code: Select all

			<parser
                displayName="AHK"
                id         ="ahk_function"
                commentExpr="((/\*.*?\*)/|((?&lt;=[\s]);.*?$))"
            >
				<classRange
					mainExpr="^[ \t]*(class|struct)[ \t]+[\w]+([ \t]+|[ \t]+(extends)[ \t]+)?\w*([\s]|(/\*.*?\*)/|((?&lt;=[\s]);[^\r\n]*?$))*?[\s]*\{"
					openSymbole = "\{"
					closeSymbole = "\}"
					displayMode="node">
					<className>
						<nameExpr expr="(class|struct)[\s]+[\w]+" />
						<nameExpr expr="[\s]+[\w]+" />
						<nameExpr expr="[\w]+" />
					</className>
					<function
						mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&amp;&lt;&gt;*~$])+\d*(\([^)]*\)|\[[^]]*\])([\s]|(/\*.*?\*)/|((?&lt;=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&amp;&lt;&gt;*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(;|if\(|while\(|for\())([^\r\n\t])+\d*(?&lt;![\s])::">
						<functionName>
							<funcNameExpr expr="([\w#!^+&amp;&lt;&gt;*~$])+\d*(\([^)]*\)|\[[^]]*\])|([\w#!^+&amp;&lt;&gt;*~$])+\d*:(?!:)|(?![ ])([^\r\n\t])+\d*::" />
						</functionName>
					</function>
				</classRange>
				<function
					mainExpr="^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&amp;&lt;&gt;*~$])+\d*\([^)]*\)([\s]|(/\*.*?\*)/|((?&lt;=[\s]);[^\r\n]*?$))*?[\s]*\{|^[ \t]*(?!(if\(|while\(|for\())([\w#!^+&amp;&lt;&gt;*~$])+\d*:(?=([\s]*[\r\n]|[\s]+;.*[\r\n]))|^[ \t]*(?!(;|if\(|while\(|for\())([^\r\n\t])+\d*(?&lt;![\s])::"
					displayMode="$className->$functionName">
					<functionName>
						<nameExpr expr="([\w#!^+&amp;&lt;&gt;*~$])+\d*\([^)]*\)|([\w#!^+&amp;&lt;&gt;*~$])+\d*:(?!:)|(?![ ])([^\r\n\t])+\d*::" />
					</functionName>
				</function>
			</parser>
Using a "text" codebox, because the "xml" codebox does not colour the contents correctly.

Return to “Notepad++”

Who is online

Users browsing this forum: No registered users and 4 guests