Mercurial > emacs
comparison lisp/international/mule.el @ 57645:24ec89bbe7bc
(translate-region): Implement it in Lisp
as a front end of translate-region-internal.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 22 Oct 2004 13:10:23 +0000 |
parents | 5af5500fd1de |
children | a469fda36737 |
comparison
equal
deleted
inserted
replaced
57644:c0f2bdd90b5d | 57645:24ec89bbe7bc |
---|---|
2013 (setq done t)) | 2013 (setq done t)) |
2014 (setq id (1+ id))))) | 2014 (setq id (1+ id))))) |
2015 (put symbol 'translation-table-id id) | 2015 (put symbol 'translation-table-id id) |
2016 id)) | 2016 id)) |
2017 | 2017 |
2018 (defun translate-region (start end table) | |
2019 "From START to END, translate characters according to TABLE. | |
2020 TABLE is a string or a char-table. | |
2021 If TABLE is a string, the Nth character in it is the mapping | |
2022 for the character with code N. | |
2023 If TABLE is a char-table, the element for character N is the mapping | |
2024 for the character with code N. | |
2025 It returns the number of characters changed." | |
2026 (interactive | |
2027 (list (region-beginning) | |
2028 (region-end) | |
2029 (let (table l) | |
2030 (dotimes (i (length translation-table-vector)) | |
2031 (if (consp (aref translation-table-vector i)) | |
2032 (push (list (symbol-name | |
2033 (car (aref translation-table-vector i)))) l))) | |
2034 (if (not l) | |
2035 (error "No translation table defined")) | |
2036 (while (not table) | |
2037 (setq table (completing-read "Translation table: " l nil t))) | |
2038 (intern table)))) | |
2039 (if (symbolp table) | |
2040 (let ((val (get table 'translation-table))) | |
2041 (or (char-table-p val) | |
2042 (error "Invalid translation table name: %s" table)) | |
2043 (setq table val))) | |
2044 (translate-region-internal start end table)) | |
2045 | |
2018 (put 'with-category-table 'lisp-indent-function 1) | 2046 (put 'with-category-table 'lisp-indent-function 1) |
2019 | 2047 |
2020 (defmacro with-category-table (table &rest body) | 2048 (defmacro with-category-table (table &rest body) |
2021 "Evaluate BODY with category table of current buffer set to TABLE. | 2049 "Evaluate BODY with category table of current buffer set to TABLE. |
2022 The category table of the current buffer is saved, BODY is evaluated, | 2050 The category table of the current buffer is saved, BODY is evaluated, |