Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

收集中英文自动切换探测函数 #21

Closed
tumashu opened this issue Jan 23, 2015 · 13 comments
Closed

收集中英文自动切换探测函数 #21

tumashu opened this issue Jan 23, 2015 · 13 comments

Comments

@tumashu
Copy link
Owner

tumashu commented Jan 23, 2015

为了解决 #15 提出的问题,我添加了变量 pyim-english-input-switch-function ,用于探测
当前编辑环境,自动开启或者关闭英文输入模式:

比如:当开启 org-mode speed commands 时,下面这个探测函数可以自动切换中英文输入。

(defun pyim-org-speed-commands-active-p ()
  (and (string= major-mode "org-mode")
       (bolp) (looking-at org-heading-regexp)
       org-use-speed-commands))

(setq pyim-english-input-switch-function
      'pyim-org-speed-commands-active-p)

大家可以在下面贴出适用于其他编辑环境的探测程序: 比如:evil, isearch,等等。。。。

@et2010
Copy link
Contributor

et2010 commented Apr 26, 2015

我仿照上面这个函数写了一个关于helm的switch函数,只要helm buffer打开并激活,就切换为英文输入:

(defun pyim-helm-buffer-active-p ()
  (string-prefix-p "helm" (buffer-name (window-buffer (active-minibuffer-window)))))

(setq pyim-english-input-switch-function
      'pyim-helm-buffer-active-p)

@et2010
Copy link
Contributor

et2010 commented Oct 6, 2015

不知道为什么,我写的用于helm的这个switch函数不能用了,不知道是helm的原因还是chinese-pyim的原因?

@tumashu
Copy link
Owner Author

tumashu commented Oct 6, 2015

pyim这个地方几乎没有变过,是不是helm那更新了?

@tumashu
Copy link
Owner Author

tumashu commented Jan 6, 2016

chinese-pyim 添加了一个新组件: chinese-pyim-probe,专门用于收集探针函数。。。

@hitswint
Copy link
Contributor

个人很看好这个输入法,遇到一点问题就是在org或者tex中写中文时,换行后就自动转换回英文,有点不爽。仿照pyim-probe-dynamic-english写了一个函数,当前如果在行首或者indentation的位置,查找之前最近一个非空白字符,确定当前输入方式。
(defun swint-pyim-probe-dynamic-english () "Changed the behaviour of chinese-pyim at beginning of line." (if (or (= (- (point) (point-at-bol)) (current-indentation)) (= (point) (point-at-bol))) (not (or (pyim-string-match-p "\\cc" (save-excursion (if (re-search-backward "[^[:space:]]" nil t) (char-to-string (char-after (point)))))) (> (length pyim-current-key) 0))) (pyim-probe-dynamic-english)))
泪奔,居然不知道怎么在评论中输入代码。。

@tumashu
Copy link
Owner Author

tumashu commented Mar 16, 2016

你说的这个应该是 pyim-probe-dynamic-english 默认的行为,这个probe会识别光标前的一个字符,只有中文字符时,才开启输入法,至于行首关闭输入法,这是为了方便输入 “*” “#+BEGIN” 等控制符的,自定义 probe就是 chinese-pyim 配置的一种方式,你这个功能用的很好

@tumashu
Copy link
Owner Author

tumashu commented Mar 16, 2016

用两个 ”```“ 围起来就可以了

(defun swint-pyim-probe-dynamic-english ()
  "Changed the behaviour of chinese-pyim at beginning of line."
  (if (or (= (- (point) (point-at-bol))
             (current-indentation))
          (= (point) (point-at-bol)))
      (not (or (pyim-string-match-p
                "\\cc"
                (save-excursion
                  (if (re-search-backward "[^[:space:]]" nil t)
                      (char-to-string (char-after (point))))))
               (> (length pyim-current-key) 0)))
    (pyim-probe-dynamic-english)))

@tumashu
Copy link
Owner Author

tumashu commented Mar 18, 2016

@hitswint 如果有兴趣,你可以直接 hack pyim-probe-dynamic-english 函数,然后给我发一个pull request

@hitswint
Copy link
Contributor

已经发了,第一次弄,不知道弄得对不对。

@tumashu
Copy link
Owner Author

tumashu commented Mar 20, 2016

Thanks!

@tumashu
Copy link
Owner Author

tumashu commented Jun 19, 2016

这个帖子人气太差,关了

@chuxubank
Copy link

chuxubank commented Nov 1, 2019

org-mode 中的 latex fragment 和 latex 宏指令中自动切换到英文输入.
用于 pyim-english-input-switch-functions

  (defun pyim-probe-org-latex-mode ()
    (when (eq major-mode 'org-mode)
      (or
       (not (eq (org-inside-LaTeX-fragment-p) nil))
       (not (eq (org-inside-latex-macro-p) nil)))))

@tumashu
Copy link
Owner Author

tumashu commented Nov 2, 2019

@chuxubank 已添加,谢啦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants