如何在Elisp中获取变量的初始值? [英] How can I get a variable's initial value in Elisp?

查看:64
本文介绍了如何在Elisp中获取变量的初始值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Emacs Lisp中,是否有一个函数来获取由 defvar 启动的符号的初始值?像 some-function 如下所示:

 (defvar varinitial值)
(setq varchanged value)
(some-function'var)
=> inital value


解决方案

Emacs不记得初始值。


pre $ (defvar varinitial value)
(setq varchanged value)$ b $在 * scratch * 缓冲区中,$ $ c $

c>初始值不再可用,全部停止。



如果 defvar 在加载的文件中执行,Emacs会记住它的加载位置; (symbol-file var'defvar)返回文件名,您可以获取变量初始化的原始表达式(而不是原始值),假设档案还在。这也可以通过命令 M-x find-variable


In Emacs Lisp, is there a function to get the initial value of a symbol initilized by defvar? Like the some-function shown below:

(defvar var "initial value")
(setq var "changed value")
(some-function 'var)
=> "inital value"

解决方案

Emacs doesn't remember the initial value. If you evaluate

(defvar var "initial value")
(setq var "changed value")

in the *scratch* buffer, "initial value" is no longer available, full stop.

If the defvar was performed in a loaded file, Emacs remembers where it's loaded from; (symbol-file var 'defvar) returns the file name, and you can get an the original expression that the variable was initialized with (but not the original value), assuming the file is still around. This is also available via the command M-x find-variable.

这篇关于如何在Elisp中获取变量的初始值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆