Feature or plugin request



  • Hi, new user of this notepad forum here.

    Notepad++ is a useful tool for me for writing html and css.

    A feature which would be very handy for me would be:
    ‘Copy/cut/move lines containing … (a search term)’.

    This would allow for sorting a list of items by file type, for instance a list of .jpg and mp4 files.
    Split this unordered list into seperate lists into seperate lists, all containing the same file type.

    Ideal would be if this function could move the cut lines to another or a new tab.

    Thanks for reading!



  • @jepz1

    Implementing such a feature is a perfect task for the Pythonscript or Luascript plugins. Learn to program in these languages if you don’t know how already. It is not that hard. But…it is definitely harder than just making a feature request. :-D



  • Thanks for the reply and the idea.

    I must however by doctors orders stay at least arm-length away from anything resembling programming or scripting, my head may explode.

    Hope this is a useful suggestion, though. Such a feature would save me a lot of tedious work.



  • Hello, @jepz1,

    May be, I misunderstood your question, but it looks like that you were searching for the Bookmark feature !

    Just a simple example :

    • Open, for instance, the change.log file

    • Open the Mark dialog, with the menu option Search > Mark…

    • In the Find what: zone, type the word Fix

    • Select the two options Bookmark line and Purge for each search

    • Select, also, the two options Match case and Wrap around

    • Finally, select the normal search mode

    • As soon as you hit the Mark All button, all the lines, containing the word Fix , with that exact case, are bookmarked ( Blue circle marker )

    • Now, using the menu option Search > Bookmark > …, you can, either :

      • Copy All the Bookmarked lines

      • Cut All the Bookmarked lines

      • Remove All the Bookmarked lines

      • Remove All the Unmarked lines

    • If, you chose, one of the two first options, open a new tab ( CTRL + N )

    • Then , paste, all the Bookmarked lines, in that new tab ( CTRL + V )

    Best Regards,

    guy038



  • @guy038

    Very good suggestions, Guy. I was thinking that the OP wanted something that was more “integrated”, meaning not a lot of steps to accomplish the goal, which programming in Pythonscript, et al would provide. However, if a number of individual steps makes a nice solution for the OP, then you’ve certainly provided that.



  • Another thing that just occurred to me is that maybe the LineFilter2 and/or Analyse plugins could help with the OP’s needs?



  • @guy038, thanks thanks & thanks!
    This is even better than what I wanted, I can also mark different movie file types subsequently and cut them all for a list of only movies.

    Is this a great program, or what! It doesn’t even need a plugin.
    Did I say thanks?



  • @guy038, it’s good for me you explained it step by step, just mentioning the Bookmark feature would’ve been a puzzle for me. You were very helpful, thanks multiple times :)



  • Hi, @jepz1 and All,

    An other example of the power of bookmarks !

    Given, again, the change.log file of N++ v7.3.3, let’s suppose that you would like to isolate all the lines which DO NOT contain the string Fix, with that exact case !

    To perform this kind of negative search, it would be necessary to use the regular expression search mode !

    • Open the Mark dialog, with the menu option Search > Mark…

    • In the Find what: zone, type the regular expression, below :

    (?-is)^(?!.*Fix).*\R? ( explained at the end of that post ! )

    • Select the two options Bookmark line and Purge for each search

    • Select, also, the two options Match case and Wrap around

    • Finally, select the Regular expression search mode

    • As soon as you hit the Mark All button, all the lines, which do not contain the string Fix , with that exact case, empty lines included, are bookmarked ( You should obtain 20 matches, which can be copied, as explained in my previous post )


    Now, for some people not very acquainted with the regular expressions syntax, it may be difficult to figure out which exact regex is needed :-(. So we could, rather, search for all the lines which DO contain the string Fix, with that exact case !
    Quite easy, isn’t it !

    • Open the Mark dialog, with the menu option Search > Mark…

    • In the Find what: zone, type the simple string Fix, with that exact case

    • Select the two options Bookmark line and Purge for each search

    • Select, also, the two options Match case and Wrap around

    • Select the Normal search mode

    • To be coherent, with the previous regex search, don’t check the Match whole word only option

    • As soon as you hit the Mark All button, all the lines, which do contain the string Fix , with that exact case, are bookmarked ( You should obtain 5 matches )

    • Now, here is the magic ! Select the menu option Search > Bookmark > Inverse bookmark => All the lines that do not contain the string Fix, are, now, bookmarked !

    This second method is easier that the first one !

    Cheers,

    guy038

    Notes on the regex ^(?-is)(?!.*Fix).*\R? :

    • As usual, the syntax (?-is) :

      • Forces the regex engine to perform the search, in a non-insensitive way ( -i = sensitive way )

      • Forces the regex engine to consider the dot special character as a single standard character, only ( -s = no single-line mode )

    • Then, from the beginning of each line, the regex engine verifies that any range, even empty, of standard characters, ending with the string Fix, with that exact case, DOES NOT exist, till the end of the current line, due to the regex syntax (?!.*Fix), which is a negative look-ahead condition

    • If this assertion is true, then all the contents, even empty, of the current line ( .* ), with the possible End of Line characters ( \R? ), are selected and the appropriate lines are bookmarked



  • So back on the track of a very integrated (not a lot of steps) solution to quickly copying lines that contain a string to a new file, I came up with this Pythonscript:

    prompt_result = notepad.prompt('Enter a string to find:', 'Find With Results to New File', '')
    if prompt_result != None:
        match_span_tup_list = []
        editor.research(prompt_result, lambda m: match_span_tup_list.append(m.span(0)), 0)
        line_list_dict = {}
        for span_tup in match_span_tup_list:
            for line_nbr in range(editor.lineFromPosition(span_tup[0]), editor.lineFromPosition(span_tup[1]) + 1):
                line_list_dict[line_nbr] = 1
        lines_buffer = []
        for line_nbr in sorted(line_list_dict): lines_buffer.append(editor.getLine(line_nbr))
        notepad.new()
        editor.addText(''.join(lines_buffer))
    

    Maybe useful to others, maybe not. The find criteria is pretty basic as written. :-D



  • Hi, @scott-sumner and All,

    I’ve just tested your Python script : it works fine !

    However, briefly, it may be useful to add that the search of lines, in your script, is performed, by default :

    • In Regular expression mode

    • With an implicit sensitive search ( So, for an insensitive search, use, rather, the syntax (?i)..... )

    • Without care to characters surrounding the string to find ( So, for a “word” search, prefer the syntax \bWORD\b)

    • With the dot symbol matching a single standard character ( If dot may, also, match End of Line chars, choose (?s)..... )


    The Scott’s script doesn’t mind, too, about the present options , checked or not , of the Find dialog !

    Cheers,

    guy038



  • @guy038

    Hi Guy, yes…I purposefully left functionality augmentations of that simple script as “exercises for the reader”. But you have provided the tools for the hackers.

    :-D


Log in to reply