2015 |
(put symbol 'translation-table-id id) |
(put symbol 'translation-table-id id) |
2016 |
id)) |
id)) |
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 |
|
|
2046 |
(put 'with-category-table 'lisp-indent-function 1) |
(put 'with-category-table 'lisp-indent-function 1) |
2047 |
|
|
2048 |
(defmacro with-category-table (table &rest body) |
(defmacro with-category-table (table &rest body) |