When using the command translate-region, the command asks to use which table. There are already some predefined tables (by pressing TAB) such as

cp51932-decode cp51932-encode eucjp-ms-decode eucjp-ms-encode japanese-ucs-cp932-to-jis-map japanese-ucs-glibc-to-jis-map japanese-ucs-jis-to-cp932-map japanese-ucs-jis-to-glibc-map jisx0213-to-unicode ucs-normalize-hfs-nfd-table ucs-normalize-nfd-table ucs-normalize-nfkd-table unicode-to-jisx0213

What if someone likes to create its own table?

For example, assume that one would like to create a conversion table like below:

1 --> 2
a --> x
n --> m
8 --> 0
σ --> s

What I have tried: based on one of the above tables, I defined a table as bellow, but I get the error apply: Wrong type argument: integerp, x

(let ((map
     (1 . 2)
     (a . x)
     (n . m)
     (8 . 0)
     (σ . s)
        (define-translation-table 'my-conversion-decode map)
  (mapc #'(lambda (x)
        (let ((tmp (car x)))
          (setcar x (cdr x)) (setcdr x tmp)))
  (define-translation-table 'my-conversion-encode map))

The map should be a char-to-char alist. In Emacs Lisp, a character is a number, the character x can be written as ?x or its Unicode code point 120. If you just write x, it's a symbol.

The following works from here:

(let ((map '((?1 . ?2)
             (?a . ?x)
             (?n . ?m)
             (?8 . ?0)
             (?σ . ?s))))
  (define-translation-table 'my-conversion-decode map))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.