Replace certain characters when typing (YAML)
-
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.
-
isnt it that autohotkey can handle such type of solution ?
-
@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… -
hacks … tststs … never thought this day would come … but…
;-D
ZnJvbSBOcHAgaW1wb3J0IGVkaXRvciwgU0NJTlRJTExBTk9USUZJQ0FUSU9OLCBNT0RJRklDQVRJT05GTEFHUw0KDQpkZWYgb25fbW9kaWZ5KGFyZ3MpOg0KICAgIGlmIChlZGl0b3IuZ2V0TGV4ZXJMYW5ndWFnZSgpID09ICd5YW1sJyBhbmQgDQogICAgICAgIGFyZ3NbJ21vZGlmaWNhdGlvblR5cGUnXSA9PSBNT0RJRklDQVRJT05GTEFHUy5JTlNFUlRDSEVDSyk6DQogICAgICAgIGlmICInIiBpbiBhcmdzWyd0ZXh0J106DQogICAgICAgICAgICBlZGl0b3IuY2hhbmdlSW5zZXJ0aW9uKGFyZ3NbJ3RleHQnXS5yZXBsYWNlKCInIiwgJ2AnKSkNCg0KZWRpdG9yLmNhbGxiYWNrU3luYyhvbl9tb2RpZnksIFtTQ0lOVElMTEFOT1RJRklDQVRJT04uTU9ESUZJRURdKQ
-
Nice one. Not sure why you chose to “hide” it, but far from me to “unhide” it. :-)
-
because I didn’t want to spoil if you decided to go for it :-D
-
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.
:-) -
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])
-
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
hackengineer such solutions when the questions are first posted.… real life getting in the way of the forum, grumble, grumble …
-
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
-