• Login
Community
  • Login

Replace certain characters when typing (YAML)

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
11 Posts 5 Posters 898 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.
  • H
    Holger Hasenmüller
    last edited by Dec 14, 2020, 6:19 PM

    Good evening,

    I just came across a problem in a tutorial (or the writer of the tutorial) where I imagine you can get a handle on it with notepad++.

    It’s about the reverse proxy “Traefik V2”. So here there are configuration files YAML files, which have a small peculiarity.

    There must not be used the superscript ( ’ ), but this character ( ` ). Unfortunately it is so that one must press here first the SHIFT key, then the actual key and afterwards still the blank.

    Is there a possibility to teach notepad++, if YAML is selected as language, that the apostrophe key ’ is pressed, but this character ` is generated.

    Thanks a lot

    P 1 Reply Last reply Dec 14, 2020, 6:25 PM Reply Quote 0
    • P
      PeterJones @Holger Hasenmüller
      last edited by PeterJones Dec 14, 2020, 6:25 PM Dec 14, 2020, 6:25 PM

      @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.

      A 1 Reply Last reply Dec 14, 2020, 9:03 PM Reply Quote 0
      • C
        carypt
        last edited by carypt Dec 14, 2020, 8:52 PM Dec 14, 2020, 8:51 PM

        isnt it that autohotkey can handle such type of solution ?

        1 Reply Last reply Reply Quote 0
        • A
          Alan Kilborn @PeterJones
          last edited by Alan Kilborn Dec 14, 2020, 9:06 PM Dec 14, 2020, 9:03 PM

          @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
          • E
            Ekopalypse
            last edited by Ekopalypse Dec 14, 2020, 9:26 PM Dec 14, 2020, 9:25 PM

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

            ;-D

            ZnJvbSBOcHAgaW1wb3J0IGVkaXRvciwgU0NJTlRJTExBTk9USUZJQ0FUSU9OLCBNT0RJRklDQVRJT05GTEFHUw0KDQpkZWYgb25fbW9kaWZ5KGFyZ3MpOg0KICAgIGlmIChlZGl0b3IuZ2V0TGV4ZXJMYW5ndWFnZSgpID09ICd5YW1sJyBhbmQgDQogICAgICAgIGFyZ3NbJ21vZGlmaWNhdGlvblR5cGUnXSA9PSBNT0RJRklDQVRJT05GTEFHUy5JTlNFUlRDSEVDSyk6DQogICAgICAgIGlmICInIiBpbiBhcmdzWyd0ZXh0J106DQogICAgICAgICAgICBlZGl0b3IuY2hhbmdlSW5zZXJ0aW9uKGFyZ3NbJ3RleHQnXS5yZXBsYWNlKCInIiwgJ2AnKSkNCg0KZWRpdG9yLmNhbGxiYWNrU3luYyhvbl9tb2RpZnksIFtTQ0lOVElMTEFOT1RJRklDQVRJT04uTU9ESUZJRURdKQ
            
            A 1 Reply Last reply Dec 14, 2020, 9:29 PM Reply Quote 4
            • A
              Alan Kilborn @Ekopalypse
              last edited by Dec 14, 2020, 9:29 PM

              @Ekopalypse

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

              E 1 Reply Last reply Dec 14, 2020, 9:32 PM Reply Quote 0
              • E
                Ekopalypse @Alan Kilborn
                last edited by Dec 14, 2020, 9:32 PM

                @Alan-Kilborn

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

                A 1 Reply Last reply Dec 14, 2020, 9:34 PM Reply Quote 2
                • A
                  Alan Kilborn @Ekopalypse
                  last edited by Dec 14, 2020, 9:34 PM

                  @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
                  • E
                    Ekopalypse
                    last edited by Ekopalypse Dec 14, 2020, 9:41 PM Dec 14, 2020, 9:38 PM

                    @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])
                    
                    P 1 Reply Last reply Dec 14, 2020, 10:38 PM Reply Quote 2
                    • P
                      PeterJones @Ekopalypse
                      last edited by Dec 14, 2020, 10:38 PM

                      @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 …

                      E 1 Reply Last reply Dec 14, 2020, 10:45 PM Reply Quote 2
                      • E
                        Ekopalypse @PeterJones
                        last edited by Dec 14, 2020, 10:45 PM

                        @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
                        • A Alan Kilborn referenced this topic on Nov 27, 2023, 7:50 PM
                        8 out of 11
                        • First post
                          8/11
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors