emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martin Pohlack <mp26@os.inf.tu-dresden.de>
To: rjhorn@alum.mit.edu
Cc: Org-mode list <emacs-orgmode@gnu.org>
Subject: Re: Date-tree navigation question
Date: Fri, 09 Mar 2012 21:35:24 +0100	[thread overview]
Message-ID: <4F5A698C.10902@os.inf.tu-dresden.de> (raw)
In-Reply-To: <4F54DB9D.4060904@alum.mit.edu>

Hi Robert,

Not sure what you want to do after opening but I have some code that
extracts a time range out of a date tree.  Maybe you can reuse the
searching parts ...

Cheers,
Martin

----------------------------------------------------------------------
(defun mp26/org-find-headline-prefix-in-buffer (heading &optional buffer pos-only)
  "Find node with heading-prefix HEADING in BUFFER.
Return a marker to the heading if it was found, or nil if not.
If POS-ONLY is set, return just the position instead of a marker.

The heading prefix must match as prefix of the full headline.  It
may have a TODO keyword, a priority cookie and tags in the
standard locations."
  (with-current-buffer (or buffer (current-buffer))
    (save-excursion
      (save-restriction
	(widen)
	(goto-char (point-min))
	(let (case-fold-search)
	  (if (re-search-forward
	       (format org-complex-heading-regexp-format
		       (concat (regexp-quote heading) ".*")) nil t)
	      (if pos-only
		  (match-beginning 0)
		(move-marker (make-marker) (match-beginning 0)))))))))

(defun mp26/org-week-from-journal ()
  "Insert a copy of the current week from the journal."
  (interactive)
  (insert
   (mapconcat
    'identity
    (with-current-buffer "Journal.org<Daten>"
      (loop for days in '(-6 -5 -4 -3 -2 -1 0)
            collect
            (let* ((date (calendar-current-date days))
                   (date-string
                    (format "%d-%02d-%02d"
                            (nth 2 date) (nth 0 date) (nth 1 date))))
              (setq pos (mp26/org-find-headline-prefix-in-buffer
                         date-string nil t))
              (when pos
                (goto-char pos)
                (org-copy-subtree)
                (car kill-ring)))))
   "")))
----------------------------------------------------------------------

      parent reply	other threads:[~2012-03-09 20:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-05 15:28 Date-tree navigation question Robert Horn
2012-03-05 18:34 ` Bernt Hansen
2012-03-09 20:35 ` Martin Pohlack [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F5A698C.10902@os.inf.tu-dresden.de \
    --to=mp26@os.inf.tu-dresden.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=rjhorn@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).