6

I've noticed that org-structure-template-alist changed (I'm using org-mode version 9.2) to automatically expand to #+BEGIN_<some block tag> #+END_<some block tag>. I wonder if it's possible to add different kind of templates. For instance a :PROPERTIES:<some properties>:END: template.

Is it possible or should I turn to another package like yasnippets?

7

UPDATE:

Haven't noticed that Org Mode 9.2 changed the mechanism of template expansion, where org-structure-template-alist is only for blocks defined by "#+BEGIN_" and "#+END_". And entry like ("p" ":PROPERTIES:?:END:") is no longer accepted.

As mentioned in the above link, other "complex" template can be defined by function tempo-define-template , and org-tempo must be loaded((require 'org-tempo)). Actually the entries of org-structure-template-alist are converted to org-tempo-tags via tempo-define-template by org-tempo, and org-tempo-tags defaults to:

(("<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))

For your case, you can define a template by:

(tempo-define-template "my-property"
               '(":PROPERTIES:" p ":END:" >)
               "<p"
               "Insert a property tempate")

Below answer only works for Org mode version prior to 9.2

Yes, you could add an entry to it like this:

(add-to-list 'org-structure-template-alist '("p" ":PROPERTIES:?:END:"))

Then in org file, you type <p and TAB, it will expand to property and leave the point at the position of ?.

And you can find more details in the documentation of the variable by typing C-h v org-structure-template-alist RET.

  • Very helpful answer, thanks. Btw, Is the > symbol on the tempo-define-template a typo? If not.... What is the role of it in the definition? – Dox Jan 15 at 12:45
  • 1
    Glad it helps:) Not a typo, it means the line would be indented, tempo-define-template is built-in defun, see the docstring for details. – whatacold Jan 16 at 15:21

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.