【问题标题】:Writing a simple toggle function with Elisp (input-method)用 Elisp(输入法)编写一个简单的切换函数
【发布时间】:2021-03-17 13:49:27
【问题描述】:

所以,我尝试了以下方法

(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)。我不知道如何将当前方法与列出的方法等同起来。我该怎么做?

-- 编辑

此版本功能正常。 可以将其他输入的列表放在条件中,您将在语言环中切换。最后,将其绑定到某个键。

这是一种比这里想象的更简单的方法: Is it possible to alternate two input methods in 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-pychinese-sisheng,就像在(equal...) 表达式中所做的那样。

标签: variables emacs toggle evaluation


【解决方案1】:

您将 chinese-pychinese-sisheng 作为变量传递给函数 set-input-method。 Lisp 在调用函数之前评估函数的参数。它尝试评估该变量,但该符号没有作为变量的值。

您想要做的是传递 符号 chinese-pychinese-sisheng,而不是它作为变量的值(它没有)。

尝试同时引用chinese-pychinese-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)))

【讨论】:

  • 好的,只是为了记录。我非常感谢您的帮助。仍然需要进行更改以使其工作,即(equal (car input-method-history) "chinese-py") 因为input-method-history 将是双引号语言的列表。 current-input-method 不用于存储语言的名称。
  • 我明白了。我对输入法一无所知-我只是在这部分中使用了您的代码。我已根据您的评论编辑了答案。
  • 我明白了。我也不知道。我刚刚学习并在我们的讨论中添加了这些信息。我仍然无法进行切换...我无法理解为什么。它有时会起作用。当我使用切换时,这取决于我是什么输入法。如果我来自外部模式(又名 latin-1 或 utf-8),那么它将起作用。如果我来自 chinese-py 或 chinese-sisheng,就不会。
  • 我建议您提出一个单独的问题,询问您现在需要的一些帮助。这个问题可以作为一个关于引用符号的问题。为了让你的代码做你想做的事,它可能需要提出和回答多个问题。每个问题只提出一个具体问题。
猜你喜欢
  • 2011-01-27
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 2011-05-25
  • 1970-01-01
  • 1970-01-01
  • 2016-04-13
  • 2010-09-14
相关资源
最近更新 更多