From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Pohlack Subject: Re: Date-tree navigation question Date: Fri, 09 Mar 2012 21:35:24 +0100 Message-ID: <4F5A698C.10902@os.inf.tu-dresden.de> References: <4F54DB9D.4060904@alum.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([208.118.235.92]:57641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S66XE-0001vb-NM for emacs-orgmode@gnu.org; Fri, 09 Mar 2012 15:35:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S66XC-0000n0-Mz for emacs-orgmode@gnu.org; Fri, 09 Mar 2012 15:35:32 -0500 Received: from os.inf.tu-dresden.de ([141.76.48.99]:41889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S66XC-0000mg-GG for emacs-orgmode@gnu.org; Fri, 09 Mar 2012 15:35:30 -0500 In-Reply-To: <4F54DB9D.4060904@alum.mit.edu> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: rjhorn@alum.mit.edu Cc: Org-mode list 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" (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))))) ""))) ----------------------------------------------------------------------