为 Org-mode 中的每个条目分配 ID [英] Assign IDs to every entry in Org-mode

查看:24
本文介绍了为 Org-mode 中的每个条目分配 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Org-mode 有一个名为 org-id,它实现了组织模式文件的全局唯一 ID.每个条目(带有正文的标题)都可以在其 :PROPERTIES: 抽屉中具有一个 ID 属性.

Org-mode has a bundled extension called org-id, that implements global unique IDs for org-mode files. Every entry (a headline with its body) can have an ID property in its :PROPERTIES: drawer.

单个条目的新 ID 可以通过函数 org-id-get-create 分配.

New ID for a single entry can be assigned with a function org-id-get-create.

如何为组织模式文件中的每个条目分配一个 ID?

我可以使用 Emacs 方法来自动执行此操作,例如为每个以 * 开头的字符串调用 org-id-get-create 的宏.但我想知道 org-mode 是否已经具备这种能力.如果没有,请推荐最惯用的方法来为此目的编写 elisp 代码.

I could use an Emacs method of automating this, like a macro that calls org-id-get-create for every string starting with *. But I'd like to know if org-mode already has that capability. If not, please recommend the most idiomatic way to write an elisp code for this purpose.

推荐答案

我搜索了源代码,但找不到任何明显可以执行此操作的内容.我知道它被 Org-mobile 使用,但我对此没有太多经验.

I searched through the source and couldn't find anything obvious to do this already. I know it's used by Org-mobile, but I've not much experience of that.

作为启动器,以下代码段将遍历当前文件中的所有大纲标题(Org-mode 标题基本上是标准的 Emacs 大纲标题),如果还没有 ID,则添加一个 ID:

By way of a starter, the following snippet will loop through all outline headings in the current file (Org-mode headings are basically standard Emacs outline headings), and add an ID if there's not already one there:

   (require 'org-id)
   (save-excursion
      (goto-char (point-max))
      (while (outline-previous-heading)
        (org-id-get-create)))

(如果你想知道为什么这个循环在缓冲区上向后而不是向前,那是因为 while 循环将总是至少调用一次大纲导航函数,如果你的 Org-mode 文件以标题开头,如果继续前进,将跳过该标题.)

(If you're wondering why this loop goes backwards over the buffer rather than forwards, it's because the while loop will always call the outline navigation function at least once and if your Org-mode file starts with a heading this would be skipped if going forwards.)

通过循环函数 (org-agenda-files) 返回的条目,可以在 Org-mode 议程已知的所有文件的循环中合理地使用它,或者添加到组织模式文件的保存钩子.

This could be reasonably easily used within a loop over all the files known to the Org-mode agenda by looping over the entries returned by the function (org-agenda-files), or added to a save hook for Org-mode files.

如果有人比我更灵活,没有先到达那里,如果您能确定何时添加 ID,我可能会将上述内容扩展为一个完整的解决方案.

If someone more nimble-fingered than I doesn't get there first, if you can identify when you'd like the IDs added I could probably expand the above to be a complete solution.

这篇关于为 Org-mode 中的每个条目分配 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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