[英]Writing a simple toggle function with Elisp (input-method)
所以,我尝试了以下
(defun toggle-input-chinese ()
(if (equal current-input-method 'chinese-py)
(set-input-method chinese-sisheng)
(set-input-method chinese-py)))
现在,基本上,我想写中文或拼音。 我发现没有简单的方法在非标准输入之间使用切换。 因此,我决定写这个 function 并绑定到一个键。
好的。 我的问题是:它引发了错误(void-variable chinese-py)
。 我不知道如何将当前方法与列出的方法等同起来。 我该怎么做?
- 编辑
这个版本是功能性的。 可以将其他输入的列表放在条件中,您将在语言环中切换。 最后,将其绑定到某个键。
这是一种比这里想象的更简单的方法: 是否可以在 Emacs 中交替使用两种输入法?
(defun toggle-input-chinese ()
(interactive)
(if (equal (car input-method-history) "chinese-py")
(set-input-method 'chinese-py)
(set-input-method 'chinese-sisheng)))
您将chinese-py
或chinese-sisheng
作为变量传递给 function set-input-method
。 在调用 function 之前,Lisp 将 arguments 评估为 function。 它试图评估该变量,但该符号没有作为变量的值。
您想要做的是传递符号chinese-py
或chinese-sisheng
,而不是将其值作为变量(它没有)。
尝试同时引用chinese-py
和chinese-sisheng
:
(defun toggle-input-chinese ()
(interactive) ; If you want to use it as a command
(if (equal (car input-method-history) "chinese-py")
(set-input-method 'chinese-sisheng)
(set-input-method 'chinese-py)))
这是一样的:
(defun toggle-input-chinese ()
(interactive) ; If you want to use it as a command
(set-input-method (if (equal (car input-method-history) "chinese-py")
'chinese-sisheng
'chinese-py)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.