• Login
Community
  • Login

Regex] Rounding numbers python script does not run properly

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
28 Posts 4 Posters 2.9k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E
    Ekopalypse @unfassbarstephan
    last edited by Aug 24, 2019, 12:31 PM

    @unfassbarstephan

    Short question: What does “???” mean?

    This is Alan’s wasteful use of the question mark,
    for which it is also used here, to ask a question. :-D

    1 Reply Last reply Reply Quote 3
    • A
      Alan Kilborn @unfassbarstephan
      last edited by Aug 24, 2019, 12:36 PM

      @unfassbarstephan said:

      Would you also publish your code for the interactive replace?

      I did…for your specific case. I’m still working on a generic version; may never finish it… :(

      @Ekopalypse said:

      Alan’s wasteful use of the question mark

      Wasteful? It doesn’t seem right without it; I did consider it this way as well, maybe better?:

      Replace selected text with? :

      1 Reply Last reply Reply Quote 2
      • P
        PeterJones
        last edited by Aug 24, 2019, 10:51 PM

        @Alan-Kilborn said:

        Replace selected text with? :

        Maybe Would you like to replace the selected text with the following text?

        A 1 Reply Last reply Aug 24, 2019, 11:57 PM Reply Quote 1
        • A
          Alan Kilborn @PeterJones
          last edited by Aug 24, 2019, 11:57 PM

          @PeterJones

          Well, Pythonscript sizes the dialog box according to contents, so I was trying to keep it as narrow and short as possible to avoid covering too much of the Notepad++ main window. But…I’ve already added more info to make it taller, so why not wider as well? :)

          1 Reply Last reply Reply Quote 1
          • A
            Alan Kilborn
            last edited by Aug 26, 2019, 6:06 PM

            Would you also publish your code for the interactive replace?

            I’m still working on a generic version; may never finish it

            Follow-up:

            There may not be a reasonable way to script this (the “generic version”); here’s why: There doesn’t seem to be a way to do a “boost-ish” replacement option on a Python string. It’s only possible to do it on in-place text.

            What I want to do in the code is pull a copy of the matched text into a Python string and then do a Notepad++ -like replacement operation on that. Sure I can do a Python “re” replacement on it, but that isn’t always going to be equivalent.

            Digging deeper, I see there is an open issue on this kind of thing in the Pythonscript code pages, here . But it hasn’t been acted on so it isn’t a reality.

            If anyone has thoughts on this, I’m all ears. @Ekopalypse ?

            E 1 Reply Last reply Aug 26, 2019, 7:02 PM Reply Quote 0
            • A
              Alan Kilborn
              last edited by Aug 26, 2019, 6:23 PM

              Ugh. Clearly I meant this Pythonscript issue: https://github.com/bruderstein/PythonScript/issues/101 in the previous post, but it is too late for an edit. :(

              1 Reply Last reply Reply Quote 1
              • E
                Ekopalypse @Alan Kilborn
                last edited by Aug 26, 2019, 7:02 PM

                @Alan-Kilborn

                one idea might be to search for matches and replace only those which are
                in the same range as the selected text. Something like

                if start_pos_selected text <= match_start and end_pos_selected_text >= match_end:
                    replaceSelText
                

                Or did I misunderstood your goal? :-(

                A 1 Reply Last reply Aug 26, 2019, 7:08 PM Reply Quote 0
                • A
                  Alan Kilborn @Ekopalypse
                  last edited by Aug 26, 2019, 7:08 PM

                  @Ekopalypse said:

                  did I misunderstood your goal?

                  Maybe that part. :)

                  To be able to offer a preview of the yet-to-be-done replacement, I need to know what that replacement will be. I can’t do that without actually doing the replacement. Catch-22. I could do it and then undo it, I suppose, but that gets messy. Mostly it should be OK, but sometimes with regexes Boost can differ from Python’s re.

                  E 1 Reply Last reply Aug 26, 2019, 7:10 PM Reply Quote 1
                  • E
                    Ekopalypse @Alan Kilborn
                    last edited by Aug 26, 2019, 7:10 PM

                    @Alan-Kilborn

                    what about using a hidden scintilla instance?

                    A 2 Replies Last reply Aug 26, 2019, 7:13 PM Reply Quote 0
                    • A
                      Alan Kilborn @Ekopalypse
                      last edited by Aug 26, 2019, 7:13 PM

                      @Ekopalypse said:

                      what about using a hidden scintilla instance?

                      That also sounds “messy” (or “involved”) but if you have some snippet to show me it is not so bad…?

                      E 2 Replies Last reply Aug 26, 2019, 7:18 PM Reply Quote 0
                      • E
                        Ekopalypse @Alan Kilborn
                        last edited by Aug 26, 2019, 7:18 PM

                        @Alan-Kilborn

                        I used it here .

                        1 Reply Last reply Reply Quote 2
                        • E
                          Ekopalypse @Alan Kilborn
                          last edited by Aug 26, 2019, 7:23 PM

                          @Alan-Kilborn

                          just be careful about notepad.destroyScintilla(self.hidden_scintilla)
                          Currently npp crashes when using this and then request another buffer.
                          There is already a merged fix but only available on next release.

                          A 1 Reply Last reply Aug 26, 2019, 8:07 PM Reply Quote 2
                          • A
                            Alan Kilborn @Ekopalypse
                            last edited by Aug 26, 2019, 8:07 PM

                            @Ekopalypse

                            This is the issue, I assume: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/4487

                            E 1 Reply Last reply Aug 26, 2019, 8:11 PM Reply Quote 1
                            • E
                              Ekopalypse @Alan Kilborn
                              last edited by Aug 26, 2019, 8:11 PM

                              @Alan-Kilborn

                              correct, that is the one.

                              1 Reply Last reply Reply Quote 0
                              • A
                                Alan Kilborn @Ekopalypse
                                last edited by Aug 27, 2019, 2:13 PM

                                @Ekopalypse said:

                                what about using a hidden scintilla instance?

                                So, like this: hidden = notepad.createScintilla()

                                That is actually a nice solution. The hidden instance’s entire text can be set to the matched text from the editor.research(). Then the hidden.rereplace() can be called and the result of the replacement read out into a Python string variable. Thanks, Eko; clearly I would not have thought of this technique without your pointer.

                                just be careful about notepad.destroyScintilla()

                                This is not a problem as I will do this near the top of the script, and never do a “destroy”:

                                try:
                                    hidden
                                except NameError:
                                    hidden = notepad.createScintilla()
                                

                                and never do a “destroy”

                                A E 2 Replies Last reply Aug 27, 2019, 6:57 PM Reply Quote 2
                                • A
                                  Alan Kilborn @Alan Kilborn
                                  last edited by Aug 27, 2019, 6:57 PM

                                  @Alan-Kilborn said:

                                  I will do this near the top of the script, and never do a “destroy”:

                                  and never do a “destroy”

                                  There really is an “echo” in here, or just me repeating myself and not noticing.

                                  1 Reply Last reply Reply Quote 0
                                  • E
                                    Ekopalypse @Alan Kilborn
                                    last edited by Aug 27, 2019, 7:02 PM

                                    @Alan-Kilborn

                                    and never do a “destroy”

                                    :-D never ever - don’t even THINK about it unless your npp version is > 7.7.1 :-D

                                    The hidden instance’s entire text can be set to the matched text from the editor.research(). Then the hidden.rereplace() can b

                                    I guess, hidden.rereplace() is enough if you keep the text from editor and hidden in sync.
                                    The replace function gets a match object which contains the position of the text to be replaced so from the replace function you could start the dialog, or?

                                    A 1 Reply Last reply Aug 27, 2019, 7:12 PM Reply Quote 2
                                    • A
                                      Alan Kilborn @Ekopalypse
                                      last edited by Aug 27, 2019, 7:12 PM

                                      @Ekopalypse

                                      No, I’m not trying to “parallel” the text in the real editor and the hidden. If I set as the hidden editor’s entire text the match from the search, doing the replace on that guarantees the replace will succeed and the entire text left in the hidden editor’s buffer will be the replacement preview text. Long to explain but it seems to work.

                                      1 Reply Last reply Reply Quote 3
                                      20 out of 28
                                      • First post
                                        20/28
                                        Last post
                                      The Community of users of the Notepad++ text editor.
                                      Powered by NodeBB | Contributors