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

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

问题描述

组织模式有一个捆绑的扩展名称为 org-id ,实现org-mode文件的全局唯一ID。每个条目(与其正文的标题)可以在其中具有ID属性:PROPERTIES: drawer。

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 为以 * 开头的每个字符串。但是我想知道组织模式是否已经具备该功能。如果没有,请推荐最惯用的方法来编写一个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.

推荐答案

我通过源搜索,找不到任何明显的做法。我知道它是由组织机构使用的,但我没有太多的经验。

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.

通过启动器,以下代码片段将循环遍历当前文件中的所有轮廓标题(组织模式标题基本是标准的Emacs轮廓标题),如果还没有,则添加一个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模式文件以标题这将被跳过,如果前进。)

(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.)

这可以很容易地在一个循环中使用在组织模式议程已知的所有文件循环访问由函数返回code>(org-agenda-files),或添加到组织模式文件的保存挂钩。

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.

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

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