Community
    • Login

    Bad Bracket Highlighter

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    29 Posts 4 Posters 16.1k Views 3 Watching
    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.
    • Scott SumnerS Offline
      Scott Sumner
      last edited by

      BTW, pressing ctrl+j if you remove the default Notepad++ keymapping tying that to the Join Lines feature will insert a \n line-ending in the current file, regardless of the file’s EOL setting. (This can be added to the previous posting’s bullet list)

      1 Reply Last reply Reply Quote 0
      • Scott SumnerS Offline
        Scott Sumner
        last edited by

        So as a prevention from pressing ctrl+m inserting a Mac line-ending into a non-Mac encoded file (as well as possibly ctrl+j inserting a Unix line-ending into a non-Unix encoded file), see the CHARADDED Pythonscript in this thread. This script should be set to be run upon Notepad++ startup.

        More comments to come on this topic…which unfortunately is off-topic for this thread (but I didn’t do that). :-)

        1 Reply Last reply Reply Quote 0
        • guy038G Offline
          guy038
          last edited by

          Hello, @salviasage, @scott-sumner and All,

          Oh, my God ! there a very simple way to prevent the Ctrl+ M shortcut from inserting the CR character ( \x{000D} ) , which is displayed in reverse video !.. Like me, simply, affect the Ctrl+ M shortcut to the Mark dialog ( Search > Mark… ) :-)))

          Et voilà !

          Cheers,

          guy038

          Scott SumnerS 1 Reply Last reply Reply Quote 2
          • Scott SumnerS Offline
            Scott Sumner @guy038
            last edited by

            @guy038

            very simple way

            Yes, but ctrl+m is just a special case of ALL of the control-plus-(mostly)letter codes that one hasn’t assigned shortcut functions to. The Pythonscript in that other thread takes care of all of them at once, so fat-fingered users should not see odd black-boxed things again in their editor window (like the picture at the bottom of this posting)…unless they Undo (ctrl+z) the change made by the script. Sadly, I don’t believe there is a way to remove something from the undo buffer without purging the entire thing. :-(

            It’s a more complete solution: It takes care of the original problem of ctrl+m inserting a \r – without having to assign it a function, and some other things that a user may experience and not like.

            By the way, the script won’t interfere with things like ctrl+a or ctrl+c or ctrl+v, etc, because those (and your ctrl+m, @guy038) get snared as commands at a higher level and don’t pass through–like unassigned ones–to be added as “text” to the current editor window.

            Imgur
            (those are ctrl+w and ctrl+e, respectively, as text)

            Scott SumnerS 1 Reply Last reply Reply Quote 2
            • Scott SumnerS Offline
              Scott Sumner @Scott Sumner
              last edited by Scott Sumner

              So one way to avoid having mixed line-endings in your file is to automatically run a check each time the file is saved, and if any inconsistent line-endings are found, correct them at that time. Here’s a Pythonscript that will do that; I call it LineEndingRepairAtSave.py:

              try:
              
                  LERAS__bad_eol_regex_via_good_eol_dict
              
              except NameError:
              
                  LERAS__bad_eol_regex_via_good_eol_dict = {
                      '\r\n' : r'\r(?!\n)|(?<!\r)\n',
                      '\n'   : r'\r\n?',
                      '\r'   : r'\r?\n',
                  }
              
                  def LERAS__callback_npp_FILEBEFORESAVE(args):
                      correct_eol_for_this_file = ['\r\n', '\r', '\n'][notepad.getFormatType()]
                      editor.rereplace(LERAS__bad_eol_regex_via_good_eol_dict[correct_eol_for_this_file], correct_eol_for_this_file)
              
                  notepad.callback(LERAS__callback_npp_FILEBEFORESAVE, [NOTIFICATION.FILEBEFORESAVE])
              

              The idea is that you run it once per Notepad++ session and it will stand guard against the tyranny of mixed line-endings in your saved files. Maybe it takes a noticeable amount of time to run on really large files…dunno…use at your own risk.

              1 Reply Last reply Reply Quote 4
              • SalviaSageS Offline
                SalviaSage
                last edited by

                I want to cry with joy at this moment…

                This is what makes notepad++ great…

                A special thanks to Scott as usual for his contribution.

                Scott SumnerS 1 Reply Last reply Reply Quote 2
                • Scott SumnerS Offline
                  Scott Sumner @SalviaSage
                  last edited by

                  @SalviaSage said:

                  I want to cry with joy at this moment…

                  LOL. …and I thought you’d complain that it isn’t an as-you-type or an as-you-paste solution! I still wonder why mixed line-endings is a real problem for you. I’ve been using Notepad++ for a long time and it rarely is a problem for me…

                  1 Reply Last reply Reply Quote 2
                  • Scott SumnerS Offline
                    Scott Sumner
                    last edited by guy038

                    Slight change to the Pythonscript I posted earlier. I noticed that does not work correctly when the Notepad++ user executes a Save All. Here’s an update to (only) the callback function part that will fix this, just replace the old LERAS__callback_npp_FILEBEFORESAVE function definition with the following:

                    def LERAS__callback_npp_FILEBEFORESAVE(args):
                        notepad.activateBufferID(args['bufferID'])
                        correct_eol_for_this_file = ['\r\n', '\r', '\n'][notepad.getFormatType()]
                        editor.rereplace(LERAS__bad_eol_regex_via_good_eol_dict[correct_eol_for_this_file], correct_eol_for_this_file)
                    
                    1 Reply Last reply Reply Quote 2
                    • SalviaSageS Offline
                      SalviaSage
                      last edited by

                      @Scott-Sumner

                      Dear Scott.

                      I am afraid this script and the broken bracket highlighter is no longer working.

                      I confirmed that the startup script of the PythonScript plugin is working by using some other scripts.

                      But, these 2 which are very similar to each other in nature, are just not working.

                      I don’t know why, I tried fixing it and I could not. So, I have to appeal to you for help.

                      :(

                      1 Reply Last reply Reply Quote 0
                      • SalviaSageS Offline
                        SalviaSage
                        last edited by

                        Ignore above, there were 2 syntax errors in there for some reason,
                        and I fixed it. I must have made a mistake myself.

                        1 Reply Last reply Reply Quote 1
                        • Alan KilbornA Alan Kilborn referenced this topic on

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors