Closed OrionRandD closed 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 🙂
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...
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 🙂
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:
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/")))
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:
TODO Ox-hugo
Hugo is better than org2blog https://gohugo.io/getting-started/quick-start/ https://zzamboni.org/post/my-emacs-configuration-with-commentary/ How to set up hugo: apt install hugo then: cd ~/org~/ and issue hugo new site blog cd ~/org~/blog git init Then add a theme: cd ~/org~/blog/themes/ git submodule add https://github.com/budparr/gohugo-theme-ananke.git ananke cd .. echo 'theme = "ananke"' >> config.toml hugo new posts/my-first-post.md Edit the my-first-post.md cd ~/org~/blog then start the server hugo server -D open it in: http://localhost:1313/ in emacs it is "org-hugo"
(use-package ox-hugo
:ensure t
:after ox)
(require 'ox-hugo) (require 'org-hugo-auto-export-mode)
(use-package org-capture
:ensure nil
:config
(defun org-hugo-new-subtree-post-capture-template ()
;; "Returns org-capture' template string for new Hugo post. ;; See
org-capture-templates' for more information."
(let ((title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title
(fname (org-hugo-slug title)))
(mapconcat #'identity
`(,(concat " TODO " title)
":PROPERTIES:"
,(concat ":EXPORT_HUGO_BUNDLE: " fname)
":EXPORT_FILE_NAME: index"
":END:"
"%?\n") ;Place the cursor here finally
"\n")))
(add-to-list 'org-capture-templates
'("o" ;org-capture' binding + o "Post" entry ;; It is assumed that below file is present in
org-directory'
;; and that it has an "Ideas" heading. It can even be a
;; symlink pointing to the actual location of all-posts.org!
(file+datetree (concat org-directory "~/blog/content/posts/my-post.org")
"* TODO %^{Description} %^g\n%?\nAdded: %U")
(function org-hugo-new-subtree-post-capture-template))))
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... :(
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")))
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...
You're welcome, you don't need to thanks myself every commit 🙂
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)
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)
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?
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
Perfect, I'm glad that you solved it 🙂
@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.
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-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")
;; 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"))
;; for dreams
("i" "Dreams" entry (file+datetree (concat org-directory "~/Gtd_mylife/org-capture_tpls/my-dreams.org"))
"* %^{Description} %^g %?\nAdded: %U")
;; for journalling
;; for hugo blogging
"* TODO %^{Description} %^g\n%?\nAdded: %U"))
;; for capturing books to read
;; for log time
;; for capturing chunks of webpages and/or webpages themselves with W3m or EWW