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

keyboard macro 输入字符数翻倍 #247

Open
whatacold opened this Issue Feb 1, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@whatacold
Copy link
Contributor

whatacold commented Feb 1, 2019

这个问题困扰已久,今天终于能够复现了。比如我有一个 org 文件如下,第二个顶级节点是期望的结果:

* original text
** hi
你好

** bar
foo

* expected text
** hi
*** front
hi
*** back
你好

** bar
*** front
bar
*** back
foo

我希望通过 keyboard macro 来完成编辑,但是在启用 pyim 的情况下会有点问题。
使用以下命令启动一个干净的实例:
emacs -Q -L workspace/elisp/pyim -L ~/.emacs.d/elpa/popup-0.5.3 -L ~/.emacs.d/elpa/async-1.9.3 -L ~/.emacs.d/elpa/pyim-basedict-0.3.1 -l ~/test/init-pyim.el
pyim 使用 git v1.8 的代码(以免受最近的 rime 特性影响),init-pyim.el 内容:

(require 'pyim)
(require 'pyim-basedict) ; 拼音词库设置,五笔用户 *不需要* 此行设置
(pyim-basedict-enable)   ; 拼音词库,五笔用户 *不需要* 此行设置
(setq default-input-method "pyim")

;; 我使用全拼
(setq pyim-default-scheme 'quanpin)

;; 设置 pyim 探针设置,这是 pyim 高级功能设置,可以实现 *无痛* 中英文切换 :-)
;; 我自己使用的中英文动态切换规则是:
;; 1. 光标只有在注释里面时,才可以输入中文。
;; 2. 光标前是汉字字符时,才能输入中文。
;; 3. 使用 M-j 快捷键,强制将光标前的拼音字符串转换为中文。
(setq-default pyim-english-input-switch-functions
              '(pyim-probe-dynamic-english
                pyim-probe-isearch-mode
                pyim-probe-program-mode
                pyim-probe-org-structure-template))

(setq-default pyim-punctuation-half-width-functions
              '(pyim-probe-punctuation-line-beginning
                pyim-probe-punctuation-after-punctuation))

;; 开启拼音搜索功能
(pyim-isearch-mode 1)

;; 使用 pupup-el 来绘制选词框, 如果用 emacs26, 建议设置
;; 为 'posframe, 速度很快并且菜单不会变形,不过需要用户
;; 手动安装 posframe 包。
(setq pyim-page-tooltip 'popup)

;; 选词框显示5个候选词
(setq pyim-page-length 5)

Emacs version: GNU Emacs 26.1 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.22.30) of 2018-06-26

未启用 pyim 前, kmacro 可以正常工作

录制的 kmacro 使用 M-x kmacro-edit-macro 内容如下,可以正常用 F4 应用:

;; Keyboard Macro Editor.  Press C-c C-c to finish; press C-x k RET to cancel.
;; Original keys: M-x i s e a r c h - f o r w a r d RET 2** SPC RET C-k C-/ C-e RET 3** SPC f r o n t RET C-y RET 3** SPC b a c k

Command: last-kbd-macro
Key: none

Macro:

M-x			;; execute-extended-command
i			;; self-insert-command
s			;; self-insert-command
e			;; self-insert-command
a			;; self-insert-command
r			;; self-insert-command
c			;; self-insert-command
h			;; self-insert-command
-			;; self-insert-command
f			;; self-insert-command
o			;; self-insert-command
r			;; self-insert-command
w			;; self-insert-command
a			;; self-insert-command
r			;; self-insert-command
d			;; self-insert-command
RET			;; org-return
2**			;; self-insert-command
SPC			;; self-insert-command
RET			;; org-return
C-k			;; org-kill-line
C-/			;; undo
C-e			;; org-end-of-line
RET			;; org-return
3**			;; self-insert-command
SPC			;; self-insert-command
f			;; self-insert-command
r			;; self-insert-command
o			;; self-insert-command
n			;; self-insert-command
t			;; self-insert-command
RET			;; org-return
C-y			;; org-yank
RET			;; org-return
3**			;; self-insert-command
SPC			;; self-insert-command
b			;; self-insert-command
a			;; self-insert-command
c			;; self-insert-command
k			;; self-insert-command

M-x pyim-convert-code-at-point 后,同样的录制过程,无法应用成功

可以看到,录制的宏中,每个字符都重复一次,会得到比如 ffrroonntt

;; Keyboard Macro Editor.  Press C-c C-c to finish; press C-x k RET to cancel.
;; Original keys: M-x i s e a r c h - f o r w a r d RET * <with-input-method> 2** <with-input-method> * SPC <with-input-method> SPC RET C-k C-/ C-e RET 6** 2*SPC 2*f 2*r 2*o 2*n 2*t RET C-y RET 6** 2*SPC 2*b 2*a 2*c 2*k

Command: last-kbd-macro
Key: none

Macro:

M-x			;; execute-extended-command
i			;; self-insert-command
s			;; self-insert-command
e			;; self-insert-command
a			;; self-insert-command
r			;; self-insert-command
c			;; self-insert-command
h			;; self-insert-command
-			;; self-insert-command
f			;; self-insert-command
o			;; self-insert-command
r			;; self-insert-command
w			;; self-insert-command
a			;; self-insert-command
r			;; self-insert-command
d			;; self-insert-command
RET			;; org-return
*			;; self-insert-command
<with-input-method>
2**			;; self-insert-command
<with-input-method>
*			;; self-insert-command
SPC			;; self-insert-command
<with-input-method>
SPC			;; self-insert-command
RET			;; org-return
C-k			;; org-kill-line
C-/			;; undo
C-e			;; org-end-of-line
RET			;; org-return
6**			;; self-insert-command
2*SPC			;; self-insert-command
2*f			;; self-insert-command
2*r			;; self-insert-command
2*o			;; self-insert-command
2*n			;; self-insert-command
2*t			;; self-insert-command
RET			;; org-return
C-y			;; org-yank
RET			;; org-return
6**			;; self-insert-command
2*SPC			;; self-insert-command
2*b			;; self-insert-command
2*a			;; self-insert-command
2*c			;; self-insert-command
2*k			;; self-insert-command

并且按 F4 之后,会报错:
undefined: Keyboard macro terminated by a command ringing the bell


有空的话帮忙看下如何解决,谢谢。

祝春节快乐 :)

@tumashu

This comment has been minimized.

Copy link
Owner

tumashu commented Feb 3, 2019

我测试了一下,确实有这种现象, 不过我又测试了一下 emacs 自带的 quail py 输入法,好像也由于类似的情况,也许这不是bug,可能是因为输入法内部对输入字符复杂的操作被 kmacro 傻傻的记录下来了,所以出现这种情况, 建议去 emacs-devel 问问大牛, 因为 kmacro 的核心是 c 编写的代码,我这边看不懂。

@whatacold

This comment has been minimized.

Copy link
Contributor Author

whatacold commented Feb 4, 2019

ok ,可以通过 M-x toggle-input-method 切换输入法来临时规避。

@whatacold

This comment has been minimized.

Copy link
Contributor Author

whatacold commented Feb 11, 2019

通过邮件列表, Eli 告知已有一个从 Emacs 25 开始引入的 bug 32108 并且已经在 master 修复了,见 emacs-mirror/emacs@03e3440

pyim 应该也可以利用内部变量 inhibit--record-char ,但我还没有编译过 master ,没法测试。

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