emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Matt Price <moptop99@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: inserting a copy of an element at point (timestamps)
Date: Mon, 30 Nov 2015 18:34:41 -0500	[thread overview]
Message-ID: <m2oaebqcxa.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <CAN_Dec9gofDn4njKjvi0Ytrm5LTMq2+85mQS0t7yB37O=+6_4w@mail.gmail.com>

Try this. You may want use <> intead of [], and you can see
org-re-timestamp for other options than all.

(defun insert-ts+7 ()
  (interactive)
  (insert
   (concat "["
           (save-excursion
             (re-search-backward
              (org-re-timestamp 'all))
             (match-string 0)))
   "]")
  (org-timestamp-change 7 'day))


Matt Price writes:

> Every time I think I'm starting to learn org Mode, I find I'm actually
> really ignorant.
>
> I want to write a simple function that inserts a timestamp at point for a
> date one week after the previous timestamp. I'm sure it's very simple. But
> I can't figure out how to do it.
>
> i have this:
>
> (defun mwp/one-week-later ()
>   "add a new timestamp a week later than the previous one"
>
>   (interactive)
>   (save-excursion
>     (let ((curpos (point)))
>       (re-search-backward "<[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"  )
>       (let* ((previous-ts (org-element-context)))
>         (goto-char curpos)
>         (INSERT COPY OF PREVIOUS-TS) ;; obviously this is fake. But what to
> replace it with?
>         (org-timestamp-change 7 'dat)     )))
>     )
>
> What's the real solution? Thank you,
> Matt

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

  reply	other threads:[~2015-11-30 23:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-30 22:59 inserting a copy of an element at point (timestamps) Matt Price
2015-11-30 23:34 ` John Kitchin [this message]
2015-11-30 23:42 ` Rasmus

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=m2oaebqcxa.fsf@andrew.cmu.edu \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=moptop99@gmail.com \
    /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).