Answers:
更新:
尚未注意到Org Mode 9.2更改了模板扩展机制,其中org-structure-template-alist
仅适用于"#+BEGIN_"
和定义的块"#+END_"
。并且("p" ":PROPERTIES:?:END:")
不再接受像这样的条目。
如上面的链接所述,其他“复杂”模板可以由function定义tempo-define-template
,并且org-tempo必须被加载((require 'org-tempo)
)。实际的条目org-structure-template-alist
被转换为org-tempo-tags
经由tempo-define-template
通过org-tempo
,并且org-tempo-tags
默认为:
(("<i" . tempo-template-org-index)
("<A" . tempo-template-org-ascii)
("<H" . tempo-template-org-html)
("<L" . tempo-template-org-latex)
("<v" . tempo-template-org-verse)
("<s" . tempo-template-org-src)
("<q" . tempo-template-org-quote)
("<l" . tempo-template-org-export-latex)
("<h" . tempo-template-org-export-html)
("<E" . tempo-template-org-export)
("<e" . tempo-template-org-example)
("<C" . tempo-template-org-comment)
("<c" . tempo-template-org-center)
("<a" . tempo-template-org-export-ascii)
("<I" . tempo-template-org-include))
对于您的情况,可以通过以下方式定义模板:
(tempo-define-template "my-property"
'(":PROPERTIES:" p ":END:" >)
"<p"
"Insert a property tempate")
以下答案仅适用于9.2之前的组织模式
是的,您可以这样添加一个条目:
(add-to-list 'org-structure-template-alist '("p" ":PROPERTIES:?:END:"))
然后在org文件中,键入<p
和TAB
,它将扩展为属性,并将该点留在的位置?
。
您可以通过键入以下内容在变量的文档中找到更多详细信息 C-h v org-structure-template-alist RET
。
他们在组织模式的自定义中引入不兼容的更改的频率确实很可惜。
以下代码为您提供了9.2版之前的org-mode的旧结构模板。该函数org-complete-expand-structure-template
是9.1和更高版本的纯副本org-try-structure-completion
是的稍微修改的版本。(我在此处添加了类型检查。)
安装该代码后,您可以
(add-to-list 'org-structure-template-alist '("p" ":PROPERTIES:?:END:"))
再次使用旧模板。
(defvar org-structure-template-alist)
(defun org+-avoid-old-structure-templates (fun &rest args)
"Call FUN with ARGS with modified `org-structure-template-alist'.
Use a copy of `org-structure-template-alist' with all
old structure templates removed."
(let ((org-structure-template-alist
(cl-remove-if
(lambda (template)
(null (stringp (cdr template))))
org-structure-template-alist)))
(apply fun args)))
(eval-after-load "org"
'(when (version<= "9.2" (org-version))
(defun org-try-structure-completion ()
"Try to complete a structure template before point.
This looks for strings like \"<e\" on an otherwise empty line and
expands them."
(let ((l (buffer-substring (point-at-bol) (point)))
a)
(when (and (looking-at "[ \t]*$")
(string-match "^[ \t]*<\\([a-zA-Z]+\\)$" l)
(setq a (assoc (match-string 1 l) org-structure-template-alist))
(null (stringp (cdr a))))
(org-complete-expand-structure-template (+ -1 (point-at-bol)
(match-beginning 1)) a)
t)))
(defun org-complete-expand-structure-template (start cell)
"Expand a structure template."
(let ((rpl (nth 1 cell))
(ind ""))
(delete-region start (point))
(when (string-match "\\`[ \t]*#\\+" rpl)
(cond
((bolp))
((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
(setq ind (buffer-substring (point-at-bol) (point))))
(t (newline))))
(setq start (point))
(when (string-match "%file" rpl)
(setq rpl (replace-match
(concat
"\""
(save-match-data
(abbreviate-file-name (read-file-name "Include file: ")))
"\"")
t t rpl)))
(setq rpl (mapconcat 'identity (split-string rpl "\n")
(concat "\n" ind)))
(insert rpl)
(when (re-search-backward "\\?" start t) (delete-char 1))))
(advice-add 'org-tempo-add-templates :around #'org+-avoid-old-structure-templates)
(add-hook 'org-tab-after-check-for-cycling-hook #'org-try-structure-completion)
(require 'org-tempo)
))
>
上的符号tempo-define-template
吗?如果不是...。它在定义中的作用是什么?