aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKenichi Handa2004-03-11 02:12:36 +0000
committerKenichi Handa2004-03-11 02:12:36 +0000
commita6d1872edbb34ad19382a21c010debba8970f209 (patch)
treeb0db8f7b9cd79702c48063fbd7c12044daa3a419 /lisp
parent0c4fbd05ec3bb7277cd99b0761191bbafe5e2d4d (diff)
downloademacs-a6d1872edbb34ad19382a21c010debba8970f209.tar.gz
emacs-a6d1872edbb34ad19382a21c010debba8970f209.zip
(define-translation-table): New function.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/international/mule.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index 28c93bb176d..1b193bc5fb9 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -1858,6 +1858,39 @@ See also the variable `nonascii-translation-table'."
1858 (set-char-table-extra-slot table 0 rev-table) 1858 (set-char-table-extra-slot table 0 rev-table)
1859 table)) 1859 table))
1860 1860
1861(defun make-translation-table-from-alist (alist)
1862 "Make translation table from N<->M mapping in ALIST.
1863ALIST is an alist, each element has the form (FROM . TO).
1864FROM and TO are a character or a vector of characters.
1865If FROM is a character, that character is translated to TO.
1866If FROM is a vector of characters, that sequence is translated to TO.
1867The second extra-slot of the value is a translation table for reverse mapping."
1868 (let ((table (make-char-table 'translation-table))
1869 (rev-table (make-char-table 'translation-table))
1870 max-lookup from to)
1871 (setq max-lookup 1)
1872 (dolist (elt alist)
1873 (setq from (car elt) to (cdr elt))
1874 (if (characterp from)
1875 (aset table from to)
1876 (let* ((ch (aref from 0))
1877 (val (aref table ch)))
1878 (aset table ch (cons (cons from to) val)))
1879 (setq max-lookup (max max-lookup (length from)))))
1880 (set-char-table-extra-slot table 1 max-lookup)
1881 (setq max-lookup 1)
1882 (dolist (elt alist)
1883 (setq from (cdr elt) to (car elt))
1884 (if (characterp from)
1885 (aset rev-table from to)
1886 (let* ((ch (aref from 0))
1887 (val (aref rev-table ch)))
1888 (aset rev-table ch (cons (cons from to) val)))
1889 (setq max-lookup (max max-lookup (length from)))))
1890 (set-char-table-extra-slot rev-table 1 max-lookup)
1891 (set-char-table-extra-slot table 0 rev-table)
1892 table))
1893
1861(defun define-translation-table (symbol &rest args) 1894(defun define-translation-table (symbol &rest args)
1862 "Define SYMBOL as the name of translation table made by ARGS. 1895 "Define SYMBOL as the name of translation table made by ARGS.
1863This sets up information so that the table can be used for 1896This sets up information so that the table can be used for