在什么情况下,`org-element` 返回的标题的 `:title` 属性不能是字符串? (或者如何可靠地获取标题字符串?)

问题描述 投票:0回答:1

我正在尝试使用

org-element
解析组织文件。

    (org-element-map (org-element-parse-buffer 'headline) 'headline
      (lambda (a-hl)
        (message "debug:title:%s" (org-element-property :title a-hl)))

上面的代码有效。但是,下面的代码略有不同,但无法按照我期望的方式工作:

    (org-element-map (org-element-parse-buffer) 'headline
      (lambda (a-hl)
        (message "debug:title:%s" (org-element-property :title a-hl)))

它的结果不是相同的,而是打印了巨大的性别树,尽管看起来差异应该只是速度。

我该怎么做才能可靠地获得头衔?

parsing emacs org-mode
1个回答
0
投票

我和OP有同样的问题,这是我机器上可重现的示例:

(with-temp-buffer
  (org-mode)
  (insert "* Hello")
  (cl-flet ((say-type (prefix hl)
              (message "Headline title from %s is of type: %s"
                       prefix
                       (type-of (org-element-property :title hl)))))
    (org-element-map (org-element-parse-buffer) 'headline
      (lambda (hl) (say-type "map" hl)))
    (goto-char (point-min))
    (say-type "context" (org-element-context))
    (say-type "at-point" (org-element-at-point))))

我期望:字符串无处不在。我得到:

Headline title from map is of type: cons
Headline title from context is of type: string
Headline title from at-point is of type: string

(请随意将其添加到问题中并删除此答案)

© www.soinside.com 2019 - 2024. All rights reserved.