[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "Unidecode" functionality in Emacs
From: |
Teemu Likonen |
Subject: |
Re: "Unidecode" functionality in Emacs |
Date: |
Tue, 20 Mar 2018 06:59:34 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.91 (gnu/linux) |
John Mastro [2018-03-19 15:04:29-07] wrote:
> There are "Unidecode" packages for Perl[1], Python[2], and Emacs[3]
> (derived from one another in that order). They each transliterate
> Unicode text to ASCII, e.g.:
>
> (unidecode "Déjà vu")
> ;=> "Deja vu"
> (unidecode "北亰")
> ;=> "Bei Jing "
>
> Does Emacs have equivalent functionality built-in?
I don't know of any built-in functions but external "iconv" tool can do
similar thing for Latin scripts. Here's an example Emacs Lisp function
wrapper for "iconv":
(defun tl-ascii-translit (string)
(with-temp-buffer
(insert string)
(call-process-region (point-min) (point-max)
"iconv" t t nil "-t" "ASCII//TRANSLIT")
(buffer-substring-no-properties (point-min) (point-max))))
Works for Latin scripts:
(tl-ascii-translit "Déjà vu") ;=> "Deja vu"
(tl-ascii-translit "北亰") ;=> "??"
--
/// Teemu Likonen - .-.. <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///
signature.asc
Description: PGP signature