From mboxrd@z Thu Jan 1 00:00:00 1970 From: zhenjiang zech xu Subject: Re: headlines without timestampes Date: Thu, 29 May 2014 17:38:24 -0600 Message-ID: References: <877g54zfk9.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0118456a36835404fa926fea Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wq9uc-0006TI-Dt for emacs-orgmode@gnu.org; Thu, 29 May 2014 19:39:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wq9ub-0003Db-IM for emacs-orgmode@gnu.org; Thu, 29 May 2014 19:39:06 -0400 In-Reply-To: <877g54zfk9.fsf@bzg.ath.cx> 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: Bastien Cc: emacs-orgmode@gnu.org --089e0118456a36835404fa926fea Content-Type: text/plain; charset=UTF-8 didn't know the regexp org-ts-regexp-*. Thanks! On Thu, May 29, 2014 at 10:59 AM, Bastien wrote: > Hi, > > zhenjiang zech xu writes: > > > For a simple example, assuming current entry is: > > > > * [2014-05-06 Thu] this is the heading > > blahblah... > > > > I'd like to get the time string and the title "this is the heading" > > separately. Is there a canonical way to do that with org-mode APIs? > > This function returns a CONS with the timestamp and the rest of the > heading: > > (defun get-timestamp-and-heading () > (interactive) > (save-excursion > (org-back-to-heading t) > (let* ((h (org-element-property :raw-value (org-element-at-point))) > (h-no-ts (replace-regexp-in-string org-ts-regexp-both "" h)) > (ts (and (string-match org-ts-regexp-both h) > (match-string 0 h)))) > (cons (org-trim h-no-ts) ts)))) > > HTH, > > -- > Bastien > --089e0118456a36835404fa926fea Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
didn't know the regexp org-ts-regexp-*. Thanks!


On Thu, Ma= y 29, 2014 at 10:59 AM, Bastien <bzg@gnu.org> wrote:
Hi,

zhenjiang zech xu <zhenjiang.x= u@gmail.com> writes:

> For a simple example, assuming current entry is:
>
> * [2014-05-06 Thu] this is the heading
> =C2=A0=C2=A0 blahblah...
>
> I'd like to get the time string and the title "this is the he= ading"
> separately. Is there a canonical way to do that with org-mode APIs?
This function returns a CONS with the timestamp and the rest of the heading:

(defun get-timestamp-and-heading ()
=C2=A0 (interactive)
=C2=A0 (save-excursion
=C2=A0 =C2=A0 (org-back-to-heading t)
=C2=A0 =C2=A0 (let* ((h (org-element-property :raw-value (org-element-at-po= int)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(h-no-ts (replace-regexp-in-string= org-ts-regexp-both "" h))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(ts (and (string-match org-ts-rege= xp-both h)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (matc= h-string 0 h))))
=C2=A0 =C2=A0 =C2=A0 (cons (org-trim h-no-ts) ts))))

HTH,

--
=C2=A0Bastien

--089e0118456a36835404fa926fea--