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

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

[elpa] externals/pyim 900a892 1/3: Add pyim-force-input-chinese-function


From: ELPA Syncer
Subject: [elpa] externals/pyim 900a892 1/3: Add pyim-force-input-chinese-functions.
Date: Sun, 14 Nov 2021 23:57:25 -0500 (EST)

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

    Add pyim-force-input-chinese-functions.
    
        * pyim-process.el (pyim-force-input-chinese-functions): New defcustom.
        (pyim-process-force-input-chinese-p): New function.
        (pyim-process-input-chinese-p, pyim-process-indicator-function): Use 
pyim-process-force-input-chinese-p instead.
    
        * pyim-probe.el (pyim-probe-dynamic-english)
        (pyim-probe-auto-english, pyim-probe-punctuation-line-beginning): do 
not test exwm.
        (exwm-xim-buffer-p): declare.
        (pyim-probe-exwm-environment): New function.
        (pyim-probe-xwidget-webkit-environment): New function.
    
        * pyim-page.el (pyim-probe-exwm-environment): declare.
        (pyim-page-refresh): Use pyim-probe-exwm-environment instead.
    
        * pyim-common.el (pyim-exwm-enable-p): removed.
    
        * README.org (pyim 高级功能): Add pyim-force-input-chinese-functions info.
---
 README.org      |  2 ++
 pyim-common.el  |  8 --------
 pyim-page.el    |  4 +++-
 pyim-probe.el   | 58 ++++++++++++++++++++++++++++++++++-----------------------
 pyim-process.el | 27 +++++++++++++++++++++++++--
 5 files changed, 65 insertions(+), 34 deletions(-)

diff --git a/README.org b/README.org
index 33b5239..4fd795a 100644
--- a/README.org
+++ b/README.org
@@ -302,6 +302,8 @@ pyim 当前内置三种指示器实现方式:
 ** pyim 高级功能
 1. 根据环境自动切换到英文输入模式,使用 pyim-english-input-switch-functions 配置。
 2. 根据环境自动切换到半角标点输入模式,使用 pyim-punctuation-half-width-functions 配置。
+3. 如果想在某种环境下强制输入中文,可以使用 pyim-force-input-chinese-functions
+   来配置,这个设置可以屏蔽掉 pyim-english-input-switch-functions 的设置。
 
 注意:上述两个功能使用不同的变量设置, *千万不要搞错* 。
 
diff --git a/pyim-common.el b/pyim-common.el
index dc7db58..fb3c692 100644
--- a/pyim-common.el
+++ b/pyim-common.el
@@ -132,14 +132,6 @@
     (when (char-after point-after)
       (char-to-string (char-after point-after)))))
 
-(defun pyim-exwm-enable-p ()
-  "测试当前是否是 exwm 环境。
-
-FIXME: This seem to be not a good approach, the
-better way is let exwm provide a test function.
-for example: https://github.com/ch11ng/exwm/pull/831";
-  (string-match-p " \\*temp\\*" (buffer-name)))
-
 (if (fboundp 'string-distance)
     (defalias 'pyim-string-distance 'string-distance)
   (defun pyim-string-distance (s1 s2)
diff --git a/pyim-page.el b/pyim-page.el
index ca436cc..1eeb2d4 100644
--- a/pyim-page.el
+++ b/pyim-page.el
@@ -132,6 +132,8 @@ non-nil,说明,补全已经用完了.
           whole
         (pyim-page-end t)))))
 
+(declare-function pyim-probe-exwm-environment "pyim-probe")
+
 (defun pyim-page-refresh (&optional hightlight-current)
   "刷新 page 页面的函数.
 
@@ -206,7 +208,7 @@ page 的概念,比如,上面的 “nihao” 的 *待选词列表* 就可以
         ;; 指定的方式来显示候选词。
         (let ((message-log-max nil))
           (cond
-           ((pyim-exwm-enable-p)
+           ((pyim-probe-exwm-environment)
             ;; when exwm-xim is used, page should be showed
             ;; in minibuffer.
             (message (pyim-page-style:exwm page-info)))
diff --git a/pyim-probe.el b/pyim-probe.el
index f8394f2..cd0da02 100644
--- a/pyim-probe.el
+++ b/pyim-probe.el
@@ -121,18 +121,17 @@
                 (cl-search non-digit-str-before-1 "0123456789"))
       (cl-incf offset)
       (setq non-digit-str-before-1 (pyim-char-before-to-string offset)))
-    (unless (pyim-exwm-enable-p)
-      (if (<= (point) (save-excursion (back-to-indentation)
-                                      (point)))
-          (not (or (pyim-string-match-p
-                    "\\cc"
-                    (save-excursion
-                      ;; 查找前一个非空格字符。
-                      (if (re-search-backward "[^[:space:]\n]" nil t)
-                          (char-to-string (char-after (point))))))
-                   (> (length (pyim-entered-get 'point-before)) 0)))
-        (not (or (pyim-string-match-p "\\cc" non-digit-str-before-1)
-                 (> (length (pyim-entered-get 'point-before)) 0)))))))
+    (if (<= (point) (save-excursion (back-to-indentation)
+                                    (point)))
+        (not (or (pyim-string-match-p
+                  "\\cc"
+                  (save-excursion
+                    ;; 查找前一个非空格字符。
+                    (if (re-search-backward "[^[:space:]\n]" nil t)
+                        (char-to-string (char-after (point))))))
+                 (> (length (pyim-entered-get 'point-before)) 0)))
+      (not (or (pyim-string-match-p "\\cc" non-digit-str-before-1)
+               (> (length (pyim-entered-get 'point-before)) 0))))))
 
 (defun pyim-probe-auto-english ()
   "激活这个 pyim 探针函数后,使用下面的规则自动切换中英文输入:
@@ -145,13 +144,12 @@
 这个函数用于:`pyim-english-input-switch-functions' 。"
   (let ((str-before-1 (pyim-char-before-to-string 0))
         (str-before-2 (pyim-char-before-to-string 1)))
-    (unless (pyim-exwm-enable-p)
-      (if (> (point) (save-excursion (back-to-indentation)
-                                     (point)))
-          (or (if (pyim-string-match-p " " str-before-1)
-                  (pyim-string-match-p "\\cc" str-before-2)
-                (and (not (pyim-string-match-p "\\cc" str-before-1))
-                     (= (length (pyim-entered-get 'point-before)) 0))))))))
+    (if (> (point) (save-excursion (back-to-indentation)
+                                   (point)))
+        (or (if (pyim-string-match-p " " str-before-1)
+                (pyim-string-match-p "\\cc" str-before-2)
+              (and (not (pyim-string-match-p "\\cc" str-before-1))
+                   (= (length (pyim-entered-get 'point-before)) 0)))))))
 
 (declare-function evil-normal-state-p "evil")
 (defun pyim-probe-evil-normal-mode ()
@@ -167,10 +165,9 @@
 
 用于:`pyim-punctuation-half-width-functions' 。"
   (let ((line-string (buffer-substring (point-at-bol) (point))))
-    (unless (pyim-exwm-enable-p)
-      (and (member (char-to-string char)
-                   (mapcar #'car pyim-punctuation-dict))
-           (string-match "^[ \t]*$" line-string)))))
+    (and (member (char-to-string char)
+                 (mapcar #'car pyim-punctuation-dict))
+         (string-match "^[ \t]*$" line-string))))
 
 (declare-function pyim-entered-get "pyim-entered" (&optional type))
 (declare-function org-inside-LaTeX-fragment-p "org")
@@ -191,6 +188,21 @@
     (or (not (eq (org-inside-LaTeX-fragment-p) nil))
         (not (eq (org-inside-latex-macro-p) nil)))))
 
+(defvar exwm-xim-buffer-p)
+(defun pyim-probe-exwm-environment ()
+  "测试当前是否是 exwm 输入法环境。
+
+这个探针主要用于: `pyim-force-input-chinese-functions'"
+  (bound-and-true-p exwm-xim-buffer-p))
+
+(defvar xwidget-webkit-isearch--read-string-buffer)
+(defun pyim-probe-xwidget-webkit-environment ()
+  "测试当前是否是 xwidget-webkit 运行环境。
+
+这个探针主要用于: `pyim-force-input-chinese-functions'."
+  (bound-and-true-p xwidget-webkit-isearch--read-string-buffer))
+
+
 ;; * Footer
 (provide 'pyim-probe)
 
diff --git a/pyim-process.el b/pyim-process.el
index c623101..52b8a2d 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -51,6 +51,16 @@
 运行结果为 t 时,pyim 开启英文输入功能。"
   :type 'symbol)
 
+(defcustom pyim-force-input-chinese-functions
+  (list 'pyim-probe-exwm-environment
+        'pyim-probe-xwidget-webkit-environment)
+  "让 pyim 强制输入中文.
+
+这个变量的取值为一个函数列表,这个函数列表中的任意一个函数的运行
+结果为 t 时,pyim 将强制输入中文功能,无视
+`pyim-english-input-switch-functions' 的设置."
+  :type 'symbol)
+
 (defcustom pyim-exhibit-delay-ms 0
   "输入或者删除拼音字符后等待多少毫秒后才显示可选词
 当用户快速输入连续的拼音时可提升用户体验.
@@ -173,12 +183,25 @@
                         ((listp func-or-list) func-or-list)
                         (t nil))))))
 
+(defun pyim-process-force-input-chinese-p ()
+  "判断是否强制输入中文,这个函数主要处理变量:
+`pyim-force-input-chinese-functions'."
+  (let ((func-or-list pyim-force-input-chinese-functions))
+    (or pyim-process-force-input-chinese
+        (cl-some (lambda (x)
+                   (if (functionp x)
+                       (funcall x)
+                     nil))
+                 (cond ((functionp func-or-list) (list func-or-list))
+                       ((listp func-or-list) func-or-list)
+                       (t nil))))))
+
 (defun pyim-process-input-chinese-p ()
   "确定 pyim 是否需要启动中文输入模式."
   (let* ((scheme-name (pyim-scheme-name))
          (first-chars (pyim-scheme-get-option scheme-name :first-chars))
          (rest-chars (pyim-scheme-get-option scheme-name :rest-chars)))
-    (and (or pyim-process-force-input-chinese
+    (and (or (pyim-process-force-input-chinese-p)
              (and (not pyim-process-input-ascii)
                   (not (pyim-process-auto-switch-english-input-p))))
          (if (not (string< "" (pyim-entered-get 'point-before)))
@@ -189,7 +212,7 @@
 
 (defun pyim-process-indicator-function ()
   "Indicator function."
-  (or pyim-process-force-input-chinese
+  (or (pyim-process-force-input-chinese-p)
       (and (not pyim-process-input-ascii)
            (not (pyim-process-auto-switch-english-input-p)))))
 



reply via email to

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