我想遍历并检查 ORG 文件中的每个标题,看看它是否是图像文件的链接。如果是,我需要对标题做一些处理。
* no_image_heading # should print nothing
* [[/path/to/img.png][description]] # should print the filename (in my test function)
我当前的代码是:
(defun my/org-img-link-p ()
"Check if heading is a link to an image."
(interactive "r")
(let ((context (org-element-context)))
(and (eq (car context) 'link)
(string= (org-element-property :type context) "file")
(member (file-name-extension (org-element-property :path context))
'("jpg" "png")))))
(defun my/org-parse-img-heading ()
"Parsing of headings"
(interactive "r")
(if (my/org-img-link-p)
(message "%s" (org-element-property :path (org-element-context)))
;(do-something-else-with-heading)
))
(defun my/org-test-function ()
(interactive)
(org-map-entries 'my/org-parse-img-heading))
但是,它永远不会打印文件,即使
my/org-img-link-p
如果我在标题上有光标并且我这样做eval
(my/org-img-link-p)
.