Community
    • Login

    How Notepad++ selects autocomplete?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    17 Posts 3 Posters 3.3k 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.
    • PeterJonesP
      PeterJones @gusztavj
      last edited by PeterJones

      @gusztavj ,

      The auto-completion selected should be based on the active Language-menu selection (the syntax highlighter selected).

      For getting it to work for you: First, the *.config.txt is adding complication. Get everything working without that weird naming convention first, before trying the complicated multi-level extensions.

      Let’s start with the simpler situation, where I want a “weirdAl” filetype with the extension .wa. First, I created my UDL, and gave it three keywords: thisKeywordIsJustSixWordsLong and itsChristmasAtGroundZero in group 1, and grapefruitDiet in group 2

      I did an Export of my UDL into the userDefineLangs folder (so it ends up in the folder, rather than the old-style userDefineLang.xml containing all of them), and then clicked Remove (so that there wouldn’t be conflicting versions in both the old file and the new subfolder). Exiting Notepad++ and restarting shows that the weirdAl UDL is still there. If I create a file, assign that Language>weirdAl, it properly syntax highlights. Save it as example.wa and close it.

      Next step: creating the weirdAl.xml that goes in autoCompletion\ folder.

      <?xml version="1.0" encoding="UTF-8" ?>
      <NotepadPlus>
      	<AutoComplete language="weirdAl">
      		<Environment ignoreCase="no" startFunc="(" stopFunc=")" paramSeparator="," terminal=";" />
      		<KeyWord name="thisKeywordIsJustSixWordsLong" />
      		<KeyWord name="itsChristmasAtGroundZero" />
      		<KeyWord name="grapefruitDiet" func="yes">
      			<Overload retVal="" descr="eat only grapefruit">
      				<Param name="Seedless" />
      			</Overload>
      			<Overload retVal="" descr="eat only grapefruit">
      				<Param name="Shape" />
      				<Param name="Season" />
      			</Overload>
      		</KeyWord>
      	</AutoComplete>
      </NotepadPlus>
      

      Save that file. Exit Notepad++. Restart.

      Open example.wa: it auto-recognizes as weirdAl filetype! Success #1.

      Start typing one of the three keywords, and it starts normal autocompletion! Success #2.

      Type grapefruit(, and it pops up the parameter auto-complete! Success #3. Here’s a screenshot.

      <INSERT>

      Now we know that the UDL is working correctly, as is the weirdAl auto-complete.

      Create a new file, called example.notwa, so it doesn’t have the right extension, and manually choose Language>weirdAl. Type the grap and it asks for auto-complete; complete it, type the (, and it prompts for the parameters: so auto-complete is fully recognized no matter the file extension, as long as the right UDL is selected. Success #4.

      At this point, if you open config.txt or *.config.txt and manually assign your UDL, you should be confident that it will auto-complete correctly.

      So now it’s a matter of auto-recongizing your weird *.config.txt.

      In my example, I will use wa.txt and *.wa.txt. In the UDL extension field, I added wa.txt so its value is wa wa.txt … Create a new file, and save as wa.txt. To my surprise, it successfully immediately applied weirdAl as the Language, and auto-completed. Nearly done!

      File > New, and save as blah.wa.txt. It considers it a normal text file rather than a weirdAl file. Failure #1.

      I don’t think you’re going to be able to auto-recognize *.config.txt – at least, I couldn’t, with *.wa.txt .

      If you are willing to install the PythonScript plugin, you can have it check the active filename whenever you activate a buffer, and have it change the language to the right UDL if the name ends in .config.txt … If you are willing to do that, and need help, let us know.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @PeterJones
        last edited by

        @PeterJones said in How Notepad++ selects autocomplete?:

        <INSERT>

        Sorry, I meant to paste my image there:

        c112319c-5289-410a-ba98-e7c6079ef7d9-image.png

        1 Reply Last reply Reply Quote 0
        • gusztavjG
          gusztavj
          last edited by

          Peter, I can’t tell what grateful I am for your extensive and clear reply!

          So, everything works fine, but the autocomplete fails… :) I’m just showing you a few screens, probably you can spot some error I did not manage to recognize.

          To check if folder locations are fine, here’s the UDL folder:
          My UDL folder

          I don’t have userDefineLanguage.xml at all (deleted it beforehand).

          And the autocomplete folder:
          The autoComplete folder

          This one is my UDL file with the relevant parts:
          UDL contents

          And the autocomplete:
          Autocomplete file

          And this shows the example file with syntax recognized, but autocomplete not working (although it’s turned on and works for other langs):
          Example file

          Can you find any discrepancies here? I’ve exited and restarted Notepad++ after every operation as you also suggested.

          Stay safe,
          Gus

          PeterJonesP 1 Reply Last reply Reply Quote 2
          • PeterJonesP
            PeterJones @gusztavj
            last edited by

            @gusztavj said in How Notepad++ selects autocomplete?:

            Can you find any discrepancies here?

            Sorry, everything looks right.

            Did you re-start Notepad++ after putting the UDL and autoCompletion XML files in the right folders?

            Could you screenshot your Settings > Preferences > Auto-completion settings?

            Could you copy/paste your ?-menu’s Debug Info?

            PeterJonesP 1 Reply Last reply Reply Quote 2
            • PeterJonesP
              PeterJones @PeterJones
              last edited by PeterJones

              @PeterJones said in How Notepad++ selects autocomplete?:

              Did you re-start Notepad++ after putting the UDL and autoCompletion XML files in the right folders?

              Sorry, I re-read and saw you’d already answered that one.

              The more I thought about this not working for you, the more confused I got. I don’t see why it wouldn’t be working… if you’re in a version of Notepad++ new enough that it comes with the autoCompletion\ folder (it used to be named something else), then all the syntax shown should work.

              I decided to bundle up a zipfile of my working portable version. So for the next week or so, the URL URL REDACTED will download a zipfile with a complete portable, including my autoCompletion\weirdAl.xml and userDefineLangs\weirdAl-udl.xml. When I unzip these to a known writeable location, then run the portable notepad++.exe from the unzipped folder, if I use Ctrl+Shift+Space inside the grapefruitDiet() parentheses, it pops up the parameter-hint auto-completion, and if I start typing the t, i, or g that start the three function keywords, the function-name auto-completion pops up. Since the portable zip contains all the config files including sessions, etc, you should be in a state to immediately test this working copy after unzipping.

              cf4f6886-24a9-4bf7-81d7-ca23076729b0-image.png

              caveat

              It’s always dangerous to download files from unknown sources. I am claiming that I haven’t done anything malicious in this zipfile, but you need to use download wisdom. It is my recommendation to at the very least run a virus checker on the zipfile and the unzipped contents.

              Future Readers: The download will go away in the near future, so you will likely get 404-not-found.

              gusztavjG 1 Reply Last reply Reply Quote 2
              • gusztavjG
                gusztavj
                last edited by

                Thanks for the response again. I have NP++ 7.9.5, and here are my autocomplete settings, seemingly the same as yours:

                Autocomplete settings

                The portable version just works fine. I’ll try to add my files to the portable instance and see if it works, and let you know about it.

                Cheers,
                Gus

                1 Reply Last reply Reply Quote 1
                • gusztavjG
                  gusztavj @PeterJones
                  last edited by

                  @PeterJones, this is what I found: autocomplete does not work if the language, as defined in the UDL file, contains keywords with a hyphen in it. The actually weird language for what I wanted to create an autocomplete file includes lot of keywords of this kind, such as “category-keyword”. For these, no autocomplete tip will pop up. Even worse, the values of these so-called tags are followed by a space, so a line of the file looks like this:

                  category-keyword “value”
                  or
                  position 0, 1, 0

                  Now it would be okay to type a ( character after a tag name to display the hint, but the hyphen makes this language incompatible with the auto-complete logic. :(

                  Anyway, thanks a lot for your efforts in explaining this whole situation.

                  Michael VincentM 1 Reply Last reply Reply Quote 1
                  • Michael VincentM
                    Michael Vincent @gusztavj
                    last edited by

                    @gusztavj said in How Notepad++ selects autocomplete?:

                    autocomplete does not work if the language, as defined in the UDL file, contains keywords with a hyphen in it.

                    That should be an easy fix. In the autoCompletion\weirdAl.xml file, add the additionalWordChars="-" parameter like so:

                    <?xml version="1.0" encoding="UTF-8" ?>
                    <NotepadPlus>
                            <AutoComplete language="weirdAl">
                                    <Environment ignoreCase="no" .....   additionalWordChars="-"/>
                                    <KeyWord name=" ...
                    

                    I have an autoCompletion file for Powerwhell and most Powershell commands are Verb-Thing (e.g., Write-Host, Get-Item) so I include the additionalWordChars="-" and it works for me.

                    Cheers.

                    gusztavjG 1 Reply Last reply Reply Quote 4
                    • gusztavjG
                      gusztavj @Michael Vincent
                      last edited by

                      @Michael-Vincent said in How Notepad++ selects autocomplete?:

                      That should be an easy fix.

                      I wish it were! :) First, thanks for mentioning this attribute. I took a look at the source code, but did not recognized it. But unfortunately it still does not work for me. Here is my piece of code, the AC file:

                      <?xml version="1.0" encoding="UTF-8" ?>
                      <NotepadPlus>
                          <AutoComplete language="weirdAl">
                              <Environment ignoreCase="yes" startFunc="(" stopFunc=")" paramSeparator="," terminal=";" additionalWordChars="-"/>
                      	<KeyWord name="grapefruit-diet" func="yes">
                                <Overload retVal="" descr="drink grapefruit juice only">
                                  <Param name="SeedlessStuff" />
                                </Overload>
                                <Overload retVal="" descr="drink grapefruit only">
                      	    <Param name="Shapes" />
                      	    <Param name="Seasons" />
                                </Overload>
                      	</KeyWord>
                      	<KeyWord name="position" func="yes">
                                <Overload retVal="" descr="elements's position">
                                  <Param name="on x axis" />
                                  <Param name="on y axis" />
                                  <Param name="on z axis" />
                                </Overload>
                      	</KeyWord>		
                      	<KeyWord name="grapefruitDiet" func="yes">
                      	  <Overload retVal="" descr="eat grapefruit only">
                      	    <Param name="Seedless" />
                      	  </Overload>
                      	  <Overload retVal="" descr="eat grapefruit only">
                      	    <Param name="Shape" />
                      	    <Param name="Season" />
                      	  </Overload>
                      	</KeyWord>
                          </AutoComplete>
                      </NotepadPlus>
                      

                      It works for grapefruitDiet and position, but doesn’t offer anything for grapefruit-diet.

                      Am I overlooking something?

                      Cheers.
                      Gus

                      Michael VincentM 1 Reply Last reply Reply Quote 0
                      • gusztavjG
                        gusztavj
                        last edited by

                        A small clarification: it offers the name grapefruit-diet, but does not show the overloads, so nothing appears after typing the bracket, pressing CTRL+SPACE or CTRL+SHIFT+SPACE.

                        1 Reply Last reply Reply Quote 0
                        • Michael VincentM
                          Michael Vincent @gusztavj
                          last edited by

                          @gusztavj said in How Notepad++ selects autocomplete?:

                          Am I overlooking something?

                          Looks good, but I thought keywords needed to be in alphabetical order?

                          Cheers.

                          gusztavjG 1 Reply Last reply Reply Quote 0
                          • gusztavjG
                            gusztavj @Michael Vincent
                            last edited by

                            @Michael-Vincent , tried to move them around, to place grapefruitDiet before grapefruit-diet and the other way around, but with no effect. grapefruitDiet is always recognized, the other is never recognized. :( Became clueless again. Yet, thanks for your help and tips.

                            1 Reply Last reply Reply Quote 1
                            • gusztavjG
                              gusztavj
                              last edited by

                              And finally… I did not find the documentation page at https://npp-user-manual.org/docs/auto-completion/, only a link to a non-existing page. Now that I know the AC file needs to be named after the language name, life is much happier… :D

                              Thanks for all your great help!

                              PeterJonesP 1 Reply Last reply Reply Quote 0
                              • PeterJonesP
                                PeterJones @gusztavj
                                last edited by

                                @gusztavj said in How Notepad++ selects autocomplete?:

                                And finally… I did not find the documentation page at https://npp-user-manual.org/docs/auto-completion/, only a link to a non-existing page.

                                That page exists (I even just checked using your exact link). Maybe you encountered a brief time when there was a server problem…

                                gusztavjG 1 Reply Last reply Reply Quote 0
                                • gusztavjG
                                  gusztavj @PeterJones
                                  last edited by

                                  @PeterJones Yes, it works, but beforehand I found a different link that was not working. :)

                                  1 Reply Last reply Reply Quote 0
                                  • gusztavjG
                                    gusztavj
                                    last edited by

                                    @PeterJones and @Michael-Vincent, would you mind if I summon you to see a new post of mine to see if you have an idea for another autocomplete issue? It’s different from this one and I did not want to mess up this thread with a different issue.

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