Community
    • Login

    AutoComplete keywords starting with symbols (#, @, $)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 6.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SmokeyWareS
      SmokeyWare
      last edited by

      I have a autoit.xml file in my notepad++\plugins\APIs folder and it has some of the following keywords defined:

      	<KeyWord name='#include' />
      	<KeyWord name='#NoTrayIcon' />
      	<KeyWord name='@DesktopWidth' />
      	<KeyWord name='@MyDocumentsDir' />
      

      However i cannot get these entries to pop up in autocomplete when i type # or @.
      I have the same problem with $, it doesn’t allow word completion (from the current document).
      Am i missing something here?
      Otherwise autocomplete is working fine, it even show function parameter hints from the autoit.xml file.

      When i type # or @, i just want to be able to see all keywords defined in the api file starting with that character.
      Is this possible?

      1 Reply Last reply Reply Quote 0
      • Jim DaileyJ
        Jim Dailey
        last edited by

        @SmokeyWare You can try adding these characters to the additionalWordChar string in the XML file, but I’m not sure it will work:

        <Environment ignoreCase="no" startFunc="(" stopFunc=")" paramSeparator="," terminal=";" additionalWordChar=".#@$" />
        
        1 Reply Last reply Reply Quote 0
        • SmokeyWareS
          SmokeyWare
          last edited by

          Sadly adding the additionalWordChar doesn’t seem to do anything.
          Thanks for the suggestion!

          Maybe there is something wrong with the autoit.xml file?
          If anyone wants to have a look, it’s here

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @SmokeyWare
            last edited by

            Hello @SmokeyWare,

            from the doc

            Following is a list of <KeyWord> tags. They are either auto-closing, for keywords that are not routines, or not when they are. Each such tag has a mandatory “name” attribute, the keyword/routine name to recognise. The list must be sorted according to this attribute and the value of the <Environment> ignoreCase attribute. See subsections below for more on keyword names and sorting.

            and

            NOTE: Spaces can’t be used as the character for the attributes and additionalWordChar is still not working (Notepad++ v.6.5.2) but maybe in future releases…

            Nevertheless you can make it work by installing python script plugin and using the startup.py to add the additional chars
            everytime an au3 file gets activated. If you need help solving this let me know.

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • SmokeyWareS
              SmokeyWare
              last edited by

              Hi @Claudia-Frank, thanks for your reply.

              I managed to get it semi-working, but you wouldn’t believe how much trouble i had.

              First of all, installing the python script plugin from the plugin manager doesn’t work.
              The install doesn’t include the Notepad++\plugins\PythonScript\lib folder for some reason and upon starting Notepad++ you will be greeted be a very helpfull “Unidentified Exception” message.
              So i installed PythonScript with the official installer, got that to work.

              Next up was the actual script…
              I really want to like Python but the documentation is terrible, but maybe i’m spoiled with the MSDN library.
              Also trying to find syntax errors is a massive pain, because i forgot to close a tag somewhere and spent 30 min to find out why my if statement gave an error.

              Here’s my script so far:

              from Npp import *
              
              def setEditiorOpts(args):
              	console.write("Buffer Activated %d\n" % args["bufferID"])
              	# check if this editor already has the WordChars set
              	if editor.getProperty("_isOptionsSet"):
              		return
              
              	editor.autoCSetIgnoreCase(True) # doesn't do anything :'(
              	# get current WordChars and append additional chars
              	chars = editor.getWordChars() + "@#$"
              	# set new WordChars
              	editor.setWordChars(chars)
              	console.write("Set WordChars to: \n" + editor.getWordChars() + "\n")
              	# set a flag in this editor instance to prevent future calls
              	editor.setProperty("_isOptionsSet", True)
              
              console.show()
              # manually call because callback will not be run upon start
              setEditiorOpts({"bufferID": notepad.getCurrentBufferID()})
              # register callback to be called whenever the current window changes
              notepad.callback(setEditiorOpts, [NOTIFICATION.BUFFERACTIVATED])
              

              My only remaining problem is the $ symbol (dollar sign).
              Currently when i type a $ it will not show any autocomplete entries, even when i enter characters after the $.
              If i remove $ from the WordChars, autocomplete will pop up if i type anything after $.

              I believe this is because NP++ has 2 autocomplete modes, word completion and function completion.
              Where function completion is defined in the api file (works now with @ and #)
              And word completion, where it gets its entries from the current document (doesn’t work with $, infact adding $ to WordChars breaks it completely)

              Any ideas anyone?
              I feel like maybe i should give up on NP++ and use a proper IDE instead (VS).
              Sorry if i seem a bit salty, but already i have spent too many hours trying to achieve the impossible.

              Claudia FrankC 1 Reply Last reply Reply Quote 0
              • Claudia FrankC
                Claudia Frank @SmokeyWare
                last edited by

                Hi @SmokeyWare,

                didn’t do a fresh install with all of my plugins lately, surprises me that installation was not working
                for the first time but good to see that you got managed it.
                To be honest, I didn’t see any API documentation which can be compared to MSDN.
                You can say what you want about MS but when it comes to documentation they aren’t bad.
                Maybe not fully documented but what they document is mostly good.

                Your script is great - did you just start with Python? I guess you do have programming skills, do you?

                The script itself does work as long as you do not need different handling for different languages.
                The first line, the import statement, isn’t needed because PythonScript itself imported it already.
                The autoCSetIgnoreCase doesn’t seem to change behavior you are right, maybe it gets
                overriden by the ignoreCase parameter of the API xml file.

                So, I assume its your API file which prevents it to work propably. As I downloaded it and tested
                it, it didn’t work too. So I sorted it and it was done - it is working now.

                The code to do the sorting is

                import xml.dom.minidom as _xml
                
                dom = _xml.parse(r"D:\Temp\autoit.xml")
                nodes = dom.getElementsByTagName('KeyWord')
                nodes.sort(key=lambda x: (x.attributes['name'].value).upper())
                for node in nodes:
                    print node.toxml('utf-8')
                

                Of course you need to change the path and the
                NotepadPlus, AutoComplete and Environment tags aren’t included.

                I ran this outside npp in a cmd with output redirected to a file.

                Regarding comparing VS and npp is a bit unfair, isn’t it.
                What I did to make npp a better python IDE is to use startup.py
                and filesaved callback to let astviewer, flakes etc. check my code.
                This results in, mostly, better error messages.

                D:\temp\failure.py:4:42: invalid syntax
                    if editor.getProperty("_isOptionsSet":                                         ^
                *** print_exc:
                Traceback (most recent call last):
                  File "D:\ProgramData\Notepad++\plugins\Config\PythonScript\scripts\nppIDE\ASTViewer.py", line 515, in parse_code
                    t = ast.parse(open(source_file).read(),source_file)
                  File "D:\ProgramData\Python\Python27\Lib\ast.py", line 37, in parse
                    return compile(source, filename, mode, PyCF_ONLY_AST)
                  File "D:\temp\failure.py", line 4
                    if editor.getProperty("_isOptionsSet":
                                                         ^
                SyntaxError: invalid syntax
                

                Cheers
                Claudia

                SmokeyWareS 1 Reply Last reply Reply Quote 0
                • SmokeyWareS
                  SmokeyWare @Claudia Frank
                  last edited by

                  Hi @Claudia-Frank ,

                  thanks for the help again!

                  I have had trouble with the plugin manager before, but it’s no big deal as long as google is still around.
                  And the Python documentation isn’t a big problem either, again google will have all the answers ;P

                  I did look into Python before as i have a Raspberry Pi, but i have never really done anything with it.
                  Most of the time i write simple programs in C#, getting spoiled by MSDN and Intellisense, hehe.

                  Your suggestion works great tho, typing @ or # shows all entries in the api file and those from files i import in the script i’m writing.
                  I only wish i could start typing in lowercase and get Properly Cased autocomplete entries. I figured that editor.autoCSetIgnoreCase(True) would do this but i might be wrong.
                  Also inside the api file the ignoreCase attribute is set to ‘yes’ so it might be a scintilla or npp limitation?
                  I might just have to adjust my typing style and not be so lazy ;P
                  But i will try sorting the api file tho. (when i have more time)

                  Considering autocompleting autoit variables (starting with $) it works ok if i leave $ out of the AdditionalWordChars, i just have to type the first character after the $ and it pops up.

                  Comparing VS and npp is like comparing apples and oranges (or as we say in Holland, apples and pears) especially considering the sheer manpower behind VS.
                  I didn’t mean to bash npp but i was just a bit annoyed by the trouble i had. Maybe i should have waited a bit before posting.
                  Npp is great with all the features and plugins, it puts regular notepad to shame.
                  Besides, writing Python in VS isn’t that much better anyway and i still have a lot to learn.

                  I definitely see you can do some interesting things with the PythonScript plugin, i’ll have to look into that. And it’s documented pretty well too.
                  Thanks!

                  If anyone’s interested here’s the script: (fixed)

                  def setEditiorOpts(args):
                  	# check if this editor already has the WordChars set
                  	if editor.getProperty("_isOptionsSet"):
                  		return
                  
                  	# get current WordChars and append additional chars. add any character you like here, but they may not all work
                  	chars = editor.getWordChars() + "@#"
                  	# set new WordChars
                  	editor.setWordChars(chars)
                  	# set a flag in this editor instance to prevent future calls
                  	editor.setProperty("_isOptionsSet", True)
                  
                  # manually call because callback will not be run upon start
                  setEditiorOpts({"bufferID": notepad.getCurrentBufferID()})
                  # register callback to be called whenever the current window changes
                  notepad.callback(setEditiorOpts, [NOTIFICATION.BUFFERACTIVATED])
                  

                  (the forum doesn’t want to format the comments properly anymore?)

                  It’s possible to detect the current language with editor.getLexerLanguage(), it returns the current language as a string.
                  Or maybe you can use NOTIFICATION.LANGCHANGED instead of NOTIFICATION.BUFFERACTIVATED, but i haven’t looked into that.

                  Happy Holidays!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors