emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Setting PROPERTIES in remember templates automatically
@ 2009-11-27  9:48 Tassilo Horn
  2009-11-27 12:53 ` James TD Smith
  0 siblings, 1 reply; 3+ messages in thread
From: Tassilo Horn @ 2009-11-27  9:48 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

in my remember templates, I'd like to set some PROPERTIES to the value
of some org-remember escape sequences.  Till now, I did that by defining
a template like that:

  ("NORMAL"  ?n "* %?\n  %i\n  :PROPERTIES:\n  :created: %U\n  :END:")

This works, but templates become very large quickly.  And I don't like
that I have to do the indentation on my own.

Ok, now I have a new usecase.  I want to set a property if some escape
sequence is non-nil.  Or more concrete: I want to set a property :link:
if the template escape sequence %a has a value.

Therefore, I tried this template using the %(sexp) escape:

  ("NORMAL"  ?n
   "* %?\n  %i %(org-set-property \"created\" \"%U\")
               %(org-set-property \"annotation\" \"%a\")")

Unfortunately, when I select this template, emacs hangs and I have to
hit C-g.  At that point, I get this expansion in my remember buffer:

--8<---------------cut here---------------start------------->8---
* %?
   %(org-set-property "created" "[2009-11-27 Fri 10:38]")
   %(org-set-property "annotation"
   "[[file:~/News/drafts/drafts/4::hit%20C%20g][file:~/News/drafts/drafts/4::hit C g]]")
--8<---------------cut here---------------end--------------->8---

What I'd like to have is something like the existing

  %^{prop}p   Prompt the user for a value for property `prop'

but more like

  %{prop,escape}p   Insert property `prop' with value taken from escape,
                    if that is non-nil

With this

  "%{created,U} %{link,a}"

in a template would always create a :created: property with an inactive
timestamp, and :link: would only be inserted, if there is an annotation
for that remember invocation.

What do you think?

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Setting PROPERTIES in remember templates automatically
  2009-11-27  9:48 Setting PROPERTIES in remember templates automatically Tassilo Horn
@ 2009-11-27 12:53 ` James TD Smith
  2009-11-27 22:17   ` Tassilo Horn
  0 siblings, 1 reply; 3+ messages in thread
From: James TD Smith @ 2009-11-27 12:53 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-orgmode

Hi Tassilo,

On 2009-11-27 10:48:06(+0100), Tassilo Horn wrote:

<snip>
 
> What I'd like to have is something like the existing
> 
>   %^{prop}p   Prompt the user for a value for property `prop'
> 
> but more like
> 
>   %{prop,escape}p   Insert property `prop' with value taken from escape,
>                     if that is non-nil
> 
> With this
> 
>   "%{created,U} %{link,a}"
> 
> in a template would always create a :created: property with an inactive
> timestamp, and :link: would only be inserted, if there is an annotation
> for that remember invocation.
> 
> What do you think?

I've actually got something like this working, as part of a whole load of
improvements to remember which I've been working on for ages. If you want to
take a look it's in the remember-lite branch at
git://yog-sothoth.mohorovi.cc/org-mode.

The first major change is that remember templates are now plists. Old-style
templates are automatically converted to the new format, but if you want to
access any of the new features you will need to use the new template format, and
add your templates to org-remember-templates-2.

Properties are now set by adding a :properties property to the list. This should
be followed by a list containing either:
- A string. Query the user for the property value.
- A cons cell. The head should be a string (the property name) and the tail can
  be either:
  - Another string: add the property with that string as its value
  - A variable: add the property with the value of the variable 
  - A function: call the function to get the property value.

There is also a variable `org-remember-default-properties', for properties you
want added to all remembered items.

Mine is set like this

--8<---------------cut here---------------start------------->8---
(setq org-remember-default-properties
      '(("CREATED" .
       (lambda () (format-time-string (org-time-stamp-format t t)
       org-remember-current-time)))
       ("CONTEXT" .
        (lambda () (if (and (marker-buffer org-clock-marker)
             (not (eq (marker-buffer org-clock-marker)
                   (current-buffer))))
                   (org-substring-no-properties org-clock-heading)
                         "Idle")))))
--8<---------------cut here---------------end--------------->8---

which adds two properties to every item I remember, one containing the current
time as an inactive timestamp and the other containing the name of the currently
clocked task or 'Idle' if I'm not clocked into anything.

Here's an example template with properties:

--8<---------------cut here---------------start------------->8---
(:key ?r :type headline :name "Book"
      :target "~/Personal/ReadingList.org::Books"
      :properties ("AUTHOR" "ISBN") :tag t :tagscope file
      :template "* MEDIA %^{Title} %?")
--8<---------------cut here---------------end--------------->8---

When I remember something using this template, the CREATED and CONTEXT
properties are added automatically, and I get asked for the values for AUTHOR
and ISBN.

Anyway, there are lots of other changes, and probably a few bugs, and there
isn't much in the way of documentation yet :). Let me know how you get on.

James 

--
|-<James TD Smith>-<email/ahktenzero@mohorovi.cc>-|

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Setting PROPERTIES in remember templates automatically
  2009-11-27 12:53 ` James TD Smith
@ 2009-11-27 22:17   ` Tassilo Horn
  0 siblings, 0 replies; 3+ messages in thread
From: Tassilo Horn @ 2009-11-27 22:17 UTC (permalink / raw)
  To: James TD Smith; +Cc: emacs-orgmode

James TD Smith <ahktenzero@mohorovi.cc> writes:

Hi James,

>> What I'd like to have is something like the existing
>> 
>>   %^{prop}p   Prompt the user for a value for property `prop'
>> 
>> but more like
>> 
>>   %{prop,escape}p   Insert property `prop' with value taken from escape,
>>                     if that is non-nil
>> 
>> With this
>> 
>>   "%{created,U} %{link,a}"
>> 
>> in a template would always create a :created: property with an inactive
>> timestamp, and :link: would only be inserted, if there is an annotation
>> for that remember invocation.
>> 
>> What do you think?
>
> I've actually got something like this working, as part of a whole load
> of improvements to remember which I've been working on for ages. If
> you want to take a look it's in the remember-lite branch at
> git://yog-sothoth.mohorovi.cc/org-mode.

Thanks, I'll have a look.

> The first major change is that remember templates are now plists.
> Old-style templates are automatically converted to the new format, but
> if you want to access any of the new features you will need to use the
> new template format, and add your templates to
> org-remember-templates-2.
>
> Properties are now set by adding a :properties property to the
> list. This should be followed by a list containing either:
> - A string. Query the user for the property value.
> - A cons cell. The head should be a string (the property name) and the tail can
>   be either:
>   - Another string: add the property with that string as its value
>   - A variable: add the property with the value of the variable 
>   - A function: call the function to get the property value.
>
> There is also a variable `org-remember-default-properties', for
> properties you want added to all remembered items.
>
> Mine is set like this
>
> (setq org-remember-default-properties
>       '(("CREATED" .
>        (lambda () (format-time-string (org-time-stamp-format t t)
>        org-remember-current-time)))
>        ("CONTEXT" .
>         (lambda () (if (and (marker-buffer org-clock-marker)
>              (not (eq (marker-buffer org-clock-marker)
>                    (current-buffer))))
>                    (org-substring-no-properties org-clock-heading)
>                          "Idle")))))
>
> which adds two properties to every item I remember, one containing the
> current time as an inactive timestamp and the other containing the
> name of the currently clocked task or 'Idle' if I'm not clocked into
> anything.

What if the function or variable evals to nil?  I'd expect that then the
property is not inserted at all.

> Here's an example template with properties:
>
> (:key ?r :type headline :name "Book"
>       :target "~/Personal/ReadingList.org::Books"
>       :properties ("AUTHOR" "ISBN") :tag t :tagscope file
>       :template "* MEDIA %^{Title} %?")

Looks pretty self-explanatory and logical to me.

> When I remember something using this template, the CREATED and CONTEXT
> properties are added automatically, and I get asked for the values for
> AUTHOR and ISBN.

Nice.

> Anyway, there are lots of other changes, and probably a few bugs, and
> there isn't much in the way of documentation yet :). Let me know how
> you get on.

This looks all very nice.  Do you plan to merge your enhancements back
into Carsten's branch anytime soon?

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-27 22:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-27  9:48 Setting PROPERTIES in remember templates automatically Tassilo Horn
2009-11-27 12:53 ` James TD Smith
2009-11-27 22:17   ` Tassilo Horn

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).