如何引用目前在Emacs Lisp中加载的文件? [英] How to refer to the file currently being loaded in Emacs Lisp?

查看:125
本文介绍了如何引用目前在Emacs Lisp中加载的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个引用非elisp文件(一个小的Python程序),并希望能够说它与当前文件在同一个目录,但与不同的文件名。 在许多脚本语言中,有一些东西像 __ FILE __ (在PHP中),以获得当前文件的绝对路径。



如果要包含的文件位于 load-path 中,那么我可以使用(locate-libraryfile.py ),但是如果文件不在加载路径中,我会被卡住。



Emacs Lisp有一种方法文件找出自己的绝对路径(加载时,未被访问)?

解决方案

Mx描述-variable load-file-name

  load-file-name是'C源代码'。 

文档:
由`load'加载的文件的全名。

您可能也对符号文件感兴趣函数,它将告诉你定义了一个指定的函数或变量的绝对文件名。



如果你想要看,可以查看 load-in-progress 变量。如果这是 nil ,那么没有任何负载正在进行中(你可能是缓冲区中的 eval d) 。在这种情况下,您可以尝试(buffer-file-name)获取文件名。


I am looking to include a reference to a non-elisp file (a small Python program), and would like to be able to say "it is in the same directory as the current file, but with a different file name." In many scripting languages, there are things like __FILE__ (in PHP) for getting an absolute path to the current file.

If the file to be included is in the load-path, then I can find it with (locate-library "file.py" t), but I'm kind of stuck if the file is not in the load path.

So is there a way for an Emacs Lisp file to find out its own absolute path (when being loaded, not visited)?

解决方案

M-x describe-variable load-file-name

load-file-name is a variable defined in `C source code'.

Documentation:
Full name of file being loaded by `load'.

You might also be interested in the symbol-file function, which will tell you the absolute filename in which a specified function or variable was defined.

If you want to get fancy, you can check the load-in-progress variable. If that's nil, then no load is in progress (and you're presumably being eval'd in a buffer). In that case, you could try (buffer-file-name) to get the filename.

这篇关于如何引用目前在Emacs Lisp中加载的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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