【问题标题】:Emacs org-mode; insert PROPERTIES drawer upon heading creationEmacs 组织模式;在创建标题时插入 PROPERTIES 抽屉
【发布时间】:2020-03-08 14:52:45
【问题描述】:

我想在创建标题时插入一个 PROPERTIES 抽屉。到目前为止我有这个

(defadvice org-insert-heading (after add-id-stuff activate)
  (template-myid))

(defun template-myid ()
  (insert "\n:PROPERTIES:\n:TIME: "
      (format "%s" (format-time-string "%Y-%m-%dT%H:%M:%S"))
      "\n:VERTEX: "
      (format "%s" (shell-command "uuidgen" t))
      "\n:EDGES:  \n:END:"))

这是有效的——有点。我的问题是 uuid 被扔了。输出如下所示

* Heading
:PROPERTIES:
:TIME: 2020-03-10T23:34:17
:VERTEX: 12836
:EDGES:  
:END:32bf9499-f9e2-49d9-b8e7-9edb40272411

不知道如何使这个行为。简单地调用 org-tempo 并插入我现成的模板会很好,但我还没有弄清楚该怎么做......

【问题讨论】:

  • 建议org-insert-heading添加抽屉?

标签: emacs org-mode drawer heading advising-functions


【解决方案1】:

这行得通

(defadvice org-insert-heading (after add-id-stuff activate)
  (template-myid))

(defun template-myid ()
  (insert "\n:PROPERTIES:\n:TIME: "
      (format-time-string "%Y-%m-%dT%H:%M:%S")
      "\n:VERTEX: "
      (org-id-uuid)
      "\n:EDGES:  \n:END:"))

生产的

* heading
:PROPERTIES:
:TIME: 2020-03-11T08:11:36
:VERTEX: 35e40480-7708-4003-9c84-f950b7ce87ce
:EDGES:  
:END:

从 NickD 的上述建议中得到帮助,Diego Zamboni 在 org-mode 邮件列表 (emacs-orgmode@gnu.org),Chris Wellons 文章,以及常见的官方 ref 转储嫌疑人。不过,我不确定为什么(shell-command "uuidgen" t) 会产生两个输出。这是他们在*scratch*中的样子

(shell-command "uuidgen" t)
2827
b5da7e0a-84c0-4db8-91f3-871b681f3022

(org-id-uuid)
"0bb7a4e1-9fc2-4428-b8de-a2d9ef5c56ab"

虽然 bash 命令行中的直接 uuidgen 只生成 UUID。首先生成上面的2827 发生了什么?我无法理解shell-command 上的*Help*

(org-id-uuid) 函数在 org-id.el 中,并且在随机性方面看起来非常彻底。

另外,有谁知道我如何通过advise-ing org-mode tempo 模板中的函数来做到这一点?我永远无法弄清楚到底是什么函数在处理<...-TAB

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多