Community
    • Login

    Some functions not shown in function list

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 4 Posters 132 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.
    • C BaccaC
      C Bacca
      last edited by C Bacca

      Notepad++ v8.7.7 (64-bit)
      Build time : Feb 6 2025 - 03:19:13
      Path : C:\USERNAME\Editors\Notepad++\notepad++.exe
      Command Line : test.py
      Admin mode : OFF
      Local Conf mode : ON
      Cloud Config : OFF
      Periodic Backup : ON
      Placeholders : OFF
      DirectWrite : OFF
      Multi-instance Mode : monoInst
      File Status Auto-Detection : cdEnabledNew (for current file/tab only)
      Dark Mode : OFF
      OS Name : Windows 10 Pro (64-bit)
      OS Version : 22H2
      OS Build : 19045.5854
      Current ANSI codepage : 1252
      Plugins :
      AutoSave (1.6.1)
      mimeTools (3.1)
      NppConverter (4.6)
      NppExport (0.4)
      NppSnippets (1.6)

      I use Notepad++ on Windows 10.

      In my main program “cntpidtype.py” I have one function “readxppfileloop” that does not show up in the function list in a sidebar on the right side of Notepad++. Above that function is a function “make filenameprefix” which shows up in the function list. Below it is a function “readxpponefile” and that shows up.

      1. When I turn on to see all hidden characters I just see normal CRLF and nothing unusual before the problem function “readxppfileloop”.
      2. I had this problem with an older version of NPP and updating it to a Feb 2025 version fixed it.
      3. If I copy and paste into another file called “test.py” the problem function “readxppfileloop” does not appear either. This tells me something may be funky with “makefilenameprefix” but I don’t know what it is. Here’s my test.py file. This is missing imports so it will not run. The program actually runs fine.
      4. I have also tried closing the file (and leaving NPP open) and reopening the file and the one function still does not appear in the function list.
      5. I don’t have any problems with any other functions in any other .py files. So there is something funky about this file perhaps.
      6. I have just used the NPP search to look for high ascii characters using regex and [\x80-\xff] and found none.

      You can try and copy and paste this code into your own NPP and see if “readxppfileloop” appears in the function list.

      
      #####################################################
      def makefilenameprefix(options, filetype): 
          r'''Make filename prefix for error log and Excel files.
          In: options = global options
              ftype = text to put before anything else in filename.
          Out: Prefix of a filename not including any file extension. 
          '''
          procname = str(inspect.stack()[0][3]) + ":"
          
          fnout = os.path.join(options.donedir,filetype)
      
          return fnout
          
          
      #####################################################
      
      def readxppfileloop(options):
          
          r"""Loop through options.inputfilelist to read each XPP ascii file.
          """
          procname = str(inspect.stack()[0][3]) + ":"
          
          allfiles = [] # Contents of sys.argv[1]
      
          with open(options.inputfile, 'r') as file: # "file" is file handle object.
              allfiles = file.readlines() # Read all lines into a list. 
          cnt = len(allfiles)
      
          for filename in allfiles: 
              filename = filename.strip()
              if filename[:1] != '#': # Ignore comments
                  readxpponefile(options, filename) # Read and process one XPP file.
          
          
      
      #####################################################
      def readxpponefile(options, filename):
          
          r""" Read one XPP file and count PID macros in it."""
          procname = str(inspect.stack()[0][3]) + ":"
          print(f"\nReading {filename}") # Print blank line.
          
          prlines = []
          lin = ''
          lpos = 0
          zpos = 0
          macroarr = [] # One macro split as a list.
          pidcode = '' # One PID code from macroarr[0].
          
          tstr = '|'.join(sorted(options.pidmacrolist))
          pidre = r'(<(' + tstr + ');.+?>)'
      
          # infile = options.pricefilename
          if not os.path.exists(filename):
              print(f"{procname} ERROR: Price file {infile} does not exist.")
              sys.exit(1)
              
      

      How can I fix this?
      What should I look for?

      Thank you.

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @C Bacca
        last edited by

        @C-Bacca

        I do not have an solution but can confirm the behavior.

        12481c85-b476-4456-a1cc-b2d4fc1595cf-{61C2C14C-37C3-4E8A-9C2E-76389065E260}.png

        Now deleting the space at the end of makefilenameprefix solves it for me.

        24216b70-4146-424a-873b-f79734b8f659-{B8A132B1-2D68-48DA-84C0-F4F578A1190D}.png

        I think the regex gurus need to take a look at this.

        C BaccaC PeterJonesP 2 Replies Last reply Reply Quote 1
        • Alan KilbornA
          Alan Kilborn
          last edited by

          FWIW, I would never see this problem, because I use the editorconfig plugin and set it to remove trailing spaces upon save. I have it set to do this because I can’t think of a single reason that trailing spaces on lines are useful.

          C BaccaC 1 Reply Last reply Reply Quote 1
          • C BaccaC
            C Bacca @Ekopalypse
            last edited by

            @Ekopalypse I can confirm, removing that last space fixes it. I didn’t even see that space or thought it would matter.

            There’s some regex in a settings file somewhere for NPP that searches for function names. Can this be fixed to allow trailing spaces in the next NPP update?

            I don’t know where that file is right now.

            1 Reply Last reply Reply Quote 0
            • C BaccaC
              C Bacca @Alan Kilborn
              last edited by C Bacca

              @Alan-Kilborn Is there an option to remove trailing whitespace in generic NPP? I’m looking and haven’t found it yet.

              Can the author add that option to the generic NPP settings? There are 2 tabs for editor settings, “Editor 1” and “Editor 2”.

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @C Bacca
                last edited by Alan Kilborn

                @C-Bacca said:

                I didn’t even see that space

                And, that’s why it is best to have something in place that removes such things.

                Is there an option to remove trailing whitespace in generic NPP?

                Yes there is; on the Edit menu.
                There’s also a sample macro called “Trim Trailing Whitespace and Save” or something close to that, that conveniently does the action every time you save (well, every time you run the macro, which, if assigned to your favorite save-keycombo, e.g. Ctrl+s, will do it).

                Can the author add that option to the generic NPP settings?

                Well, the author could, but it is probably unlikely as the functionality already exists in a plugin as well as the sample macro.

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

                  @Ekopalypse said in Some functions not shown in function list:

                  I think the regex gurus need to take a look at this.

                  Actually, the python FunctionList definition regex is pretty simple:

                  • normal function: ^(async )?def\x20\K.+?(?=(:$|,$|:\s*#))
                  • function in class: \s(async )?def\x20\K.+?(?=(:$|,$|:\s*#))

                  The problem with both is that it requires the : or , to be the last character on the line (unless there’s a comment). If both are edited so the final lookahead is (?=(:\h*$|,\h*$|:\s*#)) (edit, save, exit NPP, restart NPP), then the original file, with the extra space, will work again.

                  Analysis: It turns out, because functionlist defaults to doing a .-matches-newline search, it is actually matching from def makefilenameprefix all the way to the ending : on the def readxppfileloop(options): line: this is why the makefilenameprefix made it into the function list, but readxppfileloop did not. (I think it actually means that there’s a multi-line string being sent to the FunctionList panel… but because it only displays one line per function, you don’t notice.)

                  If there had been an if xyz: line (or any other control structure that ended with :-then-EOL) somewhere inside makefilenameprefix(), then readxppfileloop would show up, too. So there was not only “bad luck” in having the space at the end of the line, and “bad luck” that whoever developed the original functionList regex for Python didn’t think to allow whitespace, but also “bad luck” that there wasn’t another control structure inside the function. Don’t go to your local casino until you’ve broken your “bad luck” streak. ;-)

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

                    @Alan-Kilborn said in Some functions not shown in function list:

                    There’s also a sample macro called “Trim Trailing Whitespace and Save” or something close to that, that conveniently does the action every time you save (well, every time you run the macro, which, if assigned to your favorite save-keycombo, e.g. Ctrl+s, will do it).

                    I used Ctrl+S remapped to Macros > Trim Trailing and Save for years before starting to use editorconfig – and actually I still use that mapping, because I don’t have a .editorconfig file at the root directory of all my drives, so there are still times when the editorconfig plugin doesn’t know to trim trailing for me. Since I almost exclusively use the keystroke vs the toolbar or menu command for my Save, I (almost) always get the trailing removed when I save.

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