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

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

[elpa] externals/pyim 14e7f4548e: pyim-export-words-and-counts: Add igno


From: ELPA Syncer
Subject: [elpa] externals/pyim 14e7f4548e: pyim-export-words-and-counts: Add ignore-counts argument.
Date: Thu, 30 Dec 2021 05:57:51 -0500 (EST)

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

    pyim-export-words-and-counts: Add ignore-counts argument.
    
            * pyim-dcache.el (pyim-dcache-export-words-and-counts): Add 
ignore-count argument.
    
            * pyim-dhashcache.el (pyim-dhashcache-export-words-and-counts): Add 
ignore-count argument.
---
 pyim-dcache.el      |  4 ++--
 pyim-dhashcache.el  | 12 +++++++++---
 tests/pyim-tests.el |  8 ++++++++
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/pyim-dcache.el b/pyim-dcache.el
index 5a0e8ca4bc..6c8f537714 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -193,14 +193,14 @@ AUTO-BACKUP-THRESHOLD 倍, 那么原值将自动备份到 FILE 对应的备份
   t)
 
 ;; ** Dcache 导出功能
-(defun pyim-dcache-export-words-and-counts (file &optional confirm)
+(defun pyim-dcache-export-words-and-counts (file &optional confirm 
ignore-counts)
   "将个人词条以及词条对应的词频信息导出到文件 FILE.
 
 如果 FILE 为 nil, 提示用户指定导出文件位置, 如果 CONFIRM 为
 non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式"
   (interactive "F将词条和词频信息导出到文件: ")
   (pyim-dcache-init-variables)
-  (pyim-dcache-call-api 'export-words-and-counts file confirm)
+  (pyim-dcache-call-api 'export-words-and-counts file confirm ignore-counts)
   (message "PYIM: 词条和词频信息导出完成。"))
 
 (defun pyim-dcache-export-personal-words (file &optional confirm)
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index fff4c0c019..d63370ead8 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -481,12 +481,15 @@ code 对应的中文词条了。
   "导出个人词库到 FILE."
   (pyim-dhashcache-export pyim-dhashcache-icode2word file confirm))
 
-(defun pyim-dhashcache-export-words-and-counts (file &optional confirm)
+(defun pyim-dhashcache-export-words-and-counts (file &optional confirm 
ignore-counts)
   (with-temp-buffer
     (insert ";;; -*- coding: utf-8-unix -*-\n")
     (maphash
      (lambda (key value)
-       (insert (format "%s %s\n" key value)))
+       (insert
+        (if ignore-counts
+            (format "%s\n" key)
+          (format "%s %s\n" key value))))
      pyim-dhashcache-iword2count)
     ;; 在默认情况下,用户选择过的词生成的缓存中存在的词条,
     ;; `pyim-dhashcache-iword2count' 中也一定存在,但如果用户
@@ -496,7 +499,10 @@ code 对应的中文词条了。
      (lambda (_ words)
        (dolist (word words)
          (unless (gethash word pyim-dhashcache-iword2count)
-           (insert (format "%s %s\n" word 0)))))
+           (insert
+            (if ignore-counts
+                (format "%s\n" word)
+              (format "%s %s\n" word 0))))))
      pyim-dhashcache-icode2word)
     (pyim-dcache-write-file file confirm)))
 
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 57c0ba8597..5eb843963b 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -676,6 +676,14 @@
                      ";;; -*- coding: utf-8-unix -*-
 你好 10
 尼耗 1
+")))
+    (pyim-dcache-export-words-and-counts file nil t)
+    (with-temp-buffer
+      (insert-file-contents file)
+      (should (equal (buffer-string)
+                     ";;; -*- coding: utf-8-unix -*-
+你好
+尼耗
 ")))
     (pyim-dcache-export-personal-words file)
     (with-temp-buffer



reply via email to

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