comparison lisp/international/quail.el @ 31546:09bc2badb9e6

(quail-translation-docstring): New variable. (quail-show-keyboard-layout): Docstring modified. (quail-select-current): Likewise. (quail-build-decode-map): Change arg MAP to MAP-LIST to avoid infinite recursive call. (quail-help): Check quail-translation-docstring. Format of the output changed. (quail-help-insert-keymap-description): Adjusted for the above change.
author Kenichi Handa <handa@m17n.org>
date Mon, 11 Sep 2000 23:38:47 +0000
parents 8dff6bfed650
children 84fcbc8496b7
comparison
equal deleted inserted replaced
31545:ad28463a016b 31546:09bc2badb9e6
270 "Keymap used processing translation in complex Quail modes. 270 "Keymap used processing translation in complex Quail modes.
271 Only a few especially complex input methods use this map; 271 Only a few especially complex input methods use this map;
272 most use `quail-simple-translation-keymap' instead. 272 most use `quail-simple-translation-keymap' instead.
273 This map is activated while translation region is active.") 273 This map is activated while translation region is active.")
274 274
275 ;; Hide some verbose commands to make the output of quail-help 275 (defvar quail-translation-docstring
276 ;; concise. 276 "When you type keys, the echo area shows the possible characters
277 (let ((l '(quail-other-command 277 which correspond to that key sequence, each preceded by a digit. You
278 quail-self-insert-command 278 can select one of the characters shown by typing the corresponding
279 quail-delete-last-char))) 279 digit. Alternatively, you can use C-f and C-b to move through the
280 line to select the character you want, then type a letter to begin
281 entering another Chinese character or type a space or punctuation
282 character.
283
284 If there are more than ten possible characters for the given spelling,
285 the echo area shows ten characters at a time; you can use C-n to move
286 to the next group of ten, and C-p to move back to the previous group
287 of ten.")
288
289 ;; Categorize each Quail commands to make the output of quail-help
290 ;; concise. This is done by putting `quail-help' property. The value
291 ;; is:
292 ;; hide -- never show this command
293 ;; non-deterministic -- show only for non-deterministic input method
294 (let ((l '((quail-other-command . hide)
295 (quail-self-insert-command . hide)
296 (quail-delete-last-char . hide)
297 (quail-next-translation . non-deterministic)
298 (quail-prev-translation . non-deterministic)
299 (quail-next-translation-block . non-deterministic)
300 (quail-prev-translation-block . non-deterministic))))
280 (while l 301 (while l
281 (put (car l) 'quail-help-hide t) 302 (put (car (car l)) 'quail-help (cdr (car l)))
282 (setq l (cdr l)))) 303 (setq l (cdr l))))
283 304
284 (defvar quail-simple-translation-keymap 305 (defvar quail-simple-translation-keymap
285 (let ((map (make-keymap)) 306 (let ((map (make-keymap))
286 (i 0)) 307 (i 0))
356 If it is an alist, the element has the form (CHAR . STRING). Each character 377 If it is an alist, the element has the form (CHAR . STRING). Each character
357 in the current key is searched in the list and the corresponding string is 378 in the current key is searched in the list and the corresponding string is
358 shown. 379 shown.
359 If it is nil, the current key is shown. 380 If it is nil, the current key is shown.
360 381
361 DOCSTRING is the documentation string of this package. 382 DOCSTRING is the documentation string of this package. The command
383 `describe-input-method' shows this string while replacing the form
384 \\<VAR> in the string by the value of VAR. That value should be a
385 string. For instance, the form \\<quail-translation-docstring> is
386 replaced by a description about how to select a translation from a
387 list of candidates.
362 388
363 TRANSLATION-KEYS specifies additional key bindings used while translation 389 TRANSLATION-KEYS specifies additional key bindings used while translation
364 region is active. It is an alist of single key character vs. corresponding 390 region is active. It is an alist of single key character vs. corresponding
365 command to be called. 391 command to be called.
366 392
813 839
814 done-list)) 840 done-list))
815 841
816 ;;;###autoload 842 ;;;###autoload
817 (defun quail-show-keyboard-layout (&optional keyboard-type) 843 (defun quail-show-keyboard-layout (&optional keyboard-type)
818 "Show keyboard layout." 844 "Show the physical layout of the keyboard type KEYBOARD-TYPE.
845
846 The variable `quail-keyboard-layout-type' holds the currently selected
847 keyboard type."
819 (interactive 848 (interactive
820 (list (completing-read "Keyboard type (default, current choise): " 849 (list (completing-read "Keyboard type (default, current choise): "
821 quail-keyboard-layout-alist 850 quail-keyboard-layout-alist
822 nil t))) 851 nil t)))
823 (or (and keyboard-type (> (length keyboard-type) 0)) 852 (or (and keyboard-type (> (length keyboard-type) 0))
1409 (save-excursion 1438 (save-excursion
1410 (set-buffer quail-guidance-buf) 1439 (set-buffer quail-guidance-buf)
1411 (erase-buffer)))) 1440 (erase-buffer))))
1412 1441
1413 (defun quail-select-current () 1442 (defun quail-select-current ()
1414 "Select the current text shown in Quail translation region." 1443 "Accept the currently selected translation."
1415 (interactive) 1444 (interactive)
1416 (quail-terminate-translation)) 1445 (quail-terminate-translation))
1417 1446
1418 ;; Update the current translation status according to CONTROL-FLAG. 1447 ;; Update the current translation status according to CONTROL-FLAG.
1419 ;; If CONTROL-FLAG is integer value, it is the number of keys in the 1448 ;; If CONTROL-FLAG is integer value, it is the number of keys in the
2192 (if (and (eq minibuffer-completion-table 'read-file-name-internal) 2221 (if (and (eq minibuffer-completion-table 'read-file-name-internal)
2193 (file-directory-p (buffer-string))) 2222 (file-directory-p (buffer-string)))
2194 (select-window (active-minibuffer-window)) 2223 (select-window (active-minibuffer-window))
2195 (exit-minibuffer)))))) 2224 (exit-minibuffer))))))
2196 2225
2197 (defun quail-build-decode-map (map key decode-map num &optional maxnum ignores) 2226 ;; Accumulate in the cdr part of DECODE-MAP all pairs of key sequences
2198 (let ((translation (quail-get-translation (car map) key (length key))) 2227 ;; vs the corresponding translations defined in the Quail map
2199 elt) 2228 ;; specified by the first element MAP-LIST. Each pair has the form
2229 ;; (KEYSEQ . TRANSLATION). DECODE-MAP should have the form
2230 ;; (decode-map . ALIST), where ALIST is an alist of length NUM. KEY
2231 ;; is a key sequence to reach MAP.
2232 ;; Optional 5th arg MAXNUM limits the number of accumulated pairs.
2233 ;; Optional 6th arg IGNORES is a list of translations to ignore.
2234
2235 (defun quail-build-decode-map (map-list key decode-map num
2236 &optional maxnum ignores)
2237 (let* ((map (car map-list))
2238 (translation (quail-get-translation (car map) key (length key)))
2239 elt)
2200 (cond ((integerp translation) 2240 (cond ((integerp translation)
2241 ;; Accept only non-ASCII chars not listed in IGNORES.
2201 (when (and (> translation 255) (not (memq translation ignores))) 2242 (when (and (> translation 255) (not (memq translation ignores)))
2202 (setcdr decode-map 2243 (setcdr decode-map
2203 (cons (cons key translation) (cdr decode-map))) 2244 (cons (cons key translation) (cdr decode-map)))
2204 (setq num (1+ num)))) 2245 (setq num (1+ num))))
2205 ((consp translation) 2246 ((consp translation)
2206 (setq translation (cdr translation)) 2247 (setq translation (cdr translation))
2207 (let ((multibyte nil)) 2248 (let ((multibyte nil))
2208 (mapc (function (lambda (x) 2249 (mapc (function (lambda (x)
2250 ;; Accept only non-ASCII chars not
2251 ;; listed in IGNORES.
2209 (if (and (if (integerp x) (> x 255) 2252 (if (and (if (integerp x) (> x 255)
2210 (> (string-bytes x) (length x))) 2253 (> (string-bytes x) (length x)))
2211 (not (member x ignores))) 2254 (not (member x ignores)))
2212 (setq multibyte t)))) 2255 (setq multibyte t))))
2213 translation) 2256 translation)
2216 (cons (cons key translation) (cdr decode-map))) 2259 (cons (cons key translation) (cdr decode-map)))
2217 (setq num (+ num (length translation))))))) 2260 (setq num (+ num (length translation)))))))
2218 (if (and maxnum (> num maxnum)) 2261 (if (and maxnum (> num maxnum))
2219 (- num) 2262 (- num)
2220 (setq map (cdr map)) 2263 (setq map (cdr map))
2264 ;; Recursively check the deeper map.
2221 (while (and map (>= num 0)) 2265 (while (and map (>= num 0))
2222 (setq elt (car map) map (cdr map)) 2266 (setq elt (car map) map (cdr map))
2223 (when (and (integerp (car elt)) (consp (cdr elt))) 2267 (when (and (integerp (car elt)) (consp (cdr elt))
2224 (setq num (quail-build-decode-map (cdr elt) 2268 (not (memq (cdr elt) map-list)))
2269 (setq num (quail-build-decode-map (cons (cdr elt) map-list)
2225 (format "%s%c" key (car elt)) 2270 (format "%s%c" key (car elt))
2226 decode-map num maxnum ignores)))) 2271 decode-map num maxnum ignores))))
2227 num))) 2272 num)))
2273
2274 ;; Insert the pairs of key sequences vs the corresponding translations
2275 ;; stored in DECODE-MAP by the concise format. DECODE-MAP should be
2276 ;; made by `quail-build-decode-map' (which see).
2228 2277
2229 (defun quail-insert-decode-map (decode-map) 2278 (defun quail-insert-decode-map (decode-map)
2230 (setq decode-map 2279 (setq decode-map
2231 (sort (cdr decode-map) 2280 (sort (cdr decode-map)
2232 (function (lambda (x y) 2281 (function (lambda (x y)
2233 (setq x (car x) y (car y)) 2282 (setq x (car x) y (car y))
2234 (or (> (length x) (length y)) 2283 (or (> (length x) (length y))
2235 (and (= (length x) (length y)) 2284 (and (= (length x) (length y))
2236 (not (string< x y)))))))) 2285 (not (string< x y))))))))
2237 (let ((frame-width (frame-width)) 2286 (let ((frame-width (frame-width))
2238 (short-key-width 3) 2287 (single-key-width 3)
2239 (short-trans-width 4) 2288 (single-trans-width 4)
2240 (long-key-width 3) 2289 (multiple-key-width 3)
2241 (short-list nil) 2290 (single-list nil)
2242 (long-list nil) 2291 (multiple-list nil)
2243 elt trans width pos cols rows col row str col-width) 2292 elt trans width pos cols rows col row str col-width)
2244 ;; Divide the decoding map into shorter one and longer one. 2293 ;; Divide the elements of decoding map into single ones (i.e. the
2294 ;; one that has single translation) and multibyte ones (i.e. the
2295 ;; one that has multiple translations).
2245 (while decode-map 2296 (while decode-map
2246 (setq elt (car decode-map) decode-map (cdr decode-map) 2297 (setq elt (car decode-map) decode-map (cdr decode-map)
2247 trans (cdr elt)) 2298 trans (cdr elt))
2248 (if (and (vectorp trans) (= (length trans) 1)) 2299 (if (and (vectorp trans) (= (length trans) 1))
2249 (setq trans (aref trans 0))) 2300 (setq trans (aref trans 0)))
2250 (if (vectorp trans) 2301 (if (vectorp trans)
2251 (setq long-list (cons elt long-list)) 2302 (setq multiple-list (cons elt multiple-list))
2252 (setq short-list (cons (cons (car elt) trans) short-list) 2303 (setq single-list (cons (cons (car elt) trans) single-list)
2253 width (if (stringp trans) (string-width trans) 2304 width (if (stringp trans) (string-width trans)
2254 (char-width trans))) 2305 (char-width trans)))
2255 (if (> width short-trans-width) 2306 (if (> width single-trans-width)
2256 (setq short-trans-width width))) 2307 (setq single-trans-width width)))
2257 (setq width (length (car elt))) 2308 (setq width (length (car elt)))
2258 (if (> width short-key-width) 2309 (if (> width single-key-width)
2259 (setq short-key-width width)) 2310 (setq single-key-width width))
2260 (if (> width long-key-width) 2311 (if (> width multiple-key-width)
2261 (setq long-key-width width))) 2312 (setq multiple-key-width width)))
2262 (when short-list 2313 (when single-list
2263 (setq col-width (+ short-key-width 1 short-trans-width 1) 2314 (setq col-width (+ single-key-width 1 single-trans-width 1)
2264 cols (/ frame-width col-width) 2315 cols (/ frame-width col-width)
2265 rows (/ (length short-list) cols)) 2316 rows (/ (length single-list) cols))
2266 (if (> (% (length short-list) cols) 0) 2317 (if (> (% (length single-list) cols) 0)
2267 (setq rows (1+ rows))) 2318 (setq rows (1+ rows)))
2268 (insert "key") 2319 (insert "key")
2269 (indent-to (1+ short-key-width)) 2320 (indent-to (1+ single-key-width))
2270 (insert "char") 2321 (insert "char")
2271 (indent-to (1+ col-width)) 2322 (indent-to (1+ col-width))
2272 (insert "[type a key sequence to insert the corresponding character]\n") 2323 (insert "[type a key sequence to insert the corresponding character]\n")
2273 (setq pos (point)) 2324 (setq pos (point))
2274 (insert-char ?\n (+ rows 2)) 2325 (insert-char ?\n (+ rows 2))
2275 (goto-char pos) 2326 (goto-char pos)
2276 (setq col (- col-width) row 0) 2327 (setq col (- col-width) row 0)
2277 (while short-list 2328 (while single-list
2278 (setq elt (car short-list) short-list (cdr short-list)) 2329 (setq elt (car single-list) single-list (cdr single-list))
2279 (when (= (% row rows) 0) 2330 (when (= (% row rows) 0)
2280 (goto-char pos) 2331 (goto-char pos)
2281 (setq col (+ col col-width)) 2332 (setq col (+ col col-width))
2282 (move-to-column col t) 2333 (move-to-column col t)
2283 (insert-char ?- short-key-width) 2334 (insert-char ?- single-key-width)
2284 (insert ? ) 2335 (insert ? )
2285 (insert-char ?- short-trans-width) 2336 (insert-char ?- single-trans-width)
2286 (forward-line 1)) 2337 (forward-line 1))
2287 (move-to-column col t) 2338 (move-to-column col t)
2288 (insert (car elt)) 2339 (insert (car elt))
2289 (indent-to (+ col short-key-width 1)) 2340 (indent-to (+ col single-key-width 1))
2290 (insert (cdr elt)) 2341 (insert (cdr elt))
2291 (forward-line 1) 2342 (forward-line 1)
2292 (setq row (1+ row))) 2343 (setq row (1+ row)))
2293 (goto-char (point-max))) 2344 (goto-char (point-max)))
2294 2345
2295 (when long-list 2346 (when multiple-list
2296 (insert "key") 2347 (insert "key")
2297 (indent-to (1+ long-key-width)) 2348 (indent-to (1+ multiple-key-width))
2298 (insert "character(s) [type a key (sequence) and select one from the list]\n") 2349 (insert "character(s) [type a key (sequence) and select one from the list]\n")
2299 (insert-char ?- long-key-width) 2350 (insert-char ?- multiple-key-width)
2300 (insert " ------------\n") 2351 (insert " ------------\n")
2301 (while long-list 2352 (while multiple-list
2302 (setq elt (car long-list) long-list (cdr long-list)) 2353 (setq elt (car multiple-list) multiple-list (cdr multiple-list))
2303 (insert (car elt)) 2354 (insert (car elt))
2304 (indent-to long-key-width) 2355 (indent-to multiple-key-width)
2305 (if (vectorp (cdr elt)) 2356 (if (vectorp (cdr elt))
2306 (mapc (function 2357 (mapc (function
2307 (lambda (x) 2358 (lambda (x)
2308 (let ((width (if (integerp x) (char-width x) 2359 (let ((width (if (integerp x) (char-width x)
2309 (string-width x)))) 2360 (string-width x))))
2310 (when (> (+ (current-column) 1 width) frame-width) 2361 (when (> (+ (current-column) 1 width) frame-width)
2311 (insert "\n") 2362 (insert "\n")
2312 (indent-to long-key-width)) 2363 (indent-to multiple-key-width))
2313 (insert " " x)))) 2364 (insert " " x))))
2314 (cdr elt)) 2365 (cdr elt))
2315 (insert " " (cdr elt))) 2366 (insert " " (cdr elt)))
2316 (insert ?\n)) 2367 (insert ?\n))
2317 (insert ?\n)))) 2368 (insert ?\n))))
2318 2369
2319 (defun quail-help (&optional package) 2370 (defun quail-help (&optional package)
2320 "Show brief description of the current Quail package. 2371 "Show brief description of the current Quail package.
2321 Optional 2nd arg PACKAGE specifies the alternative Quail package to describe." 2372 Optional 2nd arg PACKAGE specifies the name of alternative Quail
2373 package to describe."
2322 (interactive) 2374 (interactive)
2323 (if package 2375 (if package
2324 (setq package (assoc package quail-package-alist)) 2376 (setq package (assoc package quail-package-alist))
2325 (setq package quail-current-package)) 2377 (setq package quail-current-package))
2326 (let ((help-xref-mule-regexp help-xref-mule-regexp-template)) 2378 (let ((help-xref-mule-regexp help-xref-mule-regexp-template))
2329 (set-buffer standard-output) 2381 (set-buffer standard-output)
2330 (setq quail-current-package package) 2382 (setq quail-current-package package)
2331 (insert "Input method: " (quail-name) 2383 (insert "Input method: " (quail-name)
2332 " (mode line indicator:" 2384 " (mode line indicator:"
2333 (quail-title) 2385 (quail-title)
2334 ")\n\n" 2386 ")\n\n")
2335 (quail-docstring)) 2387 (save-restriction
2388 (narrow-to-region (point) (point))
2389 (insert (quail-docstring))
2390 (goto-char (point-min))
2391 (with-syntax-table emacs-lisp-mode-syntax-table
2392 (while (re-search-forward "\\\\<\\sw\\(\\sw\\|\\s_\\)+>" nil t)
2393 (let ((sym (intern-soft
2394 (buffer-substring (+ (match-beginning 0) 2)
2395 (1- (point))))))
2396 (if (and (boundp sym)
2397 (stringp (symbol-value sym)))
2398 (replace-match (symbol-value sym) t t)))))
2399 (goto-char (point-max)))
2336 (or (bolp) 2400 (or (bolp)
2337 (insert "\n")) 2401 (insert "\n"))
2338 (insert "\n") 2402 (insert "\n")
2339 2403
2340 (let ((done-list nil)) 2404 (let ((done-list nil))
2341 ;; Show keyboard layout if the current package requests it.. 2405 ;; Show keyboard layout if the current package requests it..
2342 (when (quail-show-layout) 2406 (when (quail-show-layout)
2343 (insert 2407 (insert "
2344 "Physical key layout for this input method is as below. 2408 KEYBOARD LAYOUT
2409 ---------------
2410 Physical key layout for this input method is as below.
2345 You can input a character in the table by typing a key 2411 You can input a character in the table by typing a key
2346 at the same location on your keyboard.\n") 2412 at the same location on your keyboard.\n")
2347 (setq done-list 2413 (setq done-list
2348 (quail-insert-kbd-layout quail-keyboard-layout)) 2414 (quail-insert-kbd-layout quail-keyboard-layout))
2349 (insert "It is assumed that your keyboard type is `") 2415 (insert "It is assumed that your keyboard type is `")
2362 (insert ".\n")) 2428 (insert ".\n"))
2363 2429
2364 ;; Show key sequences. 2430 ;; Show key sequences.
2365 (let ((decode-map (list 'decode-map)) 2431 (let ((decode-map (list 'decode-map))
2366 elt pos num) 2432 elt pos num)
2367 (setq num (quail-build-decode-map (quail-map) "" decode-map 2433 (setq num (quail-build-decode-map (list (quail-map)) "" decode-map
2368 0 512 done-list)) 2434 0 512 done-list))
2369 (when (> num 0) 2435 (when (> num 0)
2370 (insert ?\n) 2436 (insert "
2437 KEY SEQUENCE
2438 -----------
2439 ")
2371 (if (quail-show-layout) 2440 (if (quail-show-layout)
2372 (insert "You can also input more characters") 2441 (insert "You can also input more characters")
2373 (insert "You can input characters")) 2442 (insert "You can input characters"))
2374 (insert " by the following key sequences:\n") 2443 (insert " by the following key sequences:\n")
2375 (quail-insert-decode-map decode-map)))) 2444 (quail-insert-decode-map decode-map))))
2376 2445
2377 (quail-help-insert-keymap-description 2446 (quail-help-insert-keymap-description
2378 (quail-translation-keymap) 2447 (quail-translation-keymap)
2379 "--- key bindings for selecting a character ---\n") 2448 "\
2449 KEY BINDINGS FOR TRANSLATION
2450 ----------------------------\n")
2380 (insert ?\n) 2451 (insert ?\n)
2381 (if (quail-conversion-keymap) 2452 (if (quail-conversion-keymap)
2382 (quail-help-insert-keymap-description 2453 (quail-help-insert-keymap-description
2383 (quail-conversion-keymap) 2454 (quail-conversion-keymap)
2384 "--- Key bindings for converting a character (sequence) ---\n")) 2455 "\
2456 KEY BINDINGS FOR CONVERSION
2457 ---------------------------\n"))
2385 (help-setup-xref (list #'quail-help (quail-name)) 2458 (help-setup-xref (list #'quail-help (quail-name))
2386 (interactive-p)) 2459 (interactive-p))
2387 (setq quail-current-package nil))))) 2460 (setq quail-current-package nil)))))
2388 2461
2389 (defun quail-help-insert-keymap-description (keymap &optional header) 2462 (defun quail-help-insert-keymap-description (keymap &optional header)
2390 (let (pos1 pos2 eol) 2463 (let (pos1 pos2 eol)
2391 (setq pos1 (point)) 2464 (setq pos1 (point))
2392 (if header 2465 (if header
2393 (insert header)) 2466 (insert header))
2394 (insert (substitute-command-keys "\\{keymap}")) 2467 (save-excursion
2395 (goto-char pos1) 2468 (insert (substitute-command-keys "\\{keymap}")))
2396 ;; Skip headers "--- key bindings ---", etc. 2469 ;; Skip headers "key bindings", etc.
2397 (forward-line 3) 2470 (forward-line 3)
2398 (setq pos2 (point)) 2471 (setq pos2 (point))
2399 (with-syntax-table emacs-lisp-mode-syntax-table 2472 (with-syntax-table emacs-lisp-mode-syntax-table
2400 (while (re-search-forward "\\sw\\(\\sw\\|\\s_\\)+" nil t) 2473 (while (re-search-forward "\\sw\\(\\sw\\|\\s_\\)+" nil t)
2401 (let ((sym (intern-soft (buffer-substring (match-beginning 0) 2474 (let ((sym (intern-soft (buffer-substring (match-beginning 0)
2402 (point))))) 2475 (point)))))
2403 (if (and sym (fboundp sym) 2476 (if (and sym (fboundp sym)
2404 (get sym 'quail-help-hide)) 2477 (or (eq (get sym 'quail-help) 'hide)
2478 (and (quail-deterministic)
2479 (eq (get sym 'quail-help) 'non-deterministic))))
2405 (delete-region (line-beginning-position) 2480 (delete-region (line-beginning-position)
2406 (1+ (line-end-position))))))) 2481 (1+ (line-end-position)))))))
2407 (goto-char pos2) 2482 (goto-char pos2)
2408 (while (not (eobp)) 2483 (while (not (eobp))
2409 (if (looking-at "[ \t]*$") 2484 (if (looking-at "[ \t]*$")