Text filters can be written in scripting languages such as Python, PHP and awk. Selected text can be filtered through them to perform edits which TextPad cannot do natively. Any script or program which reads from stdin and writes to stdout can be employed. Anything written to stderr will appear in the Tool Output window.
The following screenshots show how to add a text filter written in PHP and then run it on a selected column of numbers to calculate their total.
Add a filter:
1-AddFilter.png (33.14 KiB) Viewed 6039 times
Select a scripting language:
2-SelectPHP.png (46.05 KiB) Viewed 6039 times
Give it a meaningful name:
3-RenameFilter.png (24.86 KiB) Viewed 6039 times
Apply it:
4-ApplyFilter.png (25.47 KiB) Viewed 6039 times
Specify the script in the Parameters box then click OK:
5-SpecifyScript.png (20.7 KiB) Viewed 6039 times
This the sample script in PHP: (it's in TextPad's Samples folder.)
6-PHPscript.png (17.91 KiB) Viewed 6039 times
Select the column in block mode and run the script:
# PrettifyJson.py
# Pretty prints JSON.
# Select all before running it as a filter.
from sys import stdin
import json
obj = json.load(stdin)
prettyobj = json.dumps(obj, indent=4)
print(prettyobj)
This script is installed in TextPad's Samples folder.
Python can be installed from the Windows App Store.
Awk is a powerful scripting language which has been around since the early days of Unix. It can do a surprising amount in a single line, as this example to delete consecutive duplicate lines in a document shows. The script in the Parameters field is "!a[$0]++".
Screenshot 2024-06-08 163556.png (20.56 KiB) Viewed 6016 times
Awk can be installed with Google's Chocolatey using "choco install awk".
(Note that duplicate lines can also be deleted by searching for the regular expression "^(.+)$\n\g1" and replacing it with "$1". However, this will require multiple passes if lines are duplicated more than once.)