Mercurial > emacs
comparison lisp/international/quail.el @ 35076:778deeeffb6d
(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.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 05 Jan 2001 05:30:53 +0000 |
parents | 30f56d213a09 |
children | f9eed7569e52 |
comparison
equal
deleted
inserted
replaced
35075:f49c90fa95d7 | 35076:778deeeffb6d |
---|---|
1220 | 1220 |
1221 (put 'quail-error 'error-conditions '(quail-error error)) | 1221 (put 'quail-error 'error-conditions '(quail-error error)) |
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) |
1228 | 1253 |
1229 (defun quail-input-method (key) | 1254 (defun quail-input-method (key) |
1238 (window-live-p quail-guidance-win) | 1263 (window-live-p quail-guidance-win) |
1239 (eq (window-buffer quail-guidance-win) quail-guidance-buf) | 1264 (eq (window-buffer quail-guidance-win) quail-guidance-buf) |
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 |
1249 (set-buffer quail-guidance-buf) | 1279 (set-buffer quail-guidance-buf) |
1250 (erase-buffer))) | 1280 (erase-buffer))) |
1269 (if (overlay-start quail-overlay) | 1299 (if (overlay-start quail-overlay) |
1270 (delete-region (overlay-start quail-overlay) | 1300 (delete-region (overlay-start quail-overlay) |
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) |
1278 (assq (if (quail-kbd-translate) | 1309 (assq (if (quail-kbd-translate) |
1279 (quail-keyboard-translate key) key) | 1310 (quail-keyboard-translate key) key) |
1313 ;; Let's return the event(s) to the caller. | 1344 ;; Let's return the event(s) to the caller. |
1314 (setq unread-command-events | 1345 (setq unread-command-events |
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) |
1364 (assq (if (quail-kbd-translate) | 1363 (assq (if (quail-kbd-translate) |
1365 (quail-keyboard-translate key) key) | 1364 (quail-keyboard-translate key) key) |
1422 (setq quail-converting nil)))) | 1421 (setq quail-converting nil)))) |
1423 (if (overlay-start quail-conv-overlay) | 1422 (if (overlay-start quail-conv-overlay) |
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." |
1445 (setq quail-translating nil) | 1436 (setq quail-translating nil) |
1446 (if (buffer-live-p quail-guidance-buf) | 1437 (if (buffer-live-p quail-guidance-buf) |