@Alan-Kilborn
With your script as inspiration, I made one that has a different custom search func for each file, allows the user to set the search func with selected text, and the user can choose whether or not to bookmark lines.
[image: 1684507554720-63ddf9b8-22a9-411a-8448-33a055dcf3fa-image.png]
# -*- coding: utf-8 -*-
# references:
# https://community.notepad-plus-plus.org/topic/24481
from Npp import *
import operator
import re
# Too lazy to parse config files; just modify these global variables instead
BOOKMARK_LINES = True
class FBOLTN:
def __init__(self):
self.set_comparator()
def set_comparator(self):
comparator_regex = re.compile("([><]=?|=)(-?\d+)")
sel = editor.getSelText()
mtch = comparator_regex.search(sel)
if mtch: # user is selecting a new comparator
compstr, numstr = mtch.groups()
num = int(numstr)
else:
if hasattr(self, 'comparator'):
return # only override current comparator with valid selection
# default is what the OP wanted
compstr = '>='
num = 25
self.compstr = compstr
self.num = num
def comparator(other_num):
fun = {
'>': operator.gt,
'<': operator.lt,
'=': operator.eq,
'>=': operator.ge,
'<=': operator.le,
}[compstr]
return fun(other_num, num)
self.comparator = comparator
def custom_match_func(self, m):
if self.stop: return
i = int(m.group(0))
start, end = m.start(0), m.end(0)
if self.comparator(i):
editor.setSel(start, end)
if BOOKMARK_LINES:
notepad.menuCommand(MENUCOMMAND.SEARCH_TOGGLE_BOOKMARK)
self.stop = True
def search(self):
self.stop = False
editor.research(r'(?<!\w)-?\d+\b', self.custom_match_func, 0, editor.getCurrentPos())
if __name__ == '__main__':
try:
fboltns
except NameError:
fboltns = {}
cur_fname = notepad.getCurrentFilename()
if not fboltns.get(cur_fname):
fboltns[cur_fname] = FBOLTN()
fboltn = fboltns[cur_fname]
fboltn.set_comparator()
fboltn.search()