Emacs 和符号链接(symbolic link)

标签 emacs

假设我在 /home/.bashrc 处有一个符号链接(symbolic link),它指向其他地方的实际 .bashrc 文件:/some/other/path/.bashrc位于 git 存储库下。

如果我在 Emacs 中打开 /home/.bashrc,它会提示我:

Symbolic link to Git-controlled source file; follow link? (y or n)

我通常输入y,因为我想编辑实际的文件。但是,稍后,如果我执行 buffer-file-name Emacs 返回 /some/other/path/.bashrc,而不是 /home/.bashrc)。

我希望 Emacs 记住我访问此文件的方式是通过符号链接(symbolic link)。

换句话说,我希望我的符号链接(symbolic link)对 Emacs 是透明的。部分原因是因为我有几个依赖于当前文件路径的 Emacs 宏,并且这些宏认为我正在处理位于 /some/other/path 中的文件,而不是位于/home/.

我该怎么做?

最佳答案

只是为了完整性,对于有疑问的人

Git 控制的源文件的符号链接(symbolic link);跟随链接? (y 或 n)

但不一定想要 OP 想要的东西,这是来自 C-h v vc-follow-symlinks 的文档(从我的 Emacs 版本开始 - 请查找您自己的 Emacs 了解详细信息):

vc-follow-symlinks is a variable defined in vc-hooks.el. Its value is ask

Documentation: What to do if visiting a symbolic link to a file under version control. Editing such a file through the link bypasses the version control system, which is dangerous and probably not what you want.

If this variable is t, VC follows the link and visits the real file, telling you about it in the echo area. If it is `ask', VC asks for confirmation whether it should follow the link. If nil, the link is visited and a warning displayed.

You can customize this variable.

结果是,为了避免每次都收到提示,您可以在 .emacs 中设置

(setq vc-follow-symlinks t)

始终遵循符号链接(symbolic link)(并直接编辑“实际”文件),或

(setq vc-follow-symlinks nil)

始终像在符号链接(symbolic link)本身一样编辑文件(这似乎工作正常 - 它不会删除符号链接(symbolic link)或任何内容 - 但它不会让您在文件上使用版本控制相关的内容)。我更喜欢前者(与OP不同)。

关于Emacs 和符号链接(symbolic link),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15390178/

相关文章:

emacs - 从 emacs 运行方案

emacs - 在 Emacs 中使用 texcount 来确定 Latex 或 tex 文件的字数(需要可选参数)

emacs - 有没有办法注释掉大部分代码?

emacs - 如何永远不扩展注释和字符串中的 yasnippets

c - 如何使用 makefile 调试项目

emacs - 如何在评论中填写项目符号列表

ubuntu - 为 emacs 安装添加源 URI

Emacs:通过 crontab 批量处理 org 模式文件

emacs - 如何在 emacs 24 中启用电对模式

emacs - SLIME 未从 Emacs 加载