简体   繁体   English

emacs 的多个实例覆盖 recentf-list

[英]multiple instances of emacs overwrite recentf-list

I have quite usual recentf config.我有很平常的 recentf 配置。

(use-package recentf
  :config
  (setq
    recentf-save-file "~/.cache/emacs/recentf"
    recentf-max-saved-items 100000
    recentf-max-menu-items 5000
    )
  (recentf-mode 1)

The problem is that I run multiple emacs instances.问题是我运行了多个 emacs 实例。 Unfortunately, it overwrites recentf file when the instances are closed.不幸的是,它会在实例关闭时覆盖 recentf 文件。

instance 1 loads recentf version 1
instance 2 loads recentf version 1
... some times passed instance 1 and instance 2 do some work ...
instance 1 get closed and saves recentf version 3
instance 2 get closed and saves recentf version 4

Problem is that when instance 2 closes it does not read recentf of version 3. As a result files added by version 3 are lost.问题是,当实例 2 关闭时,它不会读取版本 3 的 recentf。结果,版本 3 添加的文件丢失了。 You can imagine it gets worst with more than one instance.您可以想象,不止一个实例会变得更糟。 How can I make recentf work correctly with multiple instaces.如何使 recentf 在多个实例中正常工作。

In case anybody still encounters this issue:如果有人仍然遇到此问题:

Try the sync-recentf package. I have not used it but it looks like what you want.试试sync-recentf package。我没用过,但它看起来像你想要的。


Every Emacs instance maintains the variable recentf-list which is populated by calling recentf-load-list .每个 Emacs 实例都维护变量recentf-list ,该变量通过调用recentf-load-list填充。 Opening files will then append the new filepath to this variable but not to the file.打开文件将 append 这个变量的新文件路径而不是文件。 Calling recentf-save-list will then cause this variable to be written to the recentf-file you specified.然后调用recentf-save-list将导致此变量写入您指定的 recentf 文件。 Note that this writing out is not appending to the file but rather replacing its content.请注意,此写出不是附加到文件,而是替换其内容。

Simply calling recentf-load-list before saving is not an option either because this will override the unique files from the recentf-list .在保存之前简单地调用recentf-load-list也不是一个选项,因为这将覆盖recentf-list的唯一文件。

The aforementioned package works around this limitation by creating a dummy file on top of recentf-list effectively seperating this variable into 'old and new'.前面提到的 package 通过在recentf-list之上创建一个虚拟文件来解决这个限制,有效地将这个变量分成“旧的和新的”。 When calling recentf-save-list a new recentf-list is created by the following steps:调用recentf-save-list时,将通过以下步骤创建一个新的recentf-list

  1. Save the new filepaths保存新文件路径
  2. Override recentf-list with the values from recentf-filerecentf-file中的值覆盖recentf-list
  3. Append saved filepaths to recentf-list Append 将文件路径保存到recentf-list
  4. Override recentf-file with the values from `recentf-list用 `recentf-list 中的值覆盖recentf-file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM