M-x calc-reset,也绑定到C-x * 0,是你需要的。来自info manual:
C-x * 0' command ('calc-reset'; that's 'C-x *' followed by a
zero) resets the Calculator to its initial state. This clears the
stack, resets all the modes to their initial values (the values that
were saved withm m' (calc-save-modes')), clears the caches (*note
Caches::), and so on. (It does _not_ erase the values of any
variables.) With an argument of 0, Calc will be reset to its default
state; namely, the modes will be given their default values. With a
positive prefix argument,C-x * 0' 保留堆栈的内容
但将其他所有内容重置为其初始状态;带有否定前缀
参数,`C-x * 0' 保留堆栈的内容但重置
其他一切都恢复到默认状态。
编辑:哎呀。即使这样也不能清除变量。我不确定是否有一种直接的方法可以一直回到原始状态:(
编辑 2:看起来 Calc 将所有变量(包括 pi 和 e 之类的“内置”)存储为带有前缀“var-”的全局变量。据我所知,它不会跟踪模式(如 pi)设置了哪些变量,以及用户设置了哪些变量。此外,默认用户变量存储为 var-q0、var-q1 等。因此,为了清除所有变量,您需要编译启动时存在的变量和状态列表,擦除不在该列表中的所有内容,然后恢复该列表中变量的原始值。这当然是可能的,但有点乏味。
编辑 3:这是我的尝试。我又看了一下 calc-mode,在启动时它定义了我添加到下面的 my-calc-builtin-vars 的变量。第二行将删除 Emacs 中所有以前缀 'var-' 开头并且在此列表中 not 的变量。这将包括您定义的任何变量,或者在另一个包中。所以让我们希望没有其他人使用前缀“var-”。并且它不会重置内置变量的值,所以如果你将 pi 重新定义为 3,它将保持为 3。
(setq my-calc-builtin-vars
'("var-nan" "var-uinf" "var-sym" "var-lines" "var-Modes"
"var-EvalRules" "var-inf" "var-phi" "var-pi" "var-gamma" "var-π"
"var-φ" "var-γ" "var-spec" "var-e" "var-i"))
(defun really-reset-calc ()
(interactive)
(calc-reset nil)
(mapc #'(lambda (el) (unintern el))
(remove nil (mapcar
#'(lambda (el) (unless (member el my-calc-builtin-vars) el))
(all-completions "var-" obarray)))))
更新日期:2016 年 8 月 6 日
当前内置变量列表:
(setq my-calc-builtin-vars
'("var-CommuteRules" "var-Decls" "var-DistribRules" "var-EvalRules"
"var-FactorRules" "var-FitRules" "var-Holidays" "var-IntegAfterRules"
"var-IntegLimit" "var-InvertRules" "var-JumpRules" "var-MergeRules"
"var-Modes" "var-NegateRules" "var-e" "var-gamma" "var-i" "var-phi"
"var-pi" "var-γ" "var-π" "var-φ"))