variables - 用 Elisp(输入法)编写一个简单的切换函数
问题描述
所以,我尝试了以下
(defun toggle-input-chinese ()
(if (equal current-input-method 'chinese-py)
(set-input-method chinese-sisheng)
(set-input-method chinese-py)))
现在,基本上,我想写中文或拼音。我发现没有简单的方法在非标准输入之间使用切换。因此,我决定编写这个函数并绑定到一个键。
好的。我的问题是:它引发了错误(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
。Lisp 在调用函数之前评估函数的参数。它试图评估该变量,但该符号没有作为变量的值。
相反,您要做的是传递符号 chinese-py
or chinese-sisheng
,而不是将其值作为变量传递(它没有)。
尝试同时引用chinese-py
and 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)))
推荐阅读
- node.js - 如何避免用户看到来自其他用户套接字的数据?
- python - 使用 jax.random.normal 对具有特定均值和标准差的单变量高斯分布进行采样
- javascript - 如何将 RegEx 中的组合捕获组与 string.prototype.matchAll 结合使用?
- angular - 使用 Angular/Ionic HTTP 调用 Azure 函数时出错。使用标头获取
- node.js - 这些东西对节点js中的heroku有什么作用
- python - 使用不同的数据格式 DD-MMM-YY 运行 Mysql 查询
- python - 带有 aiohttp 的数据类 - 将无效值转换为 int、float 或 str
- python - Selenium 代码在 Python 中使用 Web 抓取进行特定迭代后停止
- spring - 如何将 spring-boot-web-application 转换为 spring 应用程序
- ios - Xamarin 如何存储日期选择器中的日期