org-toggle-inline-images
每次打开一个包含如下链接的新缓冲区时,我都想运行一个函数file:folder/file.jpg
:
这个怎么做 ?
尝试这个:
(add-hook 'org-mode-hook 'my-org-mode-hook)
(defun my-org-mode-hook ()
(save-excursion
(save-restriction
(goto-char (point-min))
(when (re-search-forward "file:folder/file\\.jpg" nil :noerror)
(org-toggle-inline-images)))))
我不清楚你是否想要一个正则表达式匹配。您是在寻找特定的文件名还是模式?
如果是前者,请使用search-forward
而不是re-search-forward
,然后您不需要正则表达式语法。
如果是后者,您需要根据 org-mode 'link' 语法整理出正则表达式。
对于双方括号链接语法,您可以尝试以下操作:
(add-hook 'org-mode-hook 'my-org-mode-hook)
(defun my-org-mode-hook ()
;; Enable inline images if there are jpeg images in the file.
(save-excursion
(save-restriction
(goto-char (point-min))
(catch 'done
(while (re-search-forward org-bracket-link-regexp nil :noerror)
(when (string-match "^file:.+\\.jpg" (match-string-no-properties 1))
(org-toggle-inline-images)
(throw 'done t)))))))
但我同意 lawlist 的评论——org-startup-with-inline-images
似乎已经涵盖了你。