rememberYou / .emacs.d

🎉 Personal GNU Emacs configuration
The Unlicense
470 stars 43 forks source link

org-templates #4

Closed OrionRandD closed 5 years ago

OrionRandD commented 5 years ago

How can I join these two templates, so that the firs one becomes only a option in the templates list? (use-package org :ensure org-plus-contrib)

(use-package org-contacts
  :ensure nil
  :after org)

(use-package org-capture :ensure nil :after org :preface (defvar my/org-contacts-template "* %(org-contacts-template-name) :PROPERTIES: :ALIAS: %^{hefis} :NICKNAME: %^{hefistion} :PHONE: %^{123-456-789} :PHONE: %^{123-456-789} :EMAIL: %(org-contacts-template-email) :EMAIL: %(org-contacts-template-email) :ADDRESS: %^{289 Cleveland St. Brooklyn, 11206 NY, USA} :BIRTHDAY: %^{dd-mm-yyyy} :NOTE: %^{NOTE} :END:" "Template for org-contacts.") :custom (org-capture-templates `(("c" "Contact" entry (file+headline "~/org~/Gtd_mylife/org-capture_tpls/my-contacts.org" "Friends"), my/org-contacts-template :empty-lines 1))))


(define-key global-map "\C-cc" 'org-capture)

(setq org-capture-templates '(("a" "Appointment" entry (file+headline (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-appointments.org") "Calendar") "* APPT %^{Description} %^g\n%?\nAdded: %U")

 ("m" "Brain" entry (function org-brain-goto-end)
    "* %i%?" :empty-lines 1)

;; for todo tasks

("d" "Long Tail TODO Task" entry (file+headline "" "Tasks") "* TODO %?\n %u\n %a")

;; for tasks

("t" "Task Diary" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/taskdiary.org")) "* TODO %^{Description} %^g\n%?\nAdded: %U")

;; for long tail tasks

("d" "Long Tail TODO Task" entry (file+headline "" "Tasks") "* TODO %?\n %u\n %a")

;; for general notes

("n" "Notes" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-notes.org"))

  "* %^{Description} %^g %?\nAdded: %U")

;; for dreams

("i" "Dreams" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-dreams.org"))

"* %^{Description} %^g %?\nAdded: %U")

;; for journalling

 ("j" "Journal" entry
  (file+datetree
   (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-journal.org"))
  "** %^{Heading}")

;; for hugo blogging

   ("o" "Posts"
 (file+datetree (concat org-directory "~/blog/content/posts/my-post.org")

"* TODO %^{Description} %^g\n%?\nAdded: %U"))

;; for capturing books to read

   ("b" "Book" entry (file+headline "~/Gtd_mylife/org-capture_tpls/books-to_read.org" "books to read")
  "* TODO %\\1 - %\\2%?\n%U\n:PROPERTIES:\n:NAME: %^{NAME}\n:TITLE: %^{TITLE}\n:END:\n")

;; for log time

   ("l" "Log Time" entry
  (file+datetree
   (concat org-directory "~/Gtd_mylife/org-capture_tpls/timelog.org"))
  "** %U - %^{Activity}  :TIME:")

;; for capturing chunks of webpages and/or webpages themselves with W3m or EWW

   ("w" "Website" plain 
  (function org-website-clipper)
  "* %a\n%T\n" :immediate-finish t)))
rememberYou commented 5 years ago

Good evening,

First of all, in order to have a more accurate answer to your request and to make it easier for other users to read your problem, I recommend that in the future you place your code in appropriate tags and try to isolate the issue (no need to include all the templates) ☺️

That being said, if I have understood your problem correctly, you simply want to be able to choose from your templates when capturing a task (correct me if I'm wrong).

The first point I noticed is that you do not inform org-contacts about the ".org" contact file including your contacts.

Here's how to solve this:

(use-package org-contacts
  :ensure nil
  :after org
  :custom (org-contacts-files '("~/.personal/agenda/contacts.org")))

where ~/.personal/agenda/contacts.org is the path to your contacts.org file, change it by yours.

NOTE: I can also see that you define :PHONE: and :EMAIL: twice, once is enough 🙂

Then, you used defvar to define your my/org-contacts-template variable. This is a good way to do this in order to better structure your templates and ensure their authenticity.

However, your omission is that you redefine org-capture-templates, which will delete your template for my/org-contacts-template.

NOTE: you also define ("d" "Long Tail TODO Task" entry (file+headline "" "Tasks") twice.

Here's how to solve this:

(use-package org-capture
  :ensure nil
  :after org
  :preface
  (defvar my/org-contacts-template "* %(org-contacts-template-name)
:PROPERTIES:
:ALIAS: %^{hefis}
:NICKNAME: %^{hefistion}
:PHONE: %^{123-456-789}
:EMAIL: %(org-contacts-template-email)
:ADDRESS: %^{289 Cleveland St. Brooklyn, 11206 NY, USA}
:BIRTHDAY: %^{dd-mm-yyyy}
:NOTE: %^{NOTE}
:END:" "Template for org-contacts.")
  :custom
  (org-capture-templates
   `(("a" "Appointment" entry
      (file+headline (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-appointments.org") "Calendar")
      "* APPT %^{Description} %^g\n%?\nAdded: %U")

     ("b" "Book" entry (file+headline "~/Gtd_mylife/org-capture_tpls/books-to_read.org" "books to read")
      "* TODO %\\1 - %\\2%?\n%U\n:PROPERTIES:\n:NAME: %^{NAME}\n:TITLE: %^{TITLE}\n:END:\n")

     ("d" "Long Tail TODO Task" entry (file+headline "" "Tasks")
      "* TODO %?\n %u\n %a")

     ("i" "Dreams" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-dreams.org"))
      "* %^{Description} %^g %?\nAdded: %U")

     ("j" "Journal" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-journal.org"))
      "** %^{Heading}")

     ("l" "Log Time" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/timelog.org"))
      "** %U - %^{Activity}  :TIME:")

     ("m" "Brain" entry (function org-brain-goto-end)
      "* %i%?"
      :empty-lines 1)

     ("n" "Notes" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-notes.org"))
      "* %^{Description} %^g %?\nAdded: %U")

     ("o" "Posts" (file+datetree (concat org-directory  "~/blog/content/posts/my-post.org")
      "* TODO %^{Description} %^g\n%?\nAdded: %U"))

     ("t" "Task Diary" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/taskdiary.org"))
      "* TODO %^{Description} %^g\n%?\nAdded: %U")

     ("w" "Website" plain (function org-website-clipper)
      "* %a\n%T\n"
      :immediate-finish t))))

One advice I want to give is to try to organize your templates as best you can. Indeed, org-capture is a formidable weapon for productivity, but your config can quickly become a mess.

To avoid this, try to aerate the code, structure your templates alphabetically, avoid useless comments and favour the creation of templates, especially to avoid structure repetitions as you can have for the templates of your notes and those of your dreams: "* %^{Description} %^g %?\nAdded: %U").

Here's how to solve this, by adding this template below the :preface keyword:

(use-package org-capture
    :ensure nil
    :after org
    :preface
    (defvar my/org-basic-task-template "* %^{Description} %^g %?\nAdded: %U" 
       "Template for basic task.")
    ...

And so, in org-capture-templates, you can refer to this template like this:

...
("i" "Dreams" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-dreams.org")),
my/org-basic-task-template)

("n" "Notes" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-notes.org")),
my/org-basic-task-template)
...

I hope I was able to answer your question, do not hesitate to rephrase your question if the problem persists, it will be pleasure to answer you 🙂

OrionRandD commented 5 years ago

Thx a lot for cleaning and organising the code. I still have the problem of not being able to call the "my/org-contacts-template" inside the options. I thought of calling it with a letter "c". How do I insert that in the list, so that it asks me for filling the template data?

(org-capture-templates `(("a" "Appointment" entry (file+headline (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-appointments.org") "Calendar") "* APPT %^{Description} %^g\n%?\nAdded: %U")

 ("b" "Book" entry (file+headline "~/Gtd_mylife/org-capture_tpls/books-to_read.org" "books to read")
  "* TODO %\\1 - %\\2%?\n%U\n:PROPERTIES:\n:NAME: %^{NAME}\n:TITLE: %^{TITLE}\n:END:\n")

 ("c" "Contacts" ...

 ("d" "Long Tail TODO Task" entry (file+headline "" "Tasks")
  "* TODO %?\n %u\n %a")

etc...

rememberYou commented 5 years ago

With pleasure.

I forgot to explicitly mention that to be able to create a new "Contact" with your template, you have to add it in org-capture-templates.

Here is the complete code with this addition:

(use-package org-capture
  :ensure nil
  :after org
  :preface
  (defvar my/org-contacts-template "* %(org-contacts-template-name)
:PROPERTIES:
:ALIAS: %^{hefis}
:NICKNAME: %^{hefistion}
:PHONE: %^{123-456-789}
:EMAIL: %(org-contacts-template-email)
:ADDRESS: %^{289 Cleveland St. Brooklyn, 11206 NY, USA}
:BIRTHDAY: %^{dd-mm-yyyy}
:NOTE: %^{NOTE}
:END:" "Template for org-contacts.")
  :custom
  (org-capture-templates
   `(("a" "Appointment" entry
      (file+headline (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-appointments.org") "Calendar")
      "* APPT %^{Description} %^g\n%?\nAdded: %U")

     ("b" "Book" entry (file+headline "~/Gtd_mylife/org-capture_tpls/books-to_read.org" "books to read")
      "* TODO %\\1 - %\\2%?\n%U\n:PROPERTIES:\n:NAME: %^{NAME}\n:TITLE: %^{TITLE}\n:END:\n")

     ("c" "Contact" entry (file+headline "~/.personal/agenda/contacts.org" "Contacts"),
      my/org-contacts-template
      :empty-lines 1)

     ("d" "Long Tail TODO Task" entry (file+headline "" "Tasks")
      "* TODO %?\n %u\n %a")

     ("i" "Dreams" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-dreams.org"))
      "* %^{Description} %^g %?\nAdded: %U")

     ("j" "Journal" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-journal.org"))
      "** %^{Heading}")

     ("l" "Log Time" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/timelog.org"))
      "** %U - %^{Activity}  :TIME:")

     ("m" "Brain" entry (function org-brain-goto-end)
      "* %i%?"
      :empty-lines 1)

     ("n" "Notes" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-notes.org"))
      "* %^{Description} %^g %?\nAdded: %U")

     ("o" "Posts" (file+datetree (concat org-directory  "~/blog/content/posts/my-post.org")
      "* TODO %^{Description} %^g\n%?\nAdded: %U"))

     ("t" "Task Diary" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/taskdiary.org"))
      "* TODO %^{Description} %^g\n%?\nAdded: %U")

     ("w" "Website" plain (function org-website-clipper)
      "* %a\n%T\n"
      :immediate-finish t))))

where in :

("c" "Contact" entry (file+headline "~/.personal/agenda/contacts.org" "Contacts"),
my/org-contacts-template
:empty-lines 1)

you need to change the ~/.personal/agenda/contacts.org path to your contacts.org file 🙂

OrionRandD commented 5 years ago

Thx a lot for helping me. I do not mean to bother you. But, I get this error when calling the contacts option:

:PROPERTIES:

:ALIAS:

:NICKNAME: %^{hefistion}

:PHONE: %^{123-456-789}

:EMAIL: %![Error: (void-function org-contacts-template-email)]

:ADDRESS: %^{289 Cleveland St. Brooklyn, 11206 NY, USA}

:BIRTHDAY: %^{dd-mm-yyyy}

:NOTE: %^{NOTE}

:END:

rememberYou commented 5 years ago

Well, it seems that org-contacts is not installed on your GNU Emacs because org-contacts-template-name is a function from org-contacts. Can you find this function if you do C-h f org-contacts-template-name?

If not, I invite you to install org-contact which is provided with the org-plus-contrib package 🙂

Be sure to add at least these source packages:

(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("melpa" . "http://melpa.org/packages/")
                         ("org" . "http://orgmode.org/elpa/")))
OrionRandD commented 5 years ago

That's strange. Because I do have this function in my emacs C-h f org-contacts-template-name

org-contacts-template-name is a compiled Lisp function in ‘org-contacts.el’. (org-contacts-template-name &optional RETURN-VALUE) Try to return the contact name for a template. If not found return RETURN-VALUE or something that would ask the user.

And running that template outside the list gave me no errors...

Also I have:

("org" . "http://orgmode.org/elpa/")))

In my repo list and it is working. Anyway, I reinstalled org-plus-contrib and that went well...

But, I noticed this line in my message buffer:

Deprecated date/weektree capture templates changed to ‘file+olp+datetree’. [2 times]

And there is this another bit up there I hadn t seen after checking my emacs.org that for sure is interfering on my org template list:


I tested this option in my org-capture and, of course, it did not work

       '("o"                ;`org-capture' binding + o

On pressing the option "o" it gave me "nil"


It seems too much debbuing... :(

rememberYou commented 5 years ago

I tested the code I sent you and it works perfectly with my GNU Emacs.

To debug, there's nothing easier to rewrite things step by step. For example, first make sure this works, then you can simply add your other templates as you go along.

Also please, try to avoid overloading the text with tagless code, it's difficult to read unnecessarily.

Try this code and let me know if it doesn't work:

(use-package org :ensure org-plus-contrib)

(use-package org-capture
  :ensure nil
  :after org
  :preface
  (defvar my/org-contacts-template "* %(org-contacts-template-name)
:PROPERTIES:
:ALIAS: %^{hefis}
:NICKNAME: %^{hefistion}
:PHONE: %^{123-456-789}
:EMAIL: %(org-contacts-template-email)
:ADDRESS: %^{289 Cleveland St. Brooklyn, 11206 NY, USA}
:BIRTHDAY: %^{dd-mm-yyyy}
:NOTE: %^{NOTE}
:END:" "Template for org-contacts.")
  :custom
  (org-capture-templates
   `(("a" "Appointment" entry
      (file+headline (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-appointments.org") "Calendar")
      "* APPT %^{Description} %^g\n%?\nAdded: %U")

     ("c" "Contact" entry (file+headline "~/.personal/agenda/contacts.org" "Contacts"),
      my/org-contacts-template
      :empty-lines 1))))

(use-package org-contacts
  :ensure nil
  :after org
  :custom (org-contacts-files '("~/.personal/agenda/contacts.org")))
OrionRandD commented 5 years ago

I will test the code... I am trying to re-work my init.el before that... Then after these steps, if I have more issues, I will ask for more help here. Thx a lot, so far...

rememberYou commented 5 years ago

You're welcome, you don't need to thanks myself every commit 🙂

OrionRandD commented 5 years ago

I have tested the code on its own and with this layout and it gives me the same error: Error (use-package): Failed to parse package org: use-package: :ensure wants exactly one argument

But, if I comment the first part and the last one. Evereting works, but the contact template...

(use-package org :ensure org-plus-contrib

(use-package org-capture
  :ensure nil
  :after org
  :preface
  (defvar my/org-contacts-template "* %(org-contacts-template-name)
:PROPERTIES:
:ALIAS: %^{hefis}
:NICKNAME: %^{hefistion}
:PHONE: %^{123-456-789}
:EMAIL: %(org-contacts-template-email)
:ADDRESS: %^{289 Cleveland St. Brooklyn, 11206 NY, USA}
:BIRTHDAY: %^{dd-mm-yyyy}
:NOTE: %^{NOTE}
:END:" "Template for org-contacts.")
:custom

  (org-capture-templates

   '(

    ("a" "Appointments" entry (file+headline "~/org~/my-appointments.org" "Calendar")
  "* APPT %^{Description} %^g\n%?\nAdded: %U")

    ("b" "Books" entry (file+headline "~/org~/books.org" "books to read")
  "* TODO %\\1 - %\\2%?\n%U\n:PROPERTIES:\n:NAME: %^{NAME}\n:TITLE: %^{TITLE}\n:END:\n")

     ("c" "Contact" entry (file+headline "~/org~/contacts.org" "Contacts"), my/org-contacts-template :empty-lines 1)

    ("d" "Dreams" entry (file+datetree "~/org~/my-dreams.org") "* %^{Description} %^g %?\nAdded: %U")

    ("j" "Journal" entry (file+datetree "~/org~/journal.org") "* %?\nEntered on %U\n  %i\n  %a")

    ("l" "Log Time" entry (file+datetree "~/org~/timelog.org") "** %U - %^{Activity}  :TIME:")

    ("m" "Brain" entry (function org-brain-goto-end) "* %i%?" :empty-lines 1)

    ("n" "Notes" entry (file+datetree "~/org~/my-notes.org") "* %^{Description} %^g %?\nAdded: %U")

    ;; ("o" "Posts" (file+datetree "~/org~/my-post.org") "* TODO %^{Description} %^g\n%?\nAdded: %U")

     ("t" "Tasks" entry (file+datetree "~/org~/tasks.org")
  "* TODO %^{Description} %^g\n%?\nAdded: %U")

     ("w" "Website" plain (function org-website-clipper) "* %a\n%T\n" :immediate-finish t)

(use-package org-contacts :ensure nil :after org :custom (org-contacts-files '("~/org~/contacts.org" "Contacts")))))))

OrionRandD commented 5 years ago

I have tested the code on its own and with this layout and it gives me the same error: Error (use-package): Failed to parse package org: use-package: :ensure wants exactly one argument

But, if I comment the first part and the last one. Evereting works, but the contact template...

(use-package org :ensure org-plus-contrib

(use-package org-capture
  :ensure nil
  :after org
  :preface
  (defvar my/org-contacts-template "* %(org-contacts-template-name)
:PROPERTIES:
:ALIAS: %^{hefis}
:NICKNAME: %^{hefistion}
:PHONE: %^{123-456-789}
:EMAIL: %(org-contacts-template-email)
:ADDRESS: %^{289 Cleveland St. Brooklyn, 11206 NY, USA}
:BIRTHDAY: %^{dd-mm-yyyy}
:NOTE: %^{NOTE}
:END:" "Template for org-contacts.")
:custom

  (org-capture-templates

   '(

    ("a" "Appointments" entry (file+headline "~/org~/my-appointments.org" "Calendar")
  "* APPT %^{Description} %^g\n%?\nAdded: %U")

    ("b" "Books" entry (file+headline "~/org~/books.org" "books to read")
  "* TODO %\\1 - %\\2%?\n%U\n:PROPERTIES:\n:NAME: %^{NAME}\n:TITLE: %^{TITLE}\n:END:\n")

     ("c" "Contact" entry (file+headline "~/org~/contacts.org" "Contacts"), my/org-contacts-template :empty-lines 1)

    ("d" "Dreams" entry (file+datetree "~/org~/my-dreams.org") "* %^{Description} %^g %?\nAdded: %U")

    ("j" "Journal" entry (file+datetree "~/org~/journal.org") "* %?\nEntered on %U\n  %i\n  %a")

    ("l" "Log Time" entry (file+datetree "~/org~/timelog.org") "** %U - %^{Activity}  :TIME:")

    ("m" "Brain" entry (function org-brain-goto-end) "* %i%?" :empty-lines 1)

    ("n" "Notes" entry (file+datetree "~/org~/my-notes.org") "* %^{Description} %^g %?\nAdded: %U")

    ;; ("o" "Posts" (file+datetree "~/org~/my-post.org") "* TODO %^{Description} %^g\n%?\nAdded: %U")

     ("t" "Tasks" entry (file+datetree "~/org~/tasks.org")
  "* TODO %^{Description} %^g\n%?\nAdded: %U")

     ("w" "Website" plain (function org-website-clipper) "* %a\n%T\n" :immediate-finish t)

(use-package org-contacts :ensure nil :after org :custom (org-contacts-files '("~/org~/contacts.org" "Contacts")))))))

rememberYou commented 5 years ago

Add this in the beginning of your config: (use-package use-package-ensure-system-package :ensure t)

Basically, it tell use-package to always use :ensure t by default.

If this doesn't work, can you paste your config in Gist or in a parser?

OrionRandD commented 5 years ago

This worked for me:

  (setq org-capture-templates

'(

("a" "Appointments" entry (file+headline "~/org~/my-appointments.org" "Calendar") "* APPT %^{Description} %^g\n%?\nAdded: %U")

 ("b" "Books" entry (file+headline "~/org~/books.org" "books to read")

"* TODO %\1 - %\2%?\n%U\n:PROPERTIES:\n:NAME: %^{NAME}\n:TITLE: %^{TITLE}\n:END:\n")

;; you have to set up a template for this 
;; ("c" "Contacts" entry (file+headline "~/org~/contacts.org" "Contacts"), my/org-contacts-template :empty-lines 1)

 ("d" "Dreams" entry (file+datetree "~/org~/my-dreams.org") "* %^{Description} %^g %?\nAdded: %U")

 ("j" "Journal" entry (file+datetree "~/org~/journal.org") "* %?\nEntered on %U\n  %i\n  %a")

 ("l" "Log Time" entry (file+datetree "~/org~/timelog.org") "** %U - %^{Activity}  :TIME:")

 ("m" "Brain" entry (function org-brain-goto-end) "* %i%?" :empty-lines 1)

 ("n" "Notes" entry (file+datetree "~/org~/my-notes.org") "* %^{Description} %^g %?\nAdded: %U")

 ;; you have to set hugo up for this
 ;; ("o" "Posts" (file+datetree "~/org~/my-post.org") "* TODO %^{Description} %^g\n%?\nAdded: %U")

 ("t" "Tasks" entry (file+datetree "~/org~/tasks.org")

"* TODO %^{Description} %^g\n%?\nAdded: %U")

 ;; example is in:
 ;; /home/vagner/.emacs.d/elpa/org-plus-contrib-20190520/org-contacts.el
 ("c" "Contacts" entry (file "~/org~/contacts.org")
"* %(org-contacts-template-name)
 :PROPERTIES:
 :EMAIL: 
 :PHONE:
 :MOBILE:
 :BIRTHDAY:
 :ADDRESS:
 :NICKNAME:
 :ALIAS:
 :ICON:
 :IGNORE:
 :NOTE:
 :END:")

 ("w" "Website" plain (function org-website-clipper) "* %a\n%T\n" :immediate-finish t)))

When I choose "c" for contacts, it gives me this output:


Even though it says that there is an void-function org-contacts-template-name error. When I type the contact name in the heading it works and then I can fill in the fields. I think that it is ok for now. I discovered that this is a bug in the org-contacts.el(c) package

rememberYou commented 5 years ago

Perfect, I'm glad that you solved it 🙂

OrionRandD commented 5 years ago

@rememberYou this is a similar error discussed in a thread --> https://lists.gnu.org/archive/html/emacs-orgmode/2013-03/msg00150.html Although, it is an old one from 2013, in a way it is similar to mine. Anyway, my config, with your patience and help, is in a working state now.