• Search a number grater than

    9
    0 Votes
    9 Posts
    3k Views
    Mark OlsonM

    @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.
    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()
  • Appropriate command to change lines using regular expressions

    9
    1 Votes
    9 Posts
    546 Views
    J

    @guy038 I didn’t have the chance to thank you very much for your support! It worked very well!

  • Need help deleting any text between other text

    3
    0 Votes
    3 Posts
    495 Views
    ImgemaI

    Thank you!

  • Delete lines beginning with X to ending with Y

    4
    0 Votes
    4 Posts
    1k Views
    Robert OramR

    Thank you so much for your prompt help! They both work perfectly!

    Bob

  • Underlining links.

    10
    0 Votes
    10 Posts
    771 Views
    Lycan ThropeL

    @rdipardo ,
    Here’s a perfect example, of what I mean. From my Mother in law, I learned to say that backwards, Bardzo dziękuję. Been a while since the course, so I can’t challenge the translator, but that’s the point. :-)
    It’s dependent on the translation and how it’s getting done. ;)

  • Sélectionner le texte marqué / Select marked Text

    18
    0 Votes
    18 Posts
    4k Views
    Denis AdraD

    Hey hi @guy038 , I’m coming back to you

    It’s been a busy day between yesterday and today.

    Thanks for the new information. The method you propose is very interesting. Longer and a little more complicated than @Terry-R 's but in the end safer because it is true that when you finalize, there are no mistakes left. Where it can often remain with a numbering system that by dint of being cut and pasted and even sometimes unexpectedly taken in the selection that will pass to the translation, it happens that it gets mixed with the paragraphs. In the end, the time I save with the numbering system, I often lose later to detect and correct the mistakes. Note, this is entirely my fault because I could have or should have made a selection in columns.

    In order not to let your help and efforts go to waste, I used your method on the 10 or so small files I had left and it works very well. Many thanks to you!

    A huge thank you also to @Terry-R , because his method arrived quite quickly. At a time when I was more than tired of editing a 400k file by hand and wanted to give up more than once!

    Finally, thank you all for all this advice @guy038 @Terry-R @PeterJones . As I said before, I am not an expert in notepad++ at all. I’ve done a degree in computer science 15 years ago, but I’m not at all specialized in programming and I’m doing totally different things today. I found all these little tips very interesting and I’m sure they will be very useful in the future. Thanks again to both of you!

    I’ve completely finished the translation, for the rest I’ll only have to touch up the fonts and make corrections that I would have noticed in game.

  • 0 Votes
    6 Posts
    3k Views
    Mark OlsonM

    I like the solutions proposed above because they are relatively simple and to-the-point. However, regex-replaces on JSON in general get pretty hairy due to factors including but not limited to:

    how do you differentiate between a pattern in a key versus a string? how do you take into account the fact that JSON doesn’t care about the order of keys whereas regexes do? what if there are ] or } inside strings, such that the regex is fooled into thinking the JSON object ended?

    Just to illustrate how annoying regex-replaces get once you start trying to satisfy all the syntactic requirements of JSON, here’s a regex-replace I came up with to achieve this while ignoring insignificant whitespace and the order of keys and removing any trailing commas:
    find/replace (?-i),\s*{(?:[^{]*{[^}]*}\s*,\s*"model"\s*:\s*"[^"]*KeepInfo[^"]*"\s*|\s*"model"\s*:\s*"[^"]*KeepInfo[^"]*"[^{]*{[^}]*}\s*)}\s*(,)? with \1.

    JsonTools is a fine solution for this, if you’re able to use plugins.

    Because it uses a JSON parser to parse the JSON, it is insensitive to the formatting of the JSON.

    To filter JSON with the plugin, just use Alt-P-J-J (tap the keys in sequence, don’t hold them down simultaneously) to open the tree view, then enter one of the following queries into the query box and hit Ctrl+Enter, then Save query result.
    Two queries that accomplish your goals:
    @[:][not(@.model =~ `(?i)keepinfo`)] filters out objects where the model includes keepinfo ignoring case.
    @[:][not(@.model =~ KeepInfo)] filters out objects where the model includes KeepInfo in that case only.

    While I’m here, PythonScript is also an efficient solution:

    import json from Npp import editor j = json.loads(txt) filtered = [o for o in j if 'KeepInfo' in o['model']] filtered_text = json.dumps(filtered, indent=4) editor.setText(filtered_text)
  • Delete entries and unknown amount of brackets

    3
    2 Votes
    3 Posts
    209 Views
    Felix LF

    @Alan-Kilborn You’re just awesome dude, thank you very much. Works like a charm.

  • Comment on FAQ post about 8.5.3 macros

    2
    0 Votes
    2 Posts
    457 Views
    PeterJonesP

    @mkupper ,

    Ugh. Apparently, like backslash-square-brackets, HTML entities are another thing that NodeBB messes up when you edit a post, because it was right when I first posted it. Fixed. (edit: updated the forum-formatting FAQ to call out that oddity with entities, as well)

    Regarding DM: the “chat” feature speech bubble in the upper-right by your icon is the way to do private messages
    d3a7bd64-4296-4f8b-a302-820992061b17-image.png

  • Automate Notepad++ new doc creation

    8
    0 Votes
    8 Posts
    844 Views
    mkupperM

    @Chris-Johnston In reading https://www.autoitscript.com/forum/topic/210204-automate-notepad-new-doc-creation-moved/ it appears that in Notepad++ you want

    Settings / Preferences / New Document (on left sidebar) / Default language to be AutoIt.

    Notepad++ can already do that. What Notepad++ does not seem to have baked in at present is a default blank document template. It’s not clear though
    if filling in the new tab with stuff related to a generic .au3 file is useful or essential to you. Any of what people have already suggested here will do for filling in the default new-document but it’s also possible a plugin exists that can do this.

  • Sort lines but keep the hierarchy

    5
    0 Votes
    5 Posts
    433 Views
    guy038G

    Hi, @rune-egenes and All,

    Easy !

    First regex :

    SEARCH \R(?=\t)

    REPLACE Leave EMPTY

    Sort

    Second regex

    SEARCH (?=\t)

    REPLACE \r\n    or    \n if you deal with UNIX files

    BR

    guy038

  • Notepad++ upgrade issue

    2
    0 Votes
    2 Posts
    222 Views
    Terry RT

    @Abhinav-kganan said in Notepad++ upgrade issue:

    Is there any way I can retrieve it?

    You haven’t exactly provided much information. However I suspect you have been working with tabs of data that you haven’t actually saved as real files. Which if true is a shame, because if you have critical data you really do need to save it.

    How about read this post which is in the FAQ section. In there are references to the periodic backup files created if you have the right settings enabled for those “unsaved” tabs.

    Good luck. Even if you do not recover the data, please read that post entirely, understand what it is saying, and change your backup procedures so you do not suffer the same occurance in the future.

    Terry

  • Help Adding Pascal to Function List

    27
    0 Votes
    27 Posts
    3k Views
    Lycan ThropeL

    @menit-lop ,
    You might want to read the documents a little better. If you’re going to have multiple possibilities in the mainExpr buffer, than you need to give it multiple options by separating the two options, not combining them. It probably should look more like this:

    ?i:PROCEDURE\s+ \K | ?i:FUNCTION\s+ \K

    When the first option fails, it tries the next…and on down a list if there are multiple options, like @PeterJones showed me in my dBASE UDL, which had the similar construct of Procedure, Functions, but also so we could make objects show up in the function list when there was no function, by using an additional OR statement of with, where the code looked like this:

    this.NPPINST_TL = new TEXTLABEL(this) with (this.NPPINST_TL) height = 2.0 left = 29.0 top = 0.5 width = 67.0 text = "Notepad++ dBASE Plus UDL Installer" colorNormal = "0x404000/Silver" fontSize = 19.0 fontBold = true endwith

    As you can see, our UI classes would not show up unless they had a function inside them, and we wanted to be able to see the Objects whether they had a function or not, and @PeterJones figured that out for me, that adding that OR statement in the function parser would allow that to show up also emulating a function option, so our functionList code looked like this:

    <function mainExpr="(?xi-s) ^ \h* (?: function \h+ \w+ | procedure \h+ \w+ | with \h+ \(.*?\) ) \h* " >

    Hopefully this helps you.

  • 0 Votes
    4 Posts
    232 Views
    Mark OlsonM

    My gut feeling is that you should probably be using an XML parser for this sort of thing. I suspect XSLT could be useful, but since I’ve never used it I can’t say more.

    See the XMLTools plugin. Even though it hasn’t been updated recently, it still seems to work fine.

  • OneDrive interactions with Notepad++

    6
    0 Votes
    6 Posts
    4k Views
    Alan KilbornA

    @Demetrio-Foti

    Notepad++'s reload prompt only fires based upon the file timestamp that the OS supplies to Notepad++. So any funkyness regarding onedrive is related to this, not some “local bit” or “status icon”.

    My personal theory about onedrive is that there are many ways it can be configured. Depending on what configuration is set, at different times it can make Notepad++ think that the filetime has changed, thus firing the reload prompt.

  • notepad ++ v8.4.8 exception error when trying to connect NppFTP

    2
    0 Votes
    2 Posts
    226 Views
    Lycan ThropeL

    @aileen-balian
    If it’s not an incompatibility issue (check the Plugins Admin), check with the author at his github page, since this is a plugin.

  • Find and replace by adding a value

    3
    0 Votes
    3 Posts
    323 Views
    David CRD

    ok! Tanks :)

  • append text to some lines only

    5
    1 Votes
    5 Posts
    352 Views
    namx3249N

    yes Alan, i’ve see that !

  • a regex question with new line

    6
    0 Votes
    6 Posts
    1k Views
    Daniel B. 0D

    another option! thanks for this too! :)

  • Page seems to be full of space characters just recently

    2
    0 Votes
    2 Posts
    205 Views
    PeterJonesP

    @Arthur-Hodgett ,

    next line by pressing the down arrow, it automatically returned to the last > on the next line, but now it just goes to the line below as if it was full of space characters

    My guess is that you (intentionally or accidentally) checkmarked the option Settings > Preferences > Editing > ☑ Enable Virtual Space, which allows you to place your cursor beyond the end of the line.

    (In a fresh installation / fresh portable, that option defaults to not being checkmarked, so you or someone else with access to your Notepad++ has turned it on, if I am correct about the culprit)