0

I've recently decided to learn how to use Emacs. As I want to learn by using, I thought to use Org mode package as a way to track the books I want to read and the ones I've read. I want to create a template for to list these books.

How can I create a template that automatically generates a given list of properties to be filled in under a heading?

In the properties section of the manual a good example of what I would like to do is given :

 * CD collection
 ** Classic
 *** Goldberg Variations
     :PROPERTIES:
     :Title:     Goldberg Variations
     :Composer:  J.S. Bach
     :Publisher: Deutsche Grammophon
     :NDisks:    1
     :END:

However, what I've understood of emacs and orgmode is that they are meant to ease the task for me and allow me to gain some time doing such a list. Therefore, I would like to have a sort of template that automatically creates the property drawer with all the properties ready to be filled. At every new entry inside the CD collection I would like to get :

** New entry
     :PROPERTIES:
     :Title:     
     :Composer:  
     :Publisher: 
     :NDisks:  
     :END:

These properties may be inherited, as described in the manual, or set in a configuration file. I thought to use easy templates but I was not sure it would have been the proper way to do it.

Besides, I would like to have examples of similar lists. I've found a lot of examples about how to implement the gtd method in orgmode but few things about look-like lists.

Drew
  • 75,699
  • 9
  • 109
  • 225
Brutus320
  • 51
  • 5

1 Answers1

1

Here is a slightly modified version of the code in Add subheadings to all headings in an org-file at some level:

#+BEGIN_SRC emacs-lisp :results none
(setq properties-list '("Title" "Composer" "Publisher" "NDisks"))

(let ((MATCH t)
      (SCOPE 'file)
      (SKIP nil)
      (spacing nil))
  (org-map-entries
   (lambda ()
     (let ((level (nth 1 (org-heading-components))))
       (if (= level 3)                     
           (save-restriction
             (org-narrow-to-subtree)
             (goto-char (point-max))

             (org-insert-heading)
             (insert "New Entry\n")
             (dolist (property properties-list)
               (org-entry-put (point) property nil)
               )
             ;; now cut tree and paste at level 4
             (org-cut-subtree)
             (org-paste-subtree 4)
             )))) MATCH SCOPE SKIP))
#+END_SRC

** Class One
*** Student 1
**** Essay 1
*** Student 2
*** Student 3
**** Essay 1
** Class Two
*** Student 1
*** Student 2

When you run the code block with C-c C-c, you will see

** Class One
*** Student 1
**** Essay 1
**** New Entry
:PROPERTIES:
:Title:
:Composer:
:Publisher:
:NDisks:
:END:


*** Student 2
**** New Entry
:PROPERTIES:
:Title:
:Composer:
:Publisher:
:NDisks:
:END:


*** Student 3
**** Essay 1
**** New Entry
:PROPERTIES:
:Title:
:Composer:
:Publisher:
:NDisks:
:END:


** Class Two
*** Student 1
**** New Entry
:PROPERTIES:
:Title:
:Composer:
:Publisher:
:NDisks:
:END:


*** Student 2
**** New Entry
:PROPERTIES:
:Title:
:Composer:
:Publisher:
:NDisks:
:END:

You can modify the code for your needs.

joon
  • 690
  • 7
  • 17