5

I have different single files where i store different types of data, one data type per file. For instance one file for addresses and one file with an entry for each of my music CD's.

I need the following functionality per data file: For each new headline I make, automatically insert a :PROPERTIES: drawer, with specified property keys, just below the headline.

So, for instance when in my address file, I hit C-c to add a new headline for a new entry, and I get something like this:

* <headline text to be made>
:PROPERTIES:
   :Name:
   :Street:
   :Tel:
:END:

where the property keys ("Name", "Street", "Tel") are given with no property value.

Or, if my single file contains data for my mineral collection, I would like each new headline to look like this:

* <headline text to be made>
:PROPERTIES:
   :Mineral_type:
   :Longitude:
   :Latitude:
:END:

I have two questions:

1) How can I automatically insert such property drawers, with specified property keys, under each header, based on some file variable settings in the top of the file?

2) How can I cycle through the properties in a drawer to add property values to each property key?

1 Answer 1

5

You can use orgmode templating system (for question 1). At the begining of your org file, you can add the following lines:

 # -*- eval: (save-excursion  (org-babel-goto-named-src-block "mytemplate") (org-babel-execute-src-block)) ; -*-

 #+NAME: mytemplate
 #+BEGIN_SRC elisp :results none 
   (add-to-list 'org-structure-template-alist '("T" "* ?\n:PROPERTIES:\n   :Name:\n   :Street:\n   :Tel:\n:END:\n"))
 #+END_SRC

When you will open you org file again, you will be asked for a confirmation (type 'y' for a temporary change (confirmation will be asked next time) or ! to avoid confirmation at next opening))

Then, when you need to insert a new entry, you only have to type <T then the <TAB> key and your template will be used. In the source code, the ? corresponds to where the cursor will be positioned after template insertion => you can change its place at your convenience.

Used reference: https://redd.it/64jhlt

2
  • Thanks so much! It works for my first question. So, I have a following up one: is the "save-excursion" in your code saving anything on my system, and if so, where? And where is the list "org-structure-template-alist" stored?
    – myotis
    Commented Sep 3, 2017 at 15:37
  • The save-excursion is proposed in the reference I linked ( "save-excursion returns to where you were the last time you opened the buffer (the way it normally would)"). It is only a temporary save. The org-structure-template-alist is a variable that you can consult with C-h v org-structure-template-alist.
    – Lgen
    Commented Sep 3, 2017 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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