Re: Tutorial: Notepad++ shortcuts.xml macro converts unicode to the 95-keyboard ASCII characters
Marian <[email protected]>
| Newsgroups | alt.comp.os.windows-10,alt.comp.os.windows-11,alt.comp.microsoft.windows |
|---|---|
| Organization | BWH Usenet Archive (https://usenet.blueworldhosting.com) |
| Message-ID | <[email protected]> |
UPDATE:
Currently every shortcuts.xml mapping is written out as a 6-line block:
1700 -> start search
1601 -> set search string (funky character)
1625 -> clear replace buffer
1602 -> set replacement string (ASCII equivalent)
1702 -> run replace all
1701 -> end
That's why the file looks so long and repetitive.
This started as a convertion of just a couple of funky characters to ASCII.
Then it grew over time (years) one by one to include more characters.
We can't avoid the repetition entirely because Notepad++ macros don't
support loops or dictionaries.
But we can simplify because for Notepad++ macros, we don't actually need
the reset/clear/end lines every time.
The essential trio is:
<Action type="3" message="1601" wParam="0" lParam="0" sParam="BADCHAR" />
<Action type="3" message="1602" wParam="0" lParam="0" sParam="GOODCHAR" />
<Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
So each mapping shrinks from 6 lines > 3 lines.
However, if we're open to using a plugin (like PythonScript or LuaScript),
we can collapse the whole macro into a dictionary loop such as this:
mapping = {
"\u2010": "-", # hyphen
"\u2011": "-", # non-breaking hyphen
"\u2013": "-", # en dash
"\u2014": "-", # em dash
"\u2018": "'", # left single quote
"\u2019": "'", # right single quote
"\u201C": '"', # left double quote
"\u201D": '"', # right double quote
"\u2026": "...",# ellipsis
"\u2022": "*", # bullet
"\u00A0": " ", # non-breaking space
"\uFEFF": "", # BOM
# ¡K add the rest
}
editor.beginUndoAction()
for bad, good in mapping.items():
editor.rereplace(bad, good)
editor.endUndoAction()
I'll post the test version of the rewritten macro in the next update.
--
I go to trouble and time and effort to write my Usenet posts because I'm
kind hearted enough to care that everyone gets excellent researched data.