Some functions not shown in function list
-
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.
- When I turn on to see all hidden characters I just see normal CRLF and nothing unusual before the problem function “readxppfileloop”.
- I had this problem with an older version of NPP and updating it to a Feb 2025 version fixed it.
- 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. - 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.
- I don’t have any problems with any other functions in any other .py files. So there is something funky about this file perhaps.
- 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.
-
I do not have an solution but can confirm the behavior.
Now deleting the space at the end of
makefilenameprefix
solves it for me.I think the regex gurus need to take a look at this.
-
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.
-
@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.
-
@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”.
-
@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.
-
@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 thedef readxppfileloop(options):
line: this is why themakefilenameprefix
made it into the function list, butreadxppfileloop
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 insidemakefilenameprefix()
, thenreadxppfileloop
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. ;-) - normal function:
-
@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.