diff options
| author | Kenichi Handa | 2001-01-05 05:30:53 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2001-01-05 05:30:53 +0000 |
| commit | c5f3770d9917d514805606998816cf4f552efc87 (patch) | |
| tree | 3b7a7d60418a47e6cfe5892ecd6ab472e94b39a0 | |
| parent | 3b923ad8dc1c3667452dff1de43a837ba3ce8ba7 (diff) | |
| download | emacs-c5f3770d9917d514805606998816cf4f552efc87.tar.gz emacs-c5f3770d9917d514805606998816cf4f552efc87.zip | |
(quail-input-string-to-events): New function.
(quail-input-method): Convert input string to events here.
(quail-start-translation): Return input string, not event list.
(quail-start-conversion): Likewise.
| -rw-r--r-- | lisp/international/quail.el | 95 |
1 files changed, 43 insertions, 52 deletions
diff --git a/lisp/international/quail.el b/lisp/international/quail.el index 8e378104898..46e14592010 100644 --- a/lisp/international/quail.el +++ b/lisp/international/quail.el | |||
| @@ -1222,6 +1222,31 @@ The returned value is a Quail map specific to KEY." | |||
| 1222 | (defun quail-error (&rest args) | 1222 | (defun quail-error (&rest args) |
| 1223 | (signal 'quail-error (apply 'format args))) | 1223 | (signal 'quail-error (apply 'format args))) |
| 1224 | 1224 | ||
| 1225 | |||
| 1226 | ;; Convert input string STR to a list of events while interleaving | ||
| 1227 | ;; with the following special events: | ||
| 1228 | ;; (compose-last-chars LEN COMPONENTS) | ||
| 1229 | ;; (quail-advice INPUT-STRING) | ||
| 1230 | |||
| 1231 | (defun quail-input-string-to-events (str) | ||
| 1232 | (let* ((events (string-to-list str)) | ||
| 1233 | (len (length str)) | ||
| 1234 | (idx len) | ||
| 1235 | composition from to) | ||
| 1236 | (while (and (> idx 0) | ||
| 1237 | (setq composition (find-composition idx 0 str t))) | ||
| 1238 | (setq from (car composition) to (nth 1 composition)) | ||
| 1239 | (setcdr (nthcdr (1- to) events) | ||
| 1240 | (cons (list 'compose-last-chars (- to from) | ||
| 1241 | (and (not (nth 3 composition)) (nth 2 composition))) | ||
| 1242 | (nthcdr to events))) | ||
| 1243 | (setq idx (1- from))) | ||
| 1244 | (if (or (get-text-property 0 'advice str) | ||
| 1245 | (next-single-property-change 0 'advice str)) | ||
| 1246 | (setq events | ||
| 1247 | (nconc events (list (list 'quail-advice str))))) | ||
| 1248 | events)) | ||
| 1249 | |||
| 1225 | (defvar quail-translating nil) | 1250 | (defvar quail-translating nil) |
| 1226 | (defvar quail-converting nil) | 1251 | (defvar quail-converting nil) |
| 1227 | (defvar quail-conversion-str nil) | 1252 | (defvar quail-conversion-str nil) |
| @@ -1240,9 +1265,14 @@ The returned value is a Quail map specific to KEY." | |||
| 1240 | (not input-method-use-echo-area)) | 1265 | (not input-method-use-echo-area)) |
| 1241 | (quail-show-guidance-buf)) | 1266 | (quail-show-guidance-buf)) |
| 1242 | (unwind-protect | 1267 | (unwind-protect |
| 1243 | (if (quail-conversion-keymap) | 1268 | (let ((input-string (if (quail-conversion-keymap) |
| 1244 | (quail-start-conversion key) | 1269 | (quail-start-conversion key) |
| 1245 | (quail-start-translation key)) | 1270 | (quail-start-translation key)))) |
| 1271 | (when (and (stringp input-string) | ||
| 1272 | (> (length input-string) 0)) | ||
| 1273 | (if input-method-exit-on-first-char | ||
| 1274 | (list (aref input-string 0)) | ||
| 1275 | (quail-input-string-to-events input-string)))) | ||
| 1246 | (quail-delete-overlays) | 1276 | (quail-delete-overlays) |
| 1247 | (if (buffer-live-p quail-guidance-buf) | 1277 | (if (buffer-live-p quail-guidance-buf) |
| 1248 | (save-excursion | 1278 | (save-excursion |
| @@ -1271,7 +1301,8 @@ The returned value is a Quail map specific to KEY." | |||
| 1271 | (overlay-end quail-overlay)))) | 1301 | (overlay-end quail-overlay)))) |
| 1272 | 1302 | ||
| 1273 | (defun quail-start-translation (key) | 1303 | (defun quail-start-translation (key) |
| 1274 | "Start translation of the typed character KEY by the current Quail package." | 1304 | "Start translation of the typed character KEY by the current Quail package. |
| 1305 | Return the input string." | ||
| 1275 | ;; Check the possibility of translating KEY. | 1306 | ;; Check the possibility of translating KEY. |
| 1276 | ;; If KEY is nil, we can anyway start translation. | 1307 | ;; If KEY is nil, we can anyway start translation. |
| 1277 | (if (or (and (integerp key) | 1308 | (if (or (and (integerp key) |
| @@ -1315,49 +1346,17 @@ The returned value is a Quail map specific to KEY." | |||
| 1315 | (string-to-list (this-single-command-raw-keys))) | 1346 | (string-to-list (this-single-command-raw-keys))) |
| 1316 | (setq quail-translating nil)))) | 1347 | (setq quail-translating nil)))) |
| 1317 | (quail-delete-region) | 1348 | (quail-delete-region) |
| 1318 | (if (and quail-current-str (> (length quail-current-str) 0)) | 1349 | quail-current-str) |
| 1319 | (let* ((len (length quail-current-str)) | ||
| 1320 | (idx 0) | ||
| 1321 | (val (find-composition 0 len quail-current-str)) | ||
| 1322 | (advice (get-text-property idx 'advice quail-current-str)) | ||
| 1323 | char) | ||
| 1324 | ;; If the selected input has `advice' function, generate | ||
| 1325 | ;; a special event (quail-advice QUAIL-CURRENT-STR). | ||
| 1326 | (if advice | ||
| 1327 | (setq generated-events | ||
| 1328 | (cons (list 'quail-advice quail-current-str) | ||
| 1329 | generated-events))) | ||
| 1330 | ;; Push characters in quail-current-str one by one to | ||
| 1331 | ;; generated-events while interleaving it with a special | ||
| 1332 | ;; event (compose-last-chars LEN) at each composition | ||
| 1333 | ;; end. | ||
| 1334 | (while (<= idx len) | ||
| 1335 | (when (and val (= idx (nth 1 val))) | ||
| 1336 | (setq generated-events | ||
| 1337 | (cons (list 'compose-last-chars (- idx (car val))) | ||
| 1338 | generated-events)) | ||
| 1339 | (setq val (find-composition idx len quail-current-str))) | ||
| 1340 | (when (< idx len) | ||
| 1341 | (setq char (aref quail-current-str idx)) | ||
| 1342 | (or enable-multibyte-characters | ||
| 1343 | (setq char (multibyte-char-to-unibyte char))) | ||
| 1344 | (setq generated-events (cons char generated-events))) | ||
| 1345 | (setq idx (1+ idx))) | ||
| 1346 | ;; Reorder generated-events. | ||
| 1347 | (setq generated-events (nreverse generated-events)))) | ||
| 1348 | (if (and input-method-exit-on-first-char generated-events) | ||
| 1349 | (list (car generated-events)) | ||
| 1350 | generated-events)) | ||
| 1351 | 1350 | ||
| 1352 | ;; Since KEY doesn't start any translation, just return it. | 1351 | ;; Since KEY doesn't start any translation, just return it. |
| 1353 | ;; But translate KEY if necessary. | 1352 | ;; But translate KEY if necessary. |
| 1354 | (if (and (integerp key) | 1353 | (if (quail-kbd-translate) |
| 1355 | (quail-kbd-translate)) | ||
| 1356 | (setq key (quail-keyboard-translate key))) | 1354 | (setq key (quail-keyboard-translate key))) |
| 1357 | (list key))) | 1355 | (char-to-string key))) |
| 1358 | 1356 | ||
| 1359 | (defun quail-start-conversion (key) | 1357 | (defun quail-start-conversion (key) |
| 1360 | "Start conversion of the typed character KEY by the current Quail package." | 1358 | "Start conversion of the typed character KEY by the current Quail package. |
| 1359 | Return the input string." | ||
| 1361 | ;; Check the possibility of translating KEY. | 1360 | ;; Check the possibility of translating KEY. |
| 1362 | ;; If KEY is nil, we can anyway start translation. | 1361 | ;; If KEY is nil, we can anyway start translation. |
| 1363 | (if (or (and (integerp key) | 1362 | (if (or (and (integerp key) |
| @@ -1424,21 +1423,13 @@ The returned value is a Quail map specific to KEY." | |||
| 1424 | (delete-region (overlay-start quail-conv-overlay) | 1423 | (delete-region (overlay-start quail-conv-overlay) |
| 1425 | (overlay-end quail-conv-overlay))) | 1424 | (overlay-end quail-conv-overlay))) |
| 1426 | (if (> (length quail-conversion-str) 0) | 1425 | (if (> (length quail-conversion-str) 0) |
| 1427 | (setq generated-events | 1426 | quail-conversion-str)) |
| 1428 | (string-to-list | ||
| 1429 | (if enable-multibyte-characters | ||
| 1430 | quail-conversion-str | ||
| 1431 | (string-make-unibyte quail-conversion-str))))) | ||
| 1432 | (if (and input-method-exit-on-first-char generated-events) | ||
| 1433 | (list (car generated-events)) | ||
| 1434 | generated-events)) | ||
| 1435 | 1427 | ||
| 1436 | ;; Since KEY doesn't start any translation, just return it. | 1428 | ;; Since KEY doesn't start any translation, just return it. |
| 1437 | ;; But translate KEY if necessary. | 1429 | ;; But translate KEY if necessary. |
| 1438 | (if (and (integerp key) | 1430 | (if (quail-kbd-translate) |
| 1439 | (quail-kbd-translate)) | ||
| 1440 | (setq key (quail-keyboard-translate key))) | 1431 | (setq key (quail-keyboard-translate key))) |
| 1441 | (list key))) | 1432 | (char-to-string key))) |
| 1442 | 1433 | ||
| 1443 | (defun quail-terminate-translation () | 1434 | (defun quail-terminate-translation () |
| 1444 | "Terminate the translation of the current key." | 1435 | "Terminate the translation of the current key." |