emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/pyim 792b6a9 1/2: Add pyim-add-unread-command-events an


From: ELPA Syncer
Subject: [elpa] externals/pyim 792b6a9 1/2: Add pyim-add-unread-command-events and use it.
Date: Mon, 31 May 2021 23:57:12 -0400 (EDT)

branch: externals/pyim
commit 792b6a9ee9c703653a14c3b4abada097b4b25ae6
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Add pyim-add-unread-command-events and use it.
    
        * pyim-common.el (pyim-add-unread-command-events): New function.
    
        * pyim.el (pyim-start-translation, pyim-convert-string-at-point): Use 
pyim-add-unread-command-events.
    
        * pyim-page.el (pyim-page-minibuffer-message): Use 
pyim-add-unread-command-events.
    
        * pyim-entered.el (pyim-entered-refresh-1): Use 
pyim-add-unread-command-events.
        (pyim-common): required.
    
    Port 
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=bd5c7404195e45f11946b4e0933a1f8b697d8b87
---
 pyim-common.el  | 23 +++++++++++++++++++++++
 pyim-entered.el | 13 ++++++-------
 pyim-page.el    |  5 ++---
 pyim.el         | 21 ++++++---------------
 4 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/pyim-common.el b/pyim-common.el
index 0ef39ba..0308b3c 100644
--- a/pyim-common.el
+++ b/pyim-common.el
@@ -163,6 +163,29 @@ for example: https://github.com/ch11ng/exwm/pull/831";
                            (funcall in (1- i) (1- j)))))))
       (funcall in l1 l2))))
 
+(if (fboundp 'quail-add-unread-command-events)
+    (defalias 'pyim-add-unread-command-events 'quail-add-unread-command-events)
+  (defun pyim-add-unread-command-events (key &optional reset)
+    "Add KEY to `unread-command-events', ensuring that it is not recorded.
+If KEY is a character, it is prepended to `unread-command-events' as
+a cons cell of the form (no-record . KEY).
+If KEY is a vector of events, the events in the vector are prepended
+to `unread-command-events', after converting each event to a cons cell
+of the form (no-record . EVENT).
+Quail puts keys back in `unread-command-events' to be handled again,
+and when it does this these keys have already been recorded in the
+recent keys and in the keyboard macro being defined, which means that
+recording them again creates duplicates.
+When RESET is non-nil, the events in `unread-command-events' are first
+discarded."
+    (if reset (setq unread-command-events nil))
+    (setq unread-command-events
+          (if (characterp key)
+              (cons (cons 'no-record key) unread-command-events)
+            (append (mapcan (lambda (e) (list (cons 'no-record e)))
+                            (append key nil))
+                    unread-command-events)))))
+
 ;; * Footer
 (provide 'pyim-common)
 
diff --git a/pyim-entered.el b/pyim-entered.el
index 4332152..03fc09d 100644
--- a/pyim-entered.el
+++ b/pyim-entered.el
@@ -28,6 +28,7 @@
 ;;; Code:
 ;; * 代码                                                           :code:
 (require 'cl-lib)
+(require 'pyim-common)
 
 (defgroup pyim-entered nil
   "Entered tools for pyim."
@@ -246,10 +247,9 @@ TYPE 取值为 point-after, 返回 entered buffer 中 point 之后的字符
         ;; autoselector 机制已经触发的时候,如果发现 entered buffer 中
         ;; point 后面还有未处理的输入,就将其转到下一轮处理,这种情况
         ;; 很少出现,一般是型码输入法,entered 编辑的时候有可能触发。
-        (setq unread-command-events
-              (append (listify-key-sequence (pyim-entered-get 'point-after))
-                      unread-command-events))
-        (push last-command-event unread-command-events)
+        (pyim-add-unread-command-events
+         (listify-key-sequence (pyim-entered-get 'point-after)))
+        (pyim-add-unread-command-events last-command-event)
         (pyim-terminate-translation))
        ;; 假设用户已经输入 "niha", 然后按了 "o" 键,那么,当前
        ;; entered 就是 "nihao". 如果 autoselector 函数返回一个 list:
@@ -266,9 +266,8 @@ TYPE 取值为 point-after, 返回 entered buffer 中 point 之后的字符
                     (list str)
                   pyim-candidates)))
           (pyim-outcome-handle 'candidate))
-        (setq unread-command-events
-              (append (listify-key-sequence (pyim-entered-get 'point-after))
-                      unread-command-events))
+        (pyim-add-unread-command-events
+         (listify-key-sequence (pyim-entered-get 'point-after)))
         (pyim-terminate-translation))
        (t (setq pyim-candidate-position 1)
           (pyim-preview-refresh)
diff --git a/pyim-page.el b/pyim-page.el
index 0fc3648..8d3793e 100644
--- a/pyim-page.el
+++ b/pyim-page.el
@@ -506,9 +506,8 @@ minibuffer 原来显示的信息和 pyim 选词框整合在一起显示
       (setq point-1 (point)))
     (sit-for 1000000)
     (delete-region (point) point-1)
-    (when quit-flag
-      (setq quit-flag nil
-            unread-command-events '(7)))))
+    (setq quit-flag nil)
+    (pyim-add-unread-command-events 7 t)))
 
 (defun pyim-page-hide ()
   "Hide pyim page."
diff --git a/pyim.el b/pyim.el
index ac1459a..b7dee79 100644
--- a/pyim.el
+++ b/pyim.el
@@ -236,26 +236,19 @@ Return the input string.
              ;; 插入 preview string, pyim *强制* 将其设置为 nil
              (input-method-use-echo-area nil)
              (modified-p (buffer-modified-p))
-             last-command-event last-command this-command inhibit-record)
+             last-command-event last-command this-command)
 
         (setq pyim-translating t)
         (pyim-entered-erase-buffer)
         (pyim-outcome-handle "")
 
         (when key
-          (setq unread-command-events
-                (cons key unread-command-events)
-                inhibit-record t))
+          (pyim-add-unread-command-events key))
 
         (while pyim-translating
           (set-buffer-modified-p modified-p)
-          (let* (;; We inhibit record_char only for the first key,
-                 ;; because it was already recorded before read_char
-                 ;; called quail-input-method.
-                 (inhibit--record-char inhibit-record)
-                 (keyseq (read-key-sequence nil nil nil t))
+          (let* ((keyseq (read-key-sequence nil nil nil t))
                  (cmd (lookup-key pyim-mode-map keyseq)))
-            (setq inhibit-record nil)
             ;; (message "key: %s, cmd:%s\nlcmd: %s, lcmdv: %s, tcmd: %s"
             ;;          key cmd last-command last-command-event this-command)
             (if (if key
@@ -273,8 +266,7 @@ Return the input string.
                            (beep))))
               ;; KEYSEQ is not defined in the translation keymap.
               ;; Let's return the event(s) to the caller.
-              (setq unread-command-events
-                    (string-to-list (this-single-command-raw-keys)))
+              (pyim-add-unread-command-events (this-single-command-raw-keys) t)
               ;; (message "unread-command-events: %s" unread-command-events)
               (pyim-terminate-translation))))
         ;; (message "return: %s" (pyim-outcome-get))
@@ -840,9 +832,8 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
           (delete-char (- 0 length)))
         (run-hooks 'pyim-convert-string-at-point-hook)
         (when (> length 0)
-          (setq unread-command-events
-                (append (listify-key-sequence code)
-                        unread-command-events))
+          (pyim-add-unread-command-events
+           (listify-key-sequence code))
           (setq pyim-force-input-chinese t)))
        ;; 当光标前的一个字符是标点符号时,半角/全角切换。
        ((pyim-string-match-p "[[:punct:]:-]" (pyim-char-before-to-string 0))



reply via email to

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