This script, in answer to a question on the N++ Open Discussion forum, will convert a 4 digit (or less) unicode value to it's character equivalent. For example, enter "20ac", then run the script (perhaps from a shortcut key), and it will replace it with the euro currency symbol.
importstringdefisHexDigit(char):result=(charinstring.hexdigits)returnresultdefisHexString(str):resultmap=map(isHexDigit,str)result=(Falsenotinresultmap)returnresult# Get the word nearest the cursor# Could use editor.getCurrentWord() for this,# but we want to be clever when the "word" is longer than 4 digits# If it is, then we take the position of the cursor as the end# If it's still longer, then we use the last 4 characters.wordStart=editor.wordStartPosition(editor.getCurrentPos(),True)wordEnd=editor.wordEndPosition(editor.getCurrentPos(),True)ifwordEnd-wordStart>4:wordEnd=editor.getCurrentPos()ifwordEnd-wordStart>4:wordStart=wordEnd-4code=editor.getTextRange(wordStart,wordEnd)# Check that the string is completely hexifisHexString(code):# Convert the code to a unicode stringunicodeString=(r'\u'+('0000'+code)[-4:]).decode('raw-unicode-escape')editor.setTarget(wordStart,wordEnd)# Paste the text ineditor.replaceTarget(unicodeString.encode('utf8'))newPos=wordStart+len(unicodeString.encode('utf8'))editor.setAnchor(newPos)editor.setCurrentPos(newPos)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This script, in answer to a question on the N++ Open Discussion forum, will convert a 4 digit (or less) unicode value to it's character equivalent. For example, enter "20ac", then run the script (perhaps from a shortcut key), and it will replace it with the euro currency symbol.