Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

For those who use Notepad++ (aka npp)


  • Please log in to reply
39 replies to this topic
abp
  • Guests
  • Last active:
  • Joined: --
in notepad++ there is a 'function list' plugin, which does not support AHK syntax.
but you can add user defined rules, so that view a list of functions or hotkeys.
here is my ini file.
[Function List]
Show all functions=0
Sort by names=0
showCmd=0
[User Languages]
Count User Languages=1
Name 1=AHK Autohotkey
KeyWBodyBeg 1=
KeyWBodyEnd 1=
MatchCase 1=0
Count Comment 1=0
Count Syntax 1=3
Syntax P1.1.1=
Syntax P2.1.1=\([a-zA-Z0-9_, \t]*\)
Syntax P3.1.1=[a-zA-Z0-9_]+
Syntax P4.1.1={
Syntax P5.1.1=}
Syntax P6.1.1=$
Syntax P1.2.1=
Syntax P2.2.1=
Syntax P3.2.1=[#!^+&*~$ -=\[\]\\;',./A-Za-z0-9]+[:][:]
Syntax P4.2.1=
Syntax P5.2.1=
Syntax P6.2.1=
Syntax P1.3.1=
Syntax P2.3.1=
Syntax P3.3.1=
Syntax P4.3.1=
Syntax P5.3.1=
Syntax P6.3.1=
[HEX-Editor]
Columns=16
Bits=1
Binary=0
Little=0
Capitel=0
Extensions=

Save it as insertExt.ini and move it into your notepad++ directory.(eg. c:\program files\notepad++)

make sure you set AHK as user defined language. it can be done by copying ahkdir\extras\notepad++\userDefineLang.xml into your notepad++ directory.


Posted Image

HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007
Great!
But sadly it has an annoying effect: it can't handle the standalone % characters.
example:
DataPath := % A_ScriptDir "\Data\" ; This is a valid assignment
(EDIT: fixed syntax :D )
Every code appears in orange color after the % sign. Can you fix it?

abp
  • Guests
  • Last active:
  • Joined: --
Dear HuBa,
You're right. AHK highlighting with NPP is not perfect, because it's not so configurable.
If you don't mind, you can use my customized version.
it's not perfect neither, but i think it would be better.

http://www.playnow.c...rDefineLang.xml

anyway,

example:

DataPath := % A_ScriptDir "\Data\ ; This is a valid assignment

Is this a valid assignment? :)

p.s> Above ini doesn't recognize a function which has an optional parameters. This would work correctly.

HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007

Is this a valid assignment?

LOL, you are right, I forget the closing " :D

Thanx for the config files! The code is now beautiful!!!! 8)

HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007
I made a modified version of userDefineLang.xml
[*:241zny63]It includes 2 new variable: True and False
[*:241zny63]And 3 new operator: And, Not, Or
[*:241zny63]Light background color for comment.
[*:241zny63]Changed text colors a bit.Also there is a new version out there: Notepad++ 4.3
It features a new tabbed find dialog and url styling with dblclick handling.
Be careful with the %APPDATA% option in installer!

mosaic
  • Members
  • 29 posts
  • Last active: Nov 04 2009 04:57 AM
  • Joined: 25 Apr 2007

I made a modified version of userDefineLang.xml
[*:zznzc3pg]It includes 2 new variable: True and False
[*:zznzc3pg]And 3 new operator: And, Not, Or
[*:zznzc3pg]Light background color for comment.
[*:zznzc3pg]Changed text colors a bit.Also there is a new version out there: Notepad++ 4.1
It features a new tabbed find dialog and url styling with dblclick handling.
Be careful with the %APPDATA% option in installer!


Nice. Thanks a lot HuBa.

By the way, I have a question on function list based on the definition in insertExt.ini

The following few examples will display incorrect function lists:

this_function_does_not_show_but_should_be_shown(help="default help string", test=){         
} ; this the

if this_function_should_not_show_but_show(hello, haha)  { ;if this is true

}

If (InStr(FirstWord,"::")) {
   ; this is shown as hotkey because of :: in the string, oops, another one
   ; so :: should not even appear in the comment
}

DLLCall(arg1, arg2) ; this one should not be listed as function but it is
                             ; if you make lots of DllCall, guess what you will see
	
anothergoodfunction_not_shown( arg1,       ; comment for arg1
                                                 arg2       ; comment for arg2
                                              )
{
}
					

I have no knowledge of how to change insertExt.ini. Is there a documentation somewhere to explain the Syntax?

Thanks

mosaic
  • Members
  • 29 posts
  • Last active: Nov 04 2009 04:57 AM
  • Joined: 25 Apr 2007
After spend a good few hours, I made some progress.(sort of). Here is what I find out and I thought might as well share back with all of you.

First of all, there are very few information available on insertExt.ini, however, in Notepad++, goto Plugins->Function List->User Rules, that's where you can define this insertExt.ini, when you open the gui, you can click help (underneath Remove Rule button), you can get a small help.

Secondly, I tried various way, but I think, mostly probably due to my limited knowledge, I can't get them work.

Thirdly, I found out that if I stick to certain rules in my coding, I got enlightened by the Auto-Syntax-Tidy.ahk script, I maybe more likely to succeed.

Here is my version insertExt.ini ( I started with abp's version, thanks for the clue)

[Function List]
Show all functions=1
Sort by names=0
showCmd=0
[User Languages]
Count User Languages=1
Name 1=AHK Autohotkey
KeyWBodyBeg 1=
KeyWBodyEnd 1=
MatchCase 1=0
Count Comment 1=1
Count Syntax 1=3
Syntax P1.1.1=^
Syntax P2.1.1=\([a-zA-Z0-9_,="; \t]*\)
Syntax P3.1.1=[a-zA-Z0-9_]+
Syntax P4.1.1={
Syntax P5.1.1=}
Syntax P6.1.1=$
Syntax P1.2.1=^
Syntax P2.2.1=
Syntax P3.2.1=[#!^+&*~$ -=\[\]\\;',./A-Za-z0-9]+[:][:][ \t]*$
Syntax P4.2.1=
Syntax P5.2.1=
Syntax P6.2.1=
Syntax P1.3.1=
Syntax P2.3.1=
Syntax P3.3.1=
Syntax P4.3.1=
Syntax P5.3.1=
Syntax P6.3.1=
Comment P1.1.1=/*
Comment P2.1.1=*/
[HEX-Editor]
Columns=16
Bits=1
Binary=0
Little=0
Capitel=0
Extensions=.exe .dll
As you can see, I added the requirement that all the function definition can't be indented or leave any spaces. If I stick to this rule, I simplied many problems I faced, as I listed in the previous post. But this still does not solve this:
DllCall(helo, helo)
or this
If(true) {
    ;do something
}
So I made another rule, all function call (and anything resembling function definition) should be indented, in that way, they will not be listed in the function list.

The following is my test script, which shows the functions are listed correctly

/* Some Rules
   If calling a function, make sure to indent the calling function
   function definition should not be indented
   In the function argument block, if there are comments, don't use any more ()
*/
weppp::

function2(arg1="::", arg2){
}

function(help="default help string", test=){         
} ; this the

; make DllCall like this, leave some room in the begining
   DLLCall(helo, helo)

; make if block like this, leave some room in the begining
   if(true) {    ; do something
   }

if thisisnotfunction(hello, haha) { ;hello

}

functiongood(ha, ha) ; comment
{    ; more comment
}

functiongood2(arg1, arg2) { ; another good one """
} ; comment

Anothergoodfunct( arg1,     ; some comment for arg1, *****
                  arg2     ; some comment for arg2, avoid using left parences in the comment section
				)
{
}


mosaic
  • Members
  • 29 posts
  • Last active: Nov 04 2009 04:57 AM
  • Joined: 25 Apr 2007
I made some changes to insertExt.ini to include @ as valid character in function names as mentioned here.

I also greatly simplified the RegEx rule in the function argument block to not allow additional ( character. Even that could not happen if there are comments for argument as the following a legit function definition:

valid_function_heh(arg1,          ; comment for arg1
                            arg2           ; comment for arg2, !@#$%^^&&**(()_+
                          )
{
}

But that will throw things off too much, here is the new insertExt.ini file:

[Function List]
Show all functions=1
Sort by names=1
showCmd=0
[User Languages]
Count User Languages=1
Name 1=AHK Autohotkey
KeyWBodyBeg 1=
KeyWBodyEnd 1=
MatchCase 1=0
Count Comment 1=1
Count Syntax 1=3
Syntax P1.1.1=^
Syntax P2.1.1=\([^(]*\)
Syntax P3.1.1=[a-zA-Z0-9@#?\[\]_]+
Syntax P4.1.1={
Syntax P5.1.1=}
Syntax P6.1.1=$
Syntax P1.2.1=
Syntax P2.2.1=
Syntax P3.2.1=[#!^+&*~$ -=\[\]\\;',./A-Za-z0-9]+[:][:][ \t]*$
Syntax P4.2.1=
Syntax P5.2.1=
Syntax P6.2.1=
Syntax P1.3.1=
Syntax P2.3.1=
Syntax P3.3.1=
Syntax P4.3.1=
Syntax P5.3.1=
Syntax P6.3.1=
Comment P1.1.1=/*
Comment P2.1.1=*/
[HEX-Editor]
Columns=16
Bits=1
Binary=0
Little=0
Capitel=0
Extensions=.exe .dll

If anyone is trying and running into problems, please let me know. Thanks.

mosaic
  • Members
  • 29 posts
  • Last active: Nov 04 2009 04:57 AM
  • Joined: 25 Apr 2007
I updated the insertExt.ini to reflect the following:

Variable names: Variable names are not case sensitive (for example, CurrentDate is the same as currentdate). Variable names may be up to 254 characters long and may consist of letters, numbers and the following punctuation: # _ @ $ ? [ ]


This is in response to toralf's message Thanks toralf.

Using this new rule, the following extreme case function name could be picked up:

Is_This_Valid?#[@index](){
    MsgBox, is this valid?
}


Avalon
  • Members
  • 26 posts
  • Last active: Oct 18 2007 02:45 PM
  • Joined: 11 May 2007
I know it's a very lame question, but how can I install a userDefined language from that xml file linked above?

mosaic
  • Members
  • 29 posts
  • Last active: Nov 04 2009 04:57 AM
  • Joined: 25 Apr 2007

I know it's a very lame question, but how can I install a userDefined language from that xml file linked above?


Avalon,

No question is lame. To install the the XML file, just copy it (userDefined.xml) to your notepad++ directory (the same directory where your notepad++.exe resides), and afterwards, you probably need to restart your notepad++ program for it to take effect.

GL, and let me know if you ran into any problem.

Avalon
  • Members
  • 26 posts
  • Last active: Oct 18 2007 02:45 PM
  • Joined: 11 May 2007

[...]
To install the the XML file, just copy it (userDefined.xml) to your notepad++ directory (the same directory where your notepad++.exe resides), and afterwards, you probably need to restart your notepad++ program for it to take effect.
[...]

This is exactly what I did, but somehow I had messed up my Npp, and did nothing. :S Now I overwrote it with a freshly downloaded, and it works perfectly.

Thanks for the kind help! Posted Image

haichen
  • Members
  • 200 posts
  • Last active: Oct 20 2013 01:14 PM
  • Joined: 05 Feb 2007

To install the the XML file, just copy it (userDefined.xml) to your notepad++ directory (the same directory where your notepad++.exe resides), and afterwards, you probably need to restart your notepad++ program for it to take effect.

I had to put the files in C:\Documents......r\Application Data\Notepad++
Then it worked.

mosaic
  • Members
  • 29 posts
  • Last active: Nov 04 2009 04:57 AM
  • Joined: 25 Apr 2007
I have updated the insertExt.ini to include support for subroutines.

Here it is:

[Function List]
Show all functions=1
Sort by names=1
showCmd=0
[User Languages]
Count User Languages=1
Name 1=AHK Autohotkey
KeyWBodyBeg 1=
KeyWBodyEnd 1=
MatchCase 1=0
Count Comment 1=1
Count Syntax 1=4
Syntax P1.1.1=^
Syntax P2.1.1=\([^(]*\)
Syntax P3.1.1=[a-zA-Z0-9@?#\[\]_]+
Syntax P4.1.1={
Syntax P5.1.1=}
Syntax P6.1.1=$
Syntax P1.2.1=
Syntax P2.2.1=
Syntax P3.2.1=[#!^+&*~$ -=\[\]\\;',./A-Za-z0-9]+[:][:][ \t]*$
Syntax P4.2.1=
Syntax P5.2.1=
Syntax P6.2.1=
Syntax P1.3.1=^
Syntax P2.3.1=[ \t]*$
Syntax P3.3.1=[a-zA-Z0-9@?#\[\]_]+[:]
Syntax P4.3.1=
Syntax P5.3.1=^[Rr]eturn[ \t]*$
Syntax P6.3.1=$
Comment P1.1.1=/*
Comment P2.1.1=*/
Syntax P1.4.1=
Syntax P2.4.1=
Syntax P3.4.1=
Syntax P4.4.1=
Syntax P5.4.1=
Syntax P6.4.1=
[HEX-Editor]
Columns=16
Bits=1
Binary=0
Little=0
Capitel=0
Extensions=.exe .dll


As usual, some rules to use this insertExt.ini

/* Some Rules
If calling a function, make sure to indent the calling function
Function definition should not be indented or leave any spaces in the front
In the function argument block, if there are comments, don't use any more ()
When making a subroutine label, make sure don't use any indentation or leave any spaces in the front, just like function definition, same with the return statement which end the subroutine.

For example:

Sub1:

; your code blocks here
; there could be more return statement in between
; you should indent those earlier return statement (usually under certain if conditioning statement
Return

Sub1 should be correctly picked up in the function lists now.
*/


I also went to the Notepad++ plugin developement forum asking for some help, as the parser for function list plugin will treat the following if statement (in C/C++) as functions:

if(x>y) {
printf("x is bigger than y");
} else {
if(x<y) {
printf("x is smaller than y");
} else { // x=y
printf("x is the same as y");
}
}


This demonstrates the problem with function list displaying problem is not unique in ahk script. This enhances my belief that if you follow a strict rule of coding, you may more likely to succeed. As a matter of fact, since ahk support is not built in, we can succeed way faster than those built-in languages. The problem I mentioned above still exists in the newest version of NPP, however, if you use my insertExt.ini, and follow the rules I mentioned above, you eliminate the problem right away.

This is usually possible with your own code. However, what if you are reading other people's code. To quickly modify it, I recommend to use the toralf's Auto-Syntax-Tidy.ahk, pick a style you like.

This will usually solve majority of the problem. Except making function calls in the autoexec section of the code. I recommend the C/C++ approach. Convert your autoexec into a subroutine called Main, keep it on the stop of your script, so it will still be autoexecuted.

Main:
    ; your original autoexec code for ahk script
Return
   ; your other code

This works in 98% of the time, on some weird situations, Subroutine labels could be displayed in the function list twice for the same Subroutine, I tried in vain to fix it. I can produce examples here if some of you are interested and may want to help to find a solution.

Anyway, hope this is helpful for some of you who are using Notepad++ to do ahk scripting. ( I am a total newbie to Notepad++ as well )

There is a bug in the userLangDefine.xml which affecting the folding capability, I have no idea how to modify the userLangDefine.xml.

Use the following example, load into your Notepad++

If RadUpdateOnClick {
	;dosomething
}Else { ; dosomethingelse


}

;;;add a whole bunch of code afterwards
string2 = {
	string1 := "{"

	;MsgBox % StrLen(string2) StrLen(string1)

	If(string1=string2)
		MsgBox,  They are the same
}	

What is going to happen is, the if block will include everything afterwards as if they are all on the same block. After many trial and error, I found out, if you leave a space between } and Else, the problem disappears. Go ahead and try it for yourself.

Anyway, these are my 2 cents for the community.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks for your contribution,
I considering to use NPP. When that time comes, I will use your files.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.