aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2009-08-10 21:42:41 +0000
committerStefan Monnier2009-08-10 21:42:41 +0000
commit51c4341fe8226a47e0056c4bd2d63c4fe70848c1 (patch)
treeea77608b0d663795974b39735236c6561cfa99e6
parent64657387b27fef24a961228d7c7b5f18a5fa05f3 (diff)
downloademacs-51c4341fe8226a47e0056c4bd2d63c4fe70848c1.tar.gz
emacs-51c4341fe8226a47e0056c4bd2d63c4fe70848c1.zip
(quail-completion-1): Simplify.
(quail-define-rules): Use slightly more compact code. (quail-insert-decode-map): Propertize keys, compact columns.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/international/quail.el107
2 files changed, 71 insertions, 45 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0ae8c7cfdd7..8c649b17718 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,14 @@
12009-08-10 Stefan Monnier <monnier@iro.umontreal.ca> 12009-08-10 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * international/mule-cmds.el (mule-keymap, mule-menu-keymap)
4 (describe-language-environment-map, setup-language-environment-map)
5 (set-coding-system-map): Move initialization into declaration.
6 (set-language-info-alist): Last arg to define-key-after can be skipped.
7
8 * international/quail.el (quail-completion-1): Simplify.
9 (quail-define-rules): Use slightly more compact code.
10 (quail-insert-decode-map): Propertize keys, compact columns.
11
3 * emacs-lisp/bytecomp.el (byte-compile-interactive-only-functions): 12 * emacs-lisp/bytecomp.el (byte-compile-interactive-only-functions):
4 Add goto-line. 13 Add goto-line.
5 14
diff --git a/lisp/international/quail.el b/lisp/international/quail.el
index f70b5c1cfc0..c8d1083fbeb 100644
--- a/lisp/international/quail.el
+++ b/lisp/international/quail.el
@@ -54,6 +54,7 @@
54;;; Code: 54;;; Code:
55 55
56(require 'help-mode) 56(require 'help-mode)
57(eval-when-compile (require 'cl))
57 58
58(defgroup quail nil 59(defgroup quail nil
59 "Quail: multilingual input method." 60 "Quail: multilingual input method."
@@ -1020,9 +1021,8 @@ the following annotation types are supported.
1020 (while l 1021 (while l
1021 (setq key (car (car l)) trans (car (cdr (car l))) l (cdr l)) 1022 (setq key (car (car l)) trans (car (cdr (car l))) l (cdr l))
1022 (quail-defrule-internal key trans map t decode-map props)) 1023 (quail-defrule-internal key trans map t decode-map props))
1023 `(if (not (quail-decode-map)) 1024 `(if (prog1 (quail-decode-map)
1024 (quail-install-map ',map) 1025 (quail-install-map ',map))
1025 (quail-install-map ',map)
1026 (quail-install-decode-map ',decode-map)))))) 1026 (quail-install-decode-map ',decode-map))))))
1027 1027
1028;;;###autoload 1028;;;###autoload
@@ -2188,7 +2188,7 @@ are shown (at most to the depth specified `quail-completion-max-depth')."
2188 (setq this-command 'quail-completion)) 2188 (setq this-command 'quail-completion))
2189 2189
2190(defun quail-completion-1 (key map indent) 2190(defun quail-completion-1 (key map indent)
2191"List all completions of KEY in MAP with indentation INDENT." 2191 "List all completions of KEY in MAP with indentation INDENT."
2192 (let ((len (length key))) 2192 (let ((len (length key)))
2193 (quail-indent-to indent) 2193 (quail-indent-to indent)
2194 (insert key ":") 2194 (insert key ":")
@@ -2199,20 +2199,12 @@ are shown (at most to the depth specified `quail-completion-max-depth')."
2199 (insert " -\n")) 2199 (insert " -\n"))
2200 (setq indent (+ indent 2)) 2200 (setq indent (+ indent 2))
2201 (if (and (cdr map) (< (/ (1- indent) 2) quail-completion-max-depth)) 2201 (if (and (cdr map) (< (/ (1- indent) 2) quail-completion-max-depth))
2202 (let ((l (cdr map)) 2202 (let ((l (cdr map)))
2203 (newkey (make-string (1+ len) 0))
2204 (i 0))
2205 (if (functionp l) 2203 (if (functionp l)
2206 (setq l (funcall l))) 2204 (setq l (funcall l)))
2207 ;; Set KEY in the first LEN characters of NEWKEY. 2205 (dolist (elt (reverse l)) ; L = ((CHAR . DEFN) ....) ;
2208 (while (< i len) 2206 (quail-completion-1 (concat key (string (car elt)))
2209 (aset newkey i (aref key i)) 2207 (cdr elt) indent))))))
2210 (setq i (1+ i)))
2211 (setq l (reverse l))
2212 (while l ; L = ((CHAR . DEFN) ....) ;
2213 (aset newkey len (car (car l)))
2214 (quail-completion-1 newkey (cdr (car l)) indent)
2215 (setq l (cdr l)))))))
2216 2208
2217(defun quail-completion-list-translations (map key indent) 2209(defun quail-completion-list-translations (map key indent)
2218 "List all possible translations of KEY in Quail MAP with indentation INDENT." 2210 "List all possible translations of KEY in Quail MAP with indentation INDENT."
@@ -2378,38 +2370,62 @@ should be made by `quail-build-decode-map' (which see)."
2378 (if (> width single-trans-width) 2370 (if (> width single-trans-width)
2379 (setq single-trans-width width))))) 2371 (setq single-trans-width width)))))
2380 (when single-list 2372 (when single-list
2381 ;; Since decode-map is sorted, we known the longest key is at the end. 2373 ;; Figure out how many columns can fit.
2382 (let* ((max-key-width (max 3 (length (caar (last single-list))))) 2374 (let* ((len (length single-list))
2375 ;; The longest key is at the end, by virtue of the above `sort'.
2376 (max-key-width (max 3 (length (caar (last single-list)))))
2377 ;; Starting point: worst case.
2383 (col-width (+ max-key-width 1 single-trans-width 1)) 2378 (col-width (+ max-key-width 1 single-trans-width 1))
2384 (cols (/ window-width col-width)) 2379 (cols (/ window-width col-width))
2385 (rows (/ (+ (length single-list) (1- cols)) cols)) ; Round up. 2380 rows)
2386 col pos row) 2381 ;; Now, let's see if we can pack in a few more columns since
2387 (insert "key") 2382 ;; the first columns can often be made narrower thanks to the
2388 (quail-indent-to (1+ max-key-width)) 2383 ;; length-sorting.
2389 (insert "char") 2384 (while (let ((newrows (/ (+ len cols) (1+ cols))) ;Round up.
2390 (quail-indent-to (1+ col-width)) 2385 (width 0))
2386 (dotimes (col (1+ cols))
2387 (let ((last-col-elt (or (nth (1- (* (1+ col) newrows))
2388 single-list)
2389 (car (last single-list)))))
2390 (incf width (+ (max 3 (length (car last-col-elt)))
2391 1 single-trans-width 1))))
2392 (< width window-width))
2393 (incf cols))
2394 (setq rows (/ (+ len cols -1) cols)) ;Round up.
2395 (let ((key-width (max 3 (length (car (nth (1- rows) single-list))))))
2396 (insert "key")
2397 (quail-indent-to (1+ key-width))
2398 (insert "char")
2399 (quail-indent-to (+ 1 key-width 1 single-trans-width 1)))
2391 (insert "[type a key sequence to insert the corresponding character]\n") 2400 (insert "[type a key sequence to insert the corresponding character]\n")
2392 (setq pos (point)) 2401 (let ((pos (point))
2393 (insert-char ?\n (+ rows 2)) 2402 (col 0))
2394 (goto-char pos) 2403 (insert-char ?\n (+ rows 2))
2395 (setq col (- col-width) row 0) 2404 (while single-list
2396 (dolist (elt single-list)
2397 (when (= (% row rows) 0)
2398 (goto-char pos) 2405 (goto-char pos)
2399 (setq col (+ col col-width)) 2406 (let* ((key-width (max 3 (length
2400 (move-to-column col) 2407 (car (or (nth (1- rows) single-list)
2401 (quail-indent-to col) 2408 (car (last single-list)))))))
2402 (insert-char ?- max-key-width) 2409 (col-width (+ key-width 1 single-trans-width 1)))
2403 (insert ? ) 2410 ;; Insert the header-line.
2404 (insert-char ?- single-trans-width) 2411 (move-to-column col)
2405 (forward-line 1)) 2412 (quail-indent-to col)
2406 (move-to-column col) 2413 (insert-char ?- key-width)
2407 (quail-indent-to col) 2414 (insert ?\s)
2408 (insert (car elt)) 2415 (insert-char ?- single-trans-width)
2409 (quail-indent-to (+ col max-key-width 1)) 2416 (forward-line 1)
2410 (insert (cdr elt)) 2417 ;; Insert the key-tran pairs.
2411 (forward-line 1) 2418 (dotimes (row rows)
2412 (setq row (1+ row))) 2419 (let ((elt (pop single-list)))
2420 (when elt
2421 (move-to-column col)
2422 (quail-indent-to col)
2423 (insert (propertize (car elt)
2424 'face 'font-lock-comment-face))
2425 (quail-indent-to (+ col key-width 1))
2426 (insert (cdr elt))
2427 (forward-line 1))))
2428 (setq col (+ col col-width)))))
2413 (goto-char (point-max)))) 2429 (goto-char (point-max))))
2414 2430
2415 (when multiple-list 2431 (when multiple-list
@@ -2421,7 +2437,8 @@ should be made by `quail-build-decode-map' (which see)."
2421 (insert-char ?- max-key-width) 2437 (insert-char ?- max-key-width)
2422 (insert " ------------\n") 2438 (insert " ------------\n")
2423 (dolist (elt multiple-list) 2439 (dolist (elt multiple-list)
2424 (insert (car elt)) 2440 (insert (propertize (car elt)
2441 'face 'font-lock-comment-face))
2425 (quail-indent-to max-key-width) 2442 (quail-indent-to max-key-width)
2426 (if (vectorp (cdr elt)) 2443 (if (vectorp (cdr elt))
2427 (mapc (function 2444 (mapc (function