emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-remember to org-capture
@ 2012-01-27 14:05 Martin Pohlack
  2012-01-28 16:00 ` Bastien
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Pohlack @ 2012-01-27 14:05 UTC (permalink / raw)
  To: org-mode

Hi,

I am in the process of switching from org-remember to org-capture.

I used a custom function with org-remember to capture into a
host-specific sub-tree under "* Inbox" in order to minimize git merge
conflicts between my machines.

My tree typically looks like this:

* Inbox
*** Inbox:host1
***** INBOX idea 1
***** INBOX idea 2
*** Inbox:host2
***** INBOX idea 3

The custom function with org-remember only needed to create the target
headline's name.  Org-remember would find it or create it (IIRC):

---->8----------------------------------------------------------------
(defun my-host-name ()
  "Returns the name of the current host minus the domain."
  (let ((hostname (downcase (system-name))))
    (save-match-data
      (substring hostname (string-match "^[^.]+" hostname) (match-end 0)))))

(defun my-org-remember-headline ()
  (concatenate 'string "Inbox:" (my-host-name)))
---->8----------------------------------------------------------------

The problem is now that org-capture expects a function that creates
the target node and positions point at a child of the target, is this
correct?

My hacky solution is to use the file+function template and looks like
this:

---->8----------------------------------------------------------------
(defun my-org-capture-function ()
  (goto-char
   (org-find-exact-headline-in-buffer
    (concatenate 'string "Inbox:" (my-host-name)) nil t))
  (org-end-of-line)
  (org-insert-subheading ""))
---->8----------------------------------------------------------------

But it looks clumsy and always inserts as first child.  Is there a
more elegant approach, maybe using the refiling mechanism?

Thanks,
Martin

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

* Re: org-remember to org-capture
  2012-01-27 14:05 org-remember to org-capture Martin Pohlack
@ 2012-01-28 16:00 ` Bastien
  2012-01-28 21:34   ` Martin Pohlack
  0 siblings, 1 reply; 3+ messages in thread
From: Bastien @ 2012-01-28 16:00 UTC (permalink / raw)
  To: Martin Pohlack; +Cc: org-mode

Hi Martin,

Martin Pohlack <mp26@os.inf.tu-dresden.de> writes:

> I am in the process of switching from org-remember to org-capture.

Possibly useless hint: M-x org-capture-import-remember-templates RET

Can you restate the problem more directly?  What are your capture
template, what is it supposed to achieve, how does it fail to do 
what you want -- we'll work out something from there.

Thanks,

-- 
 Bastien

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

* Re: org-remember to org-capture
  2012-01-28 16:00 ` Bastien
@ 2012-01-28 21:34   ` Martin Pohlack
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Pohlack @ 2012-01-28 21:34 UTC (permalink / raw)
  To: Bastien; +Cc: org-mode

Hi Bastien,

thanks for your reply.

On 28.01.2012 17:00, Bastien wrote:
> Hi Martin,
> 
> Martin Pohlack <mp26@os.inf.tu-dresden.de> writes:
> 
>> I am in the process of switching from org-remember to org-capture.
> 
> Possibly useless hint: M-x org-capture-import-remember-templates RET

Yes thanks.  Unfortunately, this does not convert my custom function :-).

In fact, it does not convert anything (with org-mode 7.6).

> Can you restate the problem more directly?  What are your capture
> template, what is it supposed to achieve, how does it fail to do 
> what you want -- we'll work out something from there.

All right, here is my (stripped down) setup:

 '(org-remember-templates (quote (
   ("Inbox-Arbeit" 97 "* INBOX %^{Title}
  %U%?
  %i" "~/Daten/plan_arbeit.org" my-org-remember-headline nil)
   ("Inbox-Privat" 112 "* INBOX %^{Title}
  %U%?
  %i" "~/Daten/plan_privat.org" my-org-remember-headline nil)
   ("Journal" 106 "* %^{Eintrag}%?%i%&" "~/Daten/Journal.org"
    return_formated_date nil))))

Let' focus on the first entry (Inbox-Arbeit): the only non-standard
thing here is the function my-org-remember-headline.

---->8----------------------------------------------------------------
(defun my-host-name ()
  "Returns the name of the current host minus the domain."
  (let ((hostname (downcase (system-name))))
    (save-match-data
      (substring hostname (string-match "^[^.]+" hostname) (match-end 0)))))

(defun my-org-remember-headline ()
  (concatenate 'string "Inbox:" (my-host-name)))
---->8----------------------------------------------------------------

Run on “host1” it will return “Inbox:host1”, etc.

My “plan_arbeit.org” file contains this structure:

---->8----------------------------------------------------------------
* Inbox
*** Inbox:host1
*** Inbox:host2
---->8----------------------------------------------------------------

So that each machine has a separate inbox under a global container.
This reduces git merge conflicts when I merge my plan files from
different machines (but this is a side discussion).

What changed from org-remember to org-capture is that custom functions
used to return a string with a target parent headline.  Now they are
expected to modify “point” as a side effect before the actual capturing
happens (and not return anything).

Here is my new capture template:

 '(org-capture-templates (quote (
   ("a" "Inbox-Arbeit" entry
    (file+function "~/Daten/plan_arbeit.org" my-org-capture-function)
    "* INBOX %^{Title}
  %U%?
  %i"))))

I drafted this new function for org-capture:

---->8----------------------------------------------------------------
(defun my-org-capture-function ()
  (goto-char
   (org-find-exact-headline-in-buffer
    (concatenate 'string "Inbox:" (my-host-name)) nil t))
  (org-end-of-line)
  (org-insert-subheading ""))
---->8----------------------------------------------------------------

This shall capture again under “Inbox/Inbox:$hostname”.

The function feels clumsy because this functionality should already be
in org-mode (e.g., the refiling stuff).  Also, it files new items as
first child under the target and not as last child.

The question is simply: Is there a more elegant approach, maybe using
the refiling mechanism?  Have I overlooked something obvious?

Thanks,
Martin

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

end of thread, other threads:[~2012-01-28 21:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27 14:05 org-remember to org-capture Martin Pohlack
2012-01-28 16:00 ` Bastien
2012-01-28 21:34   ` Martin Pohlack

Code repositories for project(s) associated with this 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).