erbot-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Erbot-cvs] erbot erbim.el


From: Vivek Dasmohapatra
Subject: [Erbot-cvs] erbot erbim.el
Date: Tue, 22 Aug 2006 00:18:17 +0000

CVSROOT:        /sources/erbot
Module name:    erbot
Changes by:     Vivek Dasmohapatra <fledermaus> 06/08/22 00:18:17

Modified files:
        .              : erbim.el 

Log message:
        Added documentation.
        Modified behaviour when many input methods can produce a char - list
        candidate input methods instead.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/erbot/erbim.el?cvsroot=erbot&r1=1.1&r2=1.2

Patches:
Index: erbim.el
===================================================================
RCS file: /sources/erbot/erbot/erbim.el,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- erbim.el    21 Aug 2006 18:33:01 -0000      1.1
+++ erbim.el    22 Aug 2006 00:18:17 -0000      1.2
@@ -1,5 +1,5 @@
 ;;; erbim.el --- input method searching
-;; Time-stamp: <2006-08-21 12:14:53 fledermaus>
+;; Time-stamp: <2006-08-22 01:16:17 fledermaus>
 ;; Copyright (C) 2006 V. Dasmohapatra
 ;; Emacs Lisp Archive entry
 ;; Filename: erbim.el
@@ -13,19 +13,29 @@
 (require 'quail)
 (require 'iso-transl)
 
-(defvar erbim-keymaps-map nil)
+(defvar erbim-keymaps-map nil
+  "Storage for the inverted keymaps for the input methods we have searched.")
 
 (defun erbim-enc (thing) 
+  "Standard encoding for all strings (many chars don't work in an emacs
+running screen, so chars and unencoded strings may not be safe or work)."
   (encode-coding-string thing 'utf-8))
 
 (defun erbim-c2s (thing)
+  "map a character to the appropriate string. This is not a straightforward
+operation using char-to-string (for some reason)."
   (if (> 256 thing) (single-key-description thing) (char-to-string thing)))
 
 (defun erbim-map (map)
+  "Traverse the input method's MAP, invert it, and return that."
   (let ((char-map nil))
     (mapc (lambda (M) (erbim-map-internal M "")) (cdr map)) char-map))
 
 (defun erbim-interpret-target (target)
+  "Examine the TARGET of a given input method map entry and turn it
+into a list of (unencoded) strings.\n
+Destinations can be symbols (keyboard macros) vectors of strings or 
+vectors of characters, or a cons of the form (LIST . TARGET)."
   ;;(message "target %S" target)
   (if (vectorp target) 
       (mapcar (lambda (T) (if (integerp T) (erbim-c2s T) T)) target)
@@ -39,6 +49,7 @@
         (list (if (integerp target) (string target) target)) )) ))
 
 (defun erbim-map-internal (map &optional so-far)
+  "Does the actual work of `erbim-map'."  
   (let ((iseq-str
          (format (if (symbolp (car map)) "%s %S " "%s%c") (or so-far "")
                  (car map)))
@@ -65,68 +76,82 @@
         (mapcar
          (lambda (M) (erbim-map-internal M iseq-str)) (cddr map))) ) ))
 
+;; load iso-transl's inverted keymap
+(add-to-list 'erbim-keymaps-map 
+             (cons "iso-transl" (erbim-map iso-transl-ctl-x-8-map)))
+
 (defun erbim-package-list ()
+  "Return the list of input methods that erbim can understand.
+iso-transl is not exactly an input method, but it is a special case."
   (cons "iso-transl"
-        (mapcar 
-         (lambda (I) 
-           (if (eq (caddr I) 'quail-use-package) (car I))) 
input-method-alist)))
+        (mapcar (lambda (I) (if (eq (caddr I) 'quail-use-package) (car I))) 
+                input-method-alist) ))
 
 (defun erbim-keymap-map (im)
+  "Return the inside-out keymap for input method IM (IM is a string)."
   (or (cdr (assoc im erbim-keymaps-map))
       (let ( (map (erbim-map 
                    (nth 2 (assoc im quail-package-alist)))) )
         (setq erbim-keymaps-map (cons (cons im map) erbim-keymaps-map)) map) ))
 
 (defun where-is-char (c &optional im-list)
-  ;; assume we got a string: char functions are broken in fsbot
+  "Given a string C (usually, but not always, one character (but NOT 
+necessarily one byte)) in length, search the input methods in either IM-LIST 
+or `erbim-package-list' and return a help string describing the key sequences 
+\(per input method) that can be used to enter C."
+  ;; assume we got a string: char functions are broken in fsbot becuase of
+  ;; some screen/emacs/terminal black magic (which I do not understand)
+  ;; so we cannot use (aref string 0) or string-to-char reliably.
   (let ((char (erbim-enc c))
         (res   nil)
         (qsec  nil))
     (mapc (lambda (Q)
+            ;; exclude chinese-* methods (too big) and misc problematic ones:
             (when (and Q 
                        (not (string-match "^chinese-"    Q))
-                       (not (string-match "^devanagari-" Q))
-                       (not (member Q '("greek-ibycus4" 
-                                        "tibetan-wylie"))))
+                       (not (member Q '("tibetan-wylie" ;; too big?
+                                        ;; "greek-ibycus4" ;; ok actually
+                                        )) ))
+              ;; load the input method if it's not iso-transl (special case)
+              ;; and we haven't already done so:
+              (or (equal Q "iso-transl")
               (with-temp-buffer
                 (or (assoc Q quail-package-alist) 
-                    (equal Q "iso-transl")
-                    (activate-input-method Q))
+                        (activate-input-method     Q)) ))
                 (message "checking %s" Q)
+              ;; check to see if we have a quail package (iso-transl is
+              ;; not a quail package, don't check for it here):
                 (when (or (equal Q "iso-transl") (assoc Q quail-package-alist))
                   ;;(message "%s keymap - %d" Q (length (erbim-keymap-map Q)))
-                  ;;(message "%S vs %S" 
-                  ;;         char
-                  ;;         (car 
-                  ;;         (rassoc "^{TM}" 
-                  ;;                  (erbim-keymap-map Q)) ))
+                ;; extract the inverse keymap if there is one, and pull
+                ;; put the first entry for the char we are looking for:
                   (when (setq qsec (assoc char (erbim-keymap-map Q)))
                     ;;(message "found sequence %s" qsec)
-                  (setq res (cons (cons Q (cdr qsec)) res))) )) ))
+                  (setq res (cons (cons Q (cdr qsec)) res)) )) ))
           (or im-list (erbim-package-list)))
-    ;; feed the results to the user:
+    ;; feed the results to the user (if there are lots of input methods,
+    ;; just list the input methods instead):
+    (if (> (length res) 10)
+        (format "%s is in the following input methods:\n%S" 
+                char (mapcar 'car res))
     (mapconcat
      (lambda (R) 
        (if (equal (car R) "iso-transl")
           (mapconcat 'identity 
                      (cons "C-x 8" (split-string (cdr R) "")) " ")
-        (format "%s: %s" (car R) (cdr R)) )) res "\n") ))
+           (format "%s: %s" (car R) (cdr R)) )) res "\n")) ))
 
 (defun fsi-where-is-char (&optional key &rest im-list)
   (let ((imlist nil) 
        (key (if key (if (symbolp key) (symbol-name key) key) nil)))
     (if key (where-is-char key (mapcar 'symbol-name im-list)) 
-      "No character specified.") ))
+      "where-is-char <CHAR-OR-SEQUENCE> [ INPUT-METHOD INPUT-METHOD... ]") ))
 
-(defun fsi-erbim-test () "erbim loaded Ok")
-;; (where-is-char "Þ")
+(provide 'erbim)
 
+;; (where-is-char "Þ")
 ;; (assoc (erbim-enc "þ") (erbim-keymap-map "iso-transl"))
 
-(add-to-list 'erbim-keymaps-map 
-             (cons "iso-transl" (erbim-map iso-transl-ctl-x-8-map)))
-
-(provide 'erbim)
 ;; (setq erbim-keymaps-map nil)
 ;; (insert "\n" (pp (assoc "japanese" erbim-keymaps-map)))
 ;; (insert "\n" (pp (nth 2 (assoc "greek-babel" quail-package-alist))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]