Author: sasugaanija
Date: Mon Aug 27 07:49:05 2007
New Revision: 4894
Modified:
trunk/emacs/uim-key.el
trunk/emacs/uim-var.el
trunk/emacs/uim.el
Log:
* Fix this-command-key related bug.
* emacs/uim-var.el
- (uim-this-command-keys-original): New variable
* emacs/uim-key.el
- (uim-backup-this-command-keys): New function
Copy original function definition of this-command-keys to
uim-this-command-keys-original.
- (uim-this-command-keys-override): New function
Redefine this-command-keys so as to return uim-key-vector
instead of the typed keys when it's bound.
- (uim-process-keyvec):
- Remove temporariliy overriding of this-command-keys.
- Rename keyvector to uim-key-vector for overridden
this-command-keys.
- (uim-command-execute): Ditto
* emacs/uim.el
- (uim-init): Add a call of uim-this-command-keys-override.
Modified: trunk/emacs/uim-key.el
==============================================================================
--- trunk/emacs/uim-key.el (original)
+++ trunk/emacs/uim-key.el Mon Aug 27 07:49:05 2007
@@ -135,28 +135,36 @@
(undo-boundary)
)
+(defun uim-backup-this-command-keys ()
+ (when (not uim-this-command-keys-original)
+ ;;(uim-debug "this-command-keys backup!")
+ (setq uim-this-command-keys-original
+ (symbol-function 'this-command-keys))))
-(defun uim-command-execute (keyvec)
- (uim-debug (format "uim-command-execute: %s" keyvec))
- (let (this-command-keys-original
- (mode uim-mode))
- (fset 'this-command-keys-original
- (symbol-function 'this-command-keys))
+(defun uim-this-command-keys-override ()
+ (if (not uim-this-command-keys-original)
+ (progn
+ (uim-backup-this-command-keys)
+ (defun this-command-keys ()
+ (if (and (boundp 'uim-key-vector)
+ uim-key-vector)
+ uim-key-vector
+ (funcall uim-this-command-keys-original))))))
+
+
+(defun uim-command-execute (uim-key-vector)
+ (uim-debug (format "uim-command-execute: %s" uim-key-vector))
+ (let ((mode uim-mode))
(unwind-protect
(progn
- (fset 'this-command-keys
- '(lambda ()
- keyvec))
(setq uim-mode nil)
- (setq this-command keyvec)
+ (setq this-command uim-key-vector)
(run-hooks 'pre-command-hook)
(command-execute this-command)
)
(progn
- (fset 'this-command-keys
- (symbol-function 'this-command-keys-original))
(setq uim-mode mode)))))
@@ -186,8 +194,8 @@
;;
;; Process the key vector returned from Uim.
;;
-(defun uim-process-keyvec (keyvec &optional count)
- (let ((bind (uim-getbind keyvec))
+(defun uim-process-keyvec (uim-key-vector &optional count)
+ (let ((bind (uim-getbind uim-key-vector))
keyvectmp)
(uim-debug (format "uim-process-keyvec"))
@@ -197,25 +205,25 @@
(unwind-protect
(cond ((and (or (keymapp bind) (not bind))
- (setq keyvectmp (uim-remove-shift keyvec))
- (setq keyvec keyvectmp))
+ (setq keyvectmp (uim-remove-shift uim-key-vector))
+ (setq uim-key-vector keyvectmp))
(if uim-xemacs
(progn
- (setq uim-retry-keys keyvec)
+ (setq uim-retry-keys uim-key-vector)
(if count (setq prefix-arg count))
(setq unread-command-events
- (cons (aref keyvec 0) unread-command-events))))
+ (cons (aref uim-key-vector 0)
unread-command-events))))
(if uim-emacs
(progn
- (uim-debug (format "retry key is %s / count is %s" keyvec
+ (uim-debug (format "retry key is %s / count is %s"
uim-key-vector
count))
- (setq uim-retry-keys keyvec)
+ (setq uim-retry-keys uim-key-vector)
(if count (setq prefix-arg count))
;; dummy data
(setq unread-command-events
- (nconc (listify-key-sequence keyvec)
+ (nconc (listify-key-sequence uim-key-vector)
unread-command-events)
)
))
@@ -223,73 +231,51 @@
(count
(setq prefix-arg count)
(uim-command-execute
- (uim-getbind keyvec))
- ;;(uim-getbind (uim-last-onestroke-key keyvec)))
+ (uim-getbind uim-key-vector))
+ ;;(uim-getbind (uim-last-onestroke-key uim-key-vector)))
)
((commandp bind)
- (let (this-command-keys-original)
- (fset 'this-command-keys-original
- (symbol-function 'this-command-keys))
+ (if (eq bind 'self-insert-command)
+ (progn
+ (setq this-command bind)
+ (setq last-command-char (aref uim-key-vector 0))
+ (call-interactively bind)
+ (uim-concat-undo))
+ (setq this-command bind)
+ (uim-debug (format "this-command is %s" this-command))
+ (setq last-command-char (aref uim-key-vector 0))
- (unwind-protect
+ (if uim-xemacs
(progn
- (fset 'this-command-keys
- '(lambda ()
- keyvec))
-
- (if (eq bind 'self-insert-command)
- (progn
- (setq this-command bind)
- (setq last-command-char (aref keyvec 0))
- (call-interactively bind)
- (uim-concat-undo))
- (setq this-command bind)
- (uim-debug (format "this-command is %s" this-command))
- (setq last-command-char (aref keyvec 0))
-
- (if uim-xemacs
- (progn
- (setq last-input-event uim-original-input-event)
- (handle-pre-motion-command)))
+ (setq last-input-event uim-original-input-event)
+ (handle-pre-motion-command)))
- (run-hooks 'pre-command-hook)
- (command-execute this-command)
+ (run-hooks 'pre-command-hook)
+ (command-execute this-command)
- (if uim-xemacs
- (handle-post-motion-command))
+ (if uim-xemacs
+ (handle-post-motion-command))
- (uim-flush-concat-undo)
- )
- )
- (fset 'this-command-keys
- (symbol-function 'this-command-keys-original))
- )
+ (uim-flush-concat-undo)
)
)
+
((or (and uim-emacs
- (= help-char (aref (uim-last-onestroke-key keyvec) 0)))
+ (= help-char (aref (uim-last-onestroke-key
uim-key-vector) 0)))
(and uim-xemacs
(equal (uim-xemacs-make-event
(uim-convert-char-to-symbolvector
(key-description help-char)))
- (aref (uim-last-onestroke-key keyvec) 0))))
+ (aref (uim-last-onestroke-key uim-key-vector)
0))))
(uim-debug "help-char")
- (let (this-command-keys-original
- (mode uim-mode))
- (fset 'this-command-keys-original
- (symbol-function 'this-command-keys))
+ (let ((mode uim-mode))
(unwind-protect
(progn
- (fset 'this-command-keys
- '(lambda ()
- keyvec))
(setq uim-mode nil)
(funcall prefix-help-command)
)
(progn
- (fset 'this-command-keys
- (symbol-function 'this-command-keys-original))
(setq uim-mode mode))))
)
(t
@@ -298,7 +284,7 @@
(error 'undefined-keystroke-sequence
(uim-xemacs-make-event
(uim-convert-char-to-symbolvector
- (key-description keyvec))))
+ (key-description uim-key-vector))))
(undefined))
)
)
Modified: trunk/emacs/uim-var.el
==============================================================================
--- trunk/emacs/uim-var.el (original)
+++ trunk/emacs/uim-var.el Mon Aug 27 07:49:05 2007
@@ -294,6 +294,7 @@
(defvar uim-show-im-name t
"If the value is non-nil, IM name is displayed on mode-line.")
+(defvar uim-this-command-keys-original nil)
;;; Buffer Local Variables
Modified: trunk/emacs/uim.el
==============================================================================
--- trunk/emacs/uim.el (original)
+++ trunk/emacs/uim.el Mon Aug 27 07:49:05 2007
@@ -1365,6 +1365,9 @@
;; initialize keymap
(uim-init-keymap)
+ ;; wrap some functions
+ (uim-this-command-keys-override)
+
;; add hook to detect status change of buffer
(add-hook 'post-command-hook 'uim-post-command)