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

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

[elpa] externals/pyim ed8d7557e0 2/2: 优化 pyim-delete-word 命令。


From: ELPA Syncer
Subject: [elpa] externals/pyim ed8d7557e0 2/2: 优化 pyim-delete-word 命令。
Date: Sat, 1 Jan 2022 01:57:49 -0500 (EST)

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

    优化 pyim-delete-word 命令。
    
            * pyim.el (pyim-delete-last-word): Use 
pyim-process-last-created-words.
            (pyim-delete-word): Use pyim-process-last-created-words.
    
            * pyim-process.el (pyim-process-last-created-word): rename from ...
            (pyim-process-last-created-words): to ...
            (pyim-process-input-ascii, pyim-process-create-word): use 
pyim-process-last-created-words.
---
 pyim-process.el | 10 +++++-----
 pyim.el         | 33 +++++++++++++++++++++------------
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/pyim-process.el b/pyim-process.el
index 78005085bc..770b50355e 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -86,8 +86,8 @@
 (defvar pyim-process-translating nil
   "记录是否在转换状态.")
 
-(defvar pyim-process-last-created-word nil
-  "记录最近一次创建的词条, 用于实现快捷删词功能: `pyim-delete-last-word' .")
+(defvar pyim-process-last-created-words nil
+  "记录最近创建的词条, 用于实现快捷删词功能: `pyim-delete-last-word' .")
 
 (defvar pyim-process-run-async-timer nil
   "异步处理 entered 时,使用的 timer.")
@@ -99,8 +99,7 @@
 
 (pyim-register-local-variables
  '(pyim-process-input-ascii
-   pyim-process-translating
-   pyim-process-last-created-word))
+   pyim-process-translating))
 
 (defun pyim-process-init-dcaches (&optional force)
   "PYIM 流程,词库相关的初始化工作。"
@@ -569,7 +568,8 @@ BUG:拼音无法有效地处理多音字。"
     ;; text property 去除,防止不必要的数据进入 cache.
     (setq word (substring-no-properties word))
     ;; 记录最近创建的词条,用于快速删词功能。
-    (setq pyim-process-last-created-word word)
+    (setq pyim-process-last-created-words
+          (cons word (remove word pyim-process-last-created-words)))
     (let* ((scheme-name (pyim-scheme-name))
            (code-prefix (pyim-scheme-get-option scheme-name :code-prefix))
            (codes (pyim-cstring-to-codes
diff --git a/pyim.el b/pyim.el
index 34017a19a1..da6da570f8 100644
--- a/pyim.el
+++ b/pyim.el
@@ -455,9 +455,9 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
 (defun pyim-delete-last-word ()
   "从个人词库中删除最新创建的词条。"
   (interactive)
-  (when pyim-process-last-created-word
-    (pyim-process-delete-word pyim-process-last-created-word)
-    (message "pyim: 从个人词库中删除词条 “%s” !" pyim-process-last-created-word)))
+  (when pyim-process-last-created-words
+    (pyim-process-delete-word (car pyim-process-last-created-words))
+    (message "pyim: 从个人词库中删除词条 “%s” !" (car pyim-process-last-created-words))))
 
 (defun pyim-delete-word-at-point (&optional number silent)
   "将光标前字符数为 NUMBER 的中文字符串从个人词库中删除
@@ -469,16 +469,25 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
         (message "词条: \"%s\" 已经从个人词库缓冲中删除。" string)))))
 
 (defun pyim-delete-word ()
-  "将高亮选择的词条从个人词库中删除。"
+  "从个人词库中删除词条。"
   (interactive)
-  (if mark-active
-      (let ((string (buffer-substring-no-properties
-                     (region-beginning) (region-end))))
-        (when (and (< (length string) 6)
-                   (> (length string) 0))
-          (pyim-process-delete-word string)
-          (message "将词条: %S 从 personal 缓冲中删除。" string)))
-    (message "请首先高亮选择需要删除的词条。")))
+  (cond
+   (mark-active
+    (let ((string (buffer-substring-no-properties
+                   (region-beginning) (region-end))))
+      (when (and (< (length string) 6)
+                 (> (length string) 0))
+        (pyim-process-delete-word string)
+        (message "将词条: %S 从 personal 缓冲中删除。" string)
+        (deactivate-mark))))
+   (t (let ((words (completing-read-multiple
+                    "请选择需要删除的词条(可多选): "
+                    pyim-process-last-created-words)))
+        (dolist (word words)
+          (pyim-process-delete-word word)
+          (setq pyim-process-last-created-words
+                (remove word pyim-process-last-created-words))
+          (message "将词条: %S 从 personal 缓冲中删除。" word))))))
 
 ;; ** 选词功能
 (defun pyim-select-word-simple ()



reply via email to

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