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, 19 Jun 2012 13:05:52 +0000

CVSROOT:        /sources/erbot
Module name:    erbot
Changes by:     Vivek Dasmohapatra <fledermaus> 12/06/19 13:05:51

Modified files:
        .              : erbim.el 

Log message:
        XCompose key sequence lookup

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

Patches:
Index: erbim.el
===================================================================
RCS file: /sources/erbot/erbot/erbim.el,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- erbim.el    11 Apr 2007 11:59:27 -0000      1.7
+++ erbim.el    19 Jun 2012 13:05:49 -0000      1.8
@@ -142,6 +142,86 @@
        (key (if key (if (symbolp key) (symbol-name key) key) nil)))
     (if key (where-is-char key (mapcar 'symbol-name im-list)) 
       "where-is-char <CHAR-OR-SEQUENCE> [ INPUT-METHOD INPUT-METHOD... ]") ))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; look for X Compose mappings
+(defun where-is-composed-char-file (locale)
+  (string-match "\\([a-z]\\{2\\}\\)\\(_[a-z]\\{2\\}\\)?\\(\\.\\S+\\)?" locale)
+  (let (pattern file)
+    (setq pattern (concat (match-string 1 locale)
+                          (or (match-string 2 locale) "_[A-Z]\\{2\\}")
+                          (or (match-string 3 locale) "\\.UTF-8"))
+          pattern (concat "^\\([a-z]\\S-+/Compose\\):?\\s-+" pattern))
+    (with-current-buffer
+        (find-file-noselect "/usr/share/X11/locale/compose.dir")
+      (goto-char (point-min))
+      (while (and (not file) (re-search-forward pattern nil t))
+        (setq file (match-string 1)) ))
+    (if file (concat "/usr/share/X11/locale/" file)) ))
+
+(defun where-is-composed-char (c &optional locale)
+  (or locale (setq locale "en"))
+  (let ((compose-file (where-is-composed-char-file locale)) 
+        compositions pattern cfs)
+    (if (not compose-file)
+        (error "No compositions found for %s" locale)
+      (setq pattern
+            (cond 
+             ((characterp c)
+              (setq c   (regexp-quote (format "%c" c)) 
+                    cfs nil)
+              (format "\\(%s\\)\"\\s-+\\(.*?\\)\\s-+# \\(.*\\)" c))
+             ((stringp c)
+              (setq c   (regexp-quote c)
+                    cfs t)
+              (format "\\(.\\)\"\\s-+\\(.*?\\)\\s-+# \\(.*%s.*\\)" c))))
+      (setq pattern (concat "^\\(<.*>\\)\\s-+:\\s-+\"" pattern))
+      (with-temp-buffer 
+        (insert-file-contents compose-file)
+        (goto-char (point-min))
+        (let ((case-fold-search cfs) seq char xsym name)
+          (while (re-search-forward pattern nil t)
+            (setq seq  (match-string 1)
+                  char (match-string 2)
+                  xsym (match-string 3)
+                  name (match-string 4))
+            (setq compositions
+                  (cons (list char seq xsym name) compositions)) )) ))
+    compositions))
+
+(defun fsi-where-is-composed-char (&optional key locale)
+  (let ((key (if key (if (symbolp key) (aref (symbol-name key) 0) key) nil))
+        results text)
+    (if (not key)
+        (setq text "where-is-composed-char <CHAR-OR-NAME> [ LOCALE ]")
+      (mapc
+       (lambda (x &optional cell char seq)
+         (setq char (cons (car x) (nth 3 x))
+               cell (assoc char results))
+         (when (not cell)
+           (setq cell    (cons char nil)
+                 results (cons cell results)))
+         (setq seq (cadr x)
+               seq (replace-regexp-in-string
+                    "<U\\(?:10+?\\)?\\([A-F0-9]\\{3,\\}\\)>"
+                    (lambda (y) 
+                      (format "%c"
+                              (string-to-number (match-string 1 y) 16))) seq))
+         (setcdr cell (cons seq (cdr cell)) ))
+       (where-is-composed-char key locale))
+      (if (> (length results) 10)
+         (format "Too many matches (%d) for pattern %S" (length results) key)
+       (if (> (length results) 2)
+           (concat "Possible matches:\n"
+                   (mapconcat 
+                    (lambda (x)
+                      (format "%s (%s)" (caar x) (cdar x))) results "  \n"))
+         (mapconcat
+          (lambda (x)
+            (concat (format "%s (%s):\n    " (caar x) (cdar x))
+                    (mapconcat 'identity (cdr x) "\n    ")))
+          results "\n")))) ))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; load iso-transl's inverted keymap
 (add-to-list 'erbim-keymaps-map 



reply via email to

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