Escape/Unescape a unicode notations (\uNNNN
) for Emacs.
You can install this package from MELPA.
M-x package-install
RET unicode-escape
RET
Then put the following into your setting file (optional):
(require 'unicode-escape)
Escape obj
to unicode notation. (character or string)
surrogate pair conversion is enabled.
(unicode-escape "Hello") ;;=> "Hello"
(unicode-escape ?\u2603) ;;=> "\\u2603"
(unicode-escape "こんにちは") ;;=> "\\u3053\\u3093\\u306B\\u3061\\u306F"
(unicode-escape "U+1F363 is 🍣") ;;=> "U+1F363 is \\uD83C\\uDF63"
Similar to unicode-escape
.
surrogate pair conversion is disabled.
non-BMP characters convert to \UNNNNNNNN
.
(unicode-escape* "U+1F363 is 🍣") ;;=> "U+1F363 is \\U0001F363"
Unescape unicode string
.
surrogate pair convert to original code point.
(unicode-unescape "\\u3053\\u3093\\u306B\\u3061\\u306F") ;;=> "こんにちは"
(unicode-unescape "\\uD83C\\uDF63") ;;=> "🍣"
Similar to unicode-unescape
.
surrogate pair conversion is disabled.
(unicode-unescape* "\\uD83C\\uDF63" nil) ;;=> "\uD83C\uDF63"
Note: Prefix argument (C-u) is given, surrogate pair conversion is disabled.
Escape unicode characters from region start
to end
.
Unescape unicode notations from region start
to end
.
https://en.wikipedia.org/wiki/Surrogate_pair
By default, non-BMP characters (U+10000..U+10FFFF) are converted to 16-bit code of pairs.
(unicode-escape "🙈🙉🙊")
;;=> "\\uD83D\\uDE48\\uD83D\\uDE49\\uD83D\\uDE4A"
(unicode-escape "🙈🙉🙊" nil) ; or `unicode-escape*'
;;=> "\\U0001F648\\U0001F649\\U0001F64A"
MIT License