• Any way to create a shortcut to add prefix and suffix to a word?

    15
    0 Votes
    15 Posts
    3k Views
    Alan KilbornA

    Okay, here’s another (and probably last) try.
    Basically, if there’s no active selection and the caret isn’t touching a word when the script is run, it means you want to modify the current prefix/suffix setup.
    Otherwise, the current prefix/suffix is applied to the current selection/word.

    # -*- coding: utf-8 -*- from Npp import editor class T19459a(object): def __init__(self): self._prefix = '' self._suffix = '' def update_prefix_suffix_info(self): separator = '-' while True: user_input = notepad.prompt( 'Enter PREFIX{s}SUFFIX :\r\n(PREFIX or SUFFIX (not both) maybe be empty, but must still use {s})'.format(s=separator), '', '') if user_input == None: return # Cancel parms_list = user_input.strip().split(separator) if len(parms_list) == 2: (prefix, suffix) = parms_list if len(prefix) + len(suffix) == 0: continue break self._prefix = prefix self._suffix = suffix def run(self): already_ran_input_prompt_this_cycle = False if len(self._prefix + self._suffix) == 0: self.update_prefix_suffix_info() already_ran_input_prompt_this_cycle = True word_at_caret_or_selection = '' (sel_start, sel_end) = (editor.getSelectionStart(), editor.getSelectionEnd()) if editor.getSelections() == 1 and sel_start != sel_end: word_at_caret_or_selection = editor.getTextRange(sel_start, sel_end) else: start_of_word_pos = editor.wordStartPosition(editor.getCurrentPos(), True) end_of_word_pos = editor.wordEndPosition(start_of_word_pos, True) if start_of_word_pos != end_of_word_pos: word_at_caret_or_selection = editor.getTextRange(start_of_word_pos, end_of_word_pos) editor.setSelection(end_of_word_pos, start_of_word_pos) if len(word_at_caret_or_selection) == 0: if not already_ran_input_prompt_this_cycle: self.update_prefix_suffix_info() elif len(self._prefix + self._suffix) > 0: editor.beginUndoAction() editor.replaceSel(self._prefix + word_at_caret_or_selection + self._suffix) editor.endUndoAction() if __name__ == '__main__': try: t19459a except NameError: t19459a = T19459a() t19459a.run()
  • SecurePAD HELP

    2
    0 Votes
    2 Posts
    241 Views
    PeterJonesP

    For future readers who think we ignored this question, it’s because we tackled the problem in https://community.notepad-plus-plus.org/topic/19455/securepad-help, a nearly-identical posting from about a minute later in the Plugin Development category.

  • regex replace doesn't work

    4
    1 Votes
    4 Posts
    271 Views
    Alan KilbornA

    @Stefan-N said in regex replace doesn't work:

    By “leading assertions” you are talking about the “look ahead/behind” structure?

    Yes.

    When you are doing “step finds” (where you press Find Next to repeatedly jump to the next match), the buffer to be searched literally starts right where the caret is.
    There is no knowledge of what comes to the “left” of the caret.
    Thus, a positive look-behind assertion at that point will always fail – which is what you are seeing.
    A negative look-behind assertion will always succeed.
    Just a peculiarity of the N++ searching engine.
    Something to remember for the future!

  • Double Click in find results does not open and highlight

    11
    0 Votes
    11 Posts
    960 Views
    EkopalypseE

    I copied your macro, restarted Npp and did some tests and
    those worked for me. Sorry, not sure what breaks it on your side.

  • 0 Votes
    3 Posts
    861 Views
    Alan KilbornA

    @Perry-B

    It seems like this regex will match your text: (?s)^\h+?<vehicle>.*?</vehicle>\R

  • 0 Votes
    6 Posts
    428 Views
  • Easy way to mock up Position based Flat File

    12
    0 Votes
    12 Posts
    5k Views
    Sonali DixitS

    @Alan-Kilborn Thank you Alan, this looks lot easier to work with. but it seems like I need to update my Notepad++ I have older version.

    Hey by the way, I found one more link that might help, just sharing if any one else can use it. https://www.convertcsv.com/csv-to-flat-file.htm

  • Replace X number of lines after finding Y

    11
    0 Votes
    11 Posts
    2k Views
    guy038G

    Hello, @brian-krontz, @ekopalypse, @terry-r @alan-kilborn, @makwana-prahlad and All,

    To @makwana-prahlad :

    Why are you using such a complicated script, with some advanced options of sed ?

    To my mind, the one-line script, below, does the job nicely, too ;-))

    sed -n "/^\x0C/,+5d ; /(Continued)/d ; p" Input.txt > Output.txt

    Notes :

    First, sed searches, in the Input.txt file, for a range of lines :

    The first line of this range must contain the FF char, at beginning of current line, so the /^\x0C/ syntax

    Till the next 5 lines, that is to say, till the 6th empty line. Thus, the ,+5 syntax

    Then, the d command deletes this range of entire lines

    Secondly, sed searches if the next 7th line contains the (Continued) string, with that exact case, so the syntax /(Continued)/ , and, in that case, the d command, again, deletes this current line

    Finally, if none of these criteria can be verified, the p command simply rewrites the current line in the Output.txt file

    Indeed, not the same philosophy at usual N++ regexes, but rather easy to understand, too !

    Cheers,

    guy038

    P.S. :

    My sed script is not totally exact ! Indeed, if a line, located outside the header zone, contains the string (Continued), this line is wrongly deleted ! But, anyway, we’re on a Notepad++ forum, after all ;-))

  • RegEx: Anchor for beginning of file

    10
    0 Votes
    10 Posts
    9k Views
    guy038G

    Hi, All,

    Do you know how I could maintain some spacing between the three regexes :

    (?<!\n|\r|\f)^    ,    ^\A    ,    \A^

    Which are usually rewritten :

    (?<!\n|\r|\f)^ , ^\A , \A^

    in the legal code text, of my previous post ?

    Well, the trick is to use No Break Space character(s) ( \xA0 ), instead of the usual Space chars ( \x20 ) ;-))

    So, use the Alt + 160 input method, from the numeric keypad, to insert a No Break Space character, at current cursor location !

    Cheers,

    guy038

  • Compare text automation & result in excel format

    1
    0 Votes
    1 Posts
    322 Views
    No one has replied
  • Color syntax for Ruby breaks when %= is encountered

    10
    0 Votes
    10 Posts
    457 Views
    ice7512I

    @Ekopalypse Thanks

  • Replace all in all opened Documents (bug)

    3
    0 Votes
    3 Posts
    337 Views
    Roy BoothR

    I never considered that, but your right. Thanks :)

  • User Defined Language: Collapse block of text

    4
    0 Votes
    4 Posts
    3k Views
    PeterJonesP

    @CoR said in User Defined Language: Collapse block of text:

    So, choices are:
    not possible

    natively, correct, it is not currently possible

    plugin (if it is possible to do it in plugin way)

    that would work. plugins can be used to define whole new lexers in the language menu, so yes, a plugin could handle what you wanted, if such a plugin were to be written (I doubt one with that exact feature is already in the Plugins Admin list of plugins).

    With some effort, it could probably also be implemented using the already-existing PythonScript or LuaScript plugin, which allow you to write Python or Lua code to control the Notepad++ GUI and editor windows, including influencing things like syntax highlighting and code folding. My guess is that it would use a similar technique to what @Ekopalypse implemented for regex-based extra-syntax highlighting in this post, but you’d have to find the code-folding rather than text-coloring code to manipulate.

    a feature request

    You could try, yes. However, no new features have been added to User Defined Languages (UDL) system in years, and there are many open bug reports and feature requests for UDL improvements … Sorry that I don’t have better news on that front. :-(

    :(

    Indeed.

  • hello,i am new and have a very stupid question.

    3
    0 Votes
    3 Posts
    201 Views
    anastasiia maiorovaA

    @Ekopalypse oh thank you! i solved it now!! thanks alot :)

  • How to remove the space when commenting lines?

    11
    0 Votes
    11 Posts
    904 Views
    WillyW

    @Terry-R These are valid options and I did think of them, but I was hoping there was a way to configure notepad++ without doing anything, I’ll try my luck on Github and thanks for everything.

  • Will not open files on mounted ntfs partition

    3
    0 Votes
    3 Posts
    549 Views
    Alan KilbornA

    Often the argument is “It works just fine in all my other applications, just not Notepad++”.
    So at what point does NOT supporting a certain scenario become a liability?
    Perhaps even one that makes users switch to other text-editing software.
    There’s no answer – it’s a tough call.

  • Range Replace - Regular Expression

    5
    0 Votes
    5 Posts
    1k Views
    Alan KilbornA

    @guy038

    Good technique.

    Slight mod:
    The OP mentioned the top end being 150, so the selection should probably really be:

    412f6922-e2a5-4098-912a-5a015e2ac03e-image.png

    But, if the OP couldn’t extrapolate your solution to that, there’s a bigger problem. :-)

  • Macro for "Number to Insert" from Column Editor

    5
    0 Votes
    5 Posts
    341 Views
    Alan KilbornA

    @Gustavo-Baiano said in Macro for "Number to Insert" from Column Editor:

    I just want to have a “enumerate shortcut”.

    It seems like it would be an easy thing to write a script for, either in Pythonscript or Luascript

    You would:

    define a column insert region (what would look like a tall caret

    run the script (via keycombo, menu, or toolbar button)

    boom your numbering pops in! :-)

    But, do you do this constantly, such that using the actual column editor is a real burden?

  • Replace specific number and letter

    3
    0 Votes
    3 Posts
    168 Views
    Alexandros XatzidimitriouA

    Thanks a lot guy038! This is exactly what I was looking for!!!

  • Lag spikes/freezes when using multiline String in ps1 file

    2
    0 Votes
    2 Posts
    436 Views
    PeterJonesP

    @Kevin-Holtkamp said in Lag spikes/freezes when using multiline String in ps1 file:

    @"
    string content
    "@

    With a powershell file with just that content, I don’t notice any lag / freezes. My guess is something else is going on.

    Please go to the ? menu, select Debug Info, and paste the results into the forum.

    Also, see if it freezes for you when all you have in your powershell file is

    @" string content "@

    If it does freeze from just that, let us know. If not, there is going to have to be more debug.

    My guess is something else is going on: either it’s because of a really long file, or because of one or more plugins, or both. (There could also be many things I haven’t considered.)