Adding TCL to functionlist panel
-
Could somebody at notepad++ please add this by default to notepad++:
#!/usr/bin/perl use strict; use warnings; # Build the PowerShell script as an array, one line per element. my @ps; push @ps, '# Define the target file path.'; push @ps, '$filePath = "C:\Program Files\Notepad++\functionList\tcl.xml"'; push @ps, ''; push @ps, '# Check if the file already exists.'; push @ps, 'if (Test-Path $filePath) {'; push @ps, q{ $answer = Read-Host "File '$filePath' already exists. Do you want to overwrite it? (y/n)"}; push @ps, ' if ($answer -ne "y") {'; push @ps, ' Write-Output "Exiting without overwriting."'; push @ps, ' exit 0'; push @ps, ' }'; push @ps, '}'; push @ps, ''; push @ps, '# Define the XML content to write using a here-string.'; push @ps, '$xmlContent = @"'; push @ps, '<?xml version="1.0" encoding="UTF-8"?>'; push @ps, '<NotepadPlus>'; push @ps, ' <functionList>'; push @ps, ' <parser id="tcl_procedure" displayName="TCL" commentExpr="(#)">'; push @ps, ' <function mainExpr="^[\t ]*((proc)[\s]+)[^\s]+">'; push @ps, ' <functionName>'; push @ps, ' <nameExpr expr="(proc)\s+[\x21-\x7E]+" />'; push @ps, ' <nameExpr expr="\s+[^\s]+" />'; push @ps, ' </functionName>'; push @ps, ' </function>'; push @ps, ' </parser>'; push @ps, ' </functionList>'; push @ps, '</NotepadPlus>'; push @ps, '"@'; # End the here-string. Ensure this marker is on its own line. push @ps, ''; push @ps, '# Write the XML content to the file.'; push @ps, 'Set-Content -Path $filePath -Value $xmlContent -Force'; push @ps, q{Write-Output "File '$filePath' has been written successfully."}; # Write the PowerShell script to a file called tmp_install_npp.ps1. my $ps_filename = "tmp_install_npp.ps1"; open my $fh, '>', $ps_filename or die "Cannot open $ps_filename for writing: $!"; print $fh join("\n", @ps), "\n"; close $fh; # Optionally, execute the PowerShell script. my $exit_code = system("powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"$ps_filename\""); if ($exit_code != 0) { die "PowerShell script failed with exit code: " . ($exit_code >> 8) . "\n"; } exit 0; __DATA__ Script Name: npp_install_tcl.pl Description: This Perl script is designed to create or update the TCL parser XML file used by Notepad++ to populate its Function List panel with TCL “proc” function definitions. Notepad++ utilizes this XML configuration (located in its “functionList” directory) to parse source files and display a list of functions, enabling easier navigation within code. Functionality: 1. The script targets the file “C:\Program Files\Notepad++\functionList\tcl.xml”. If this file already exists, the script prompts the user for permission to overwrite it. 2. It defines the XML content that includes the regex-based rules for detecting TCL procedure definitions (i.e., lines starting with the ‘proc’ keyword), which will then appear in Notepad++'s Function List. 3. After handling the file existence check and user confirmation, it writes the XML content to the file, effectively updating or installing the parser. Usage: - Ensure you run this script in an environment where you have write access to the Notepad++ installation directory. - Execute the script from the command line: perl write_tcl_parser_xml.pl - Follow any on-screen prompts regarding overwriting the existing file. Notes: - It is recommended to close Notepad++ before running this script to avoid any potential conflicts or file access issues. - Modify the file path if your Notepad++ installation is in a different location.
-
@Bill-M ,
A Perl script to create a powershell script to create and copy an XML file? That seems a bit indirect. If you’re going to invoke the perl interpreter, why not have your Perl code write the XML to the right location directly? And if you don’t know how to accomplish the same thing in Perl (which it definitely can do), why not just share the powershell script directly instead of “dynamically” generating it using static strings in Perl?
But that’s neither here nor there, so nevermind.
Could somebody at notepad++ please add this by default to notepad++:
The script is obviously not going to be added to Notepad++, nor anything that behaves like that script. If you wanted to take the XML that’s generated by your nested script and have that functionList XML added to the Notepad++ distribution by default, the User Manual has an entire section on how to "Contribute your new or enhanced parser rule to the Notepad++ codebase. So follow those instructions if you want Notepad++ to ship with your TCL functionList definition.