Community
    • Login

    Replace certain characters when typing (YAML)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 5 Posters 878 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.
    • PeterJonesP
      PeterJones @Holger Hasenmüller
      last edited by PeterJones

      @Holger-Hasenmüller ,

      Sorry, not with any built-in Notepad++ tool. Normally, the keyboard settings (what character gets typed when a specific key is pressed) are up to the OS, not to the application.

      Those who are experts with the PythonScript plugin might be able to hack up something that will add a handler-function which verifies YAML and then makes that substitution automatically when the “wrong” character is typed. But you would have to be willing to install the PythonScript plugin.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • caryptC
        carypt
        last edited by carypt

        isnt it that autohotkey can handle such type of solution ?

        1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @PeterJones
          last edited by Alan Kilborn

          @PeterJones said in Replace certain characters when typing (YAML):

          Those who are experts with the PythonScript plugin might be able to hack up something that will add a handler-function which verifies YAML and then makes that substitution automatically when the “wrong” character is typed. But you would have to be willing to install the PythonScript plugin.

          Ahem…

          hack up something

          That sounds like unfortunate act that my cat performs, on occasion.
          Pythonscript solutions are always professionally architected and developed solutions, not “hacks”. :-)

          So this sounds like a job for the “char added” notification message from Scintilla, which could handle a replacement dynamically as the user types.

          But, what about pasting data – if the wrong character happens to be in a block of pasted data, when does it get corrected?
          Due to this, it seems like a fuller solution is needed than just an on-the-fly correction of one character.

          Still, nothing a script can’t handle, just need to know what the spec is, for whomever might try to write it.
          I don’t know if I can find time, I think I have to go see what my cat is up to in the other room…I hear something…

          a4362267-44a1-4825-84e9-c1c8e87fed77-image.png

          1 Reply Last reply Reply Quote 2
          • EkopalypseE
            Ekopalypse
            last edited by Ekopalypse

            hacks … tststs … never thought this day would come … but…

            ;-D

            ZnJvbSBOcHAgaW1wb3J0IGVkaXRvciwgU0NJTlRJTExBTk9USUZJQ0FUSU9OLCBNT0RJRklDQVRJT05GTEFHUw0KDQpkZWYgb25fbW9kaWZ5KGFyZ3MpOg0KICAgIGlmIChlZGl0b3IuZ2V0TGV4ZXJMYW5ndWFnZSgpID09ICd5YW1sJyBhbmQgDQogICAgICAgIGFyZ3NbJ21vZGlmaWNhdGlvblR5cGUnXSA9PSBNT0RJRklDQVRJT05GTEFHUy5JTlNFUlRDSEVDSyk6DQogICAgICAgIGlmICInIiBpbiBhcmdzWyd0ZXh0J106DQogICAgICAgICAgICBlZGl0b3IuY2hhbmdlSW5zZXJ0aW9uKGFyZ3NbJ3RleHQnXS5yZXBsYWNlKCInIiwgJ2AnKSkNCg0KZWRpdG9yLmNhbGxiYWNrU3luYyhvbl9tb2RpZnksIFtTQ0lOVElMTEFOT1RJRklDQVRJT04uTU9ESUZJRURdKQ
            
            Alan KilbornA 1 Reply Last reply Reply Quote 4
            • Alan KilbornA
              Alan Kilborn @Ekopalypse
              last edited by

              @Ekopalypse

              Nice one. Not sure why you chose to “hide” it, but far from me to “unhide” it. :-)

              EkopalypseE 1 Reply Last reply Reply Quote 0
              • EkopalypseE
                Ekopalypse @Alan Kilborn
                last edited by

                @Alan-Kilborn

                because I didn’t want to spoil if you decided to go for it :-D

                Alan KilbornA 1 Reply Last reply Reply Quote 2
                • Alan KilbornA
                  Alan Kilborn @Ekopalypse
                  last edited by

                  @Ekopalypse

                  Oh, no. If you already have a solution handy, post it ASAP.
                  I’ve got better things to spend my time on than reinventing the wheel.
                  :-)

                  1 Reply Last reply Reply Quote 1
                  • EkopalypseE
                    Ekopalypse
                    last edited by Ekopalypse

                    @Holger-Hasenmüller

                    a python script which would translate ' to `
                    But I’m not sure if this is the right way to go, as it means you
                    can no longer use the single quote in yaml documents.

                    from Npp import editor, SCINTILLANOTIFICATION, MODIFICATIONFLAGS
                    
                    def on_modify(args):
                        if (editor.getLexerLanguage() == 'yaml' and 
                            args['modificationType'] == MODIFICATIONFLAGS.INSERTCHECK):
                            if "'" in args['text']:
                                editor.changeInsertion(args['text'].replace("'", '`'))
                    
                    editor.callbackSync(on_modify, [SCINTILLANOTIFICATION.MODIFIED])
                    
                    PeterJonesP 1 Reply Last reply Reply Quote 2
                    • PeterJonesP
                      PeterJones @Ekopalypse
                      last edited by

                      @Alan-Kilborn ,

                      hack up something

                      Okay, not the best choice of words in the context of cats.

                      I was thinking of the old paper-and-scissors “hack” algorithm: taking an already existing solution, copy/paste the simple guts in the right order, tweak a few things. (I am guessing that Eko took one of his existing scripts, and started from that… though, with as simple as it was, maybe he really did start from scratch.)

                      And yes, what @Ekopalypse came up with followed my mental outline; I just haven’t had time recently to hack engineer such solutions when the questions are first posted.

                      … real life getting in the way of the forum, grumble, grumble …

                      EkopalypseE 1 Reply Last reply Reply Quote 2
                      • EkopalypseE
                        Ekopalypse @PeterJones
                        last edited by

                        @PeterJones

                        That was quite a lengthy process.
                        First I read through the question.
                        Then I tried to understand the question and what a possible solution might look like.
                        Then I had coffee and cake and had to start all over again.
                        In no time at all, 2 hours went by :-D
                        In the end I did a copy and paste so as not to miss dinner.

                        :-D

                        1 Reply Last reply Reply Quote 3
                        • Alan KilbornA Alan Kilborn referenced this topic on
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors