emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* inserting a copy of an element at point (timestamps)
@ 2015-11-30 22:59 Matt Price
  2015-11-30 23:34 ` John Kitchin
  2015-11-30 23:42 ` Rasmus
  0 siblings, 2 replies; 3+ messages in thread
From: Matt Price @ 2015-11-30 22:59 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 773 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1056 bytes --]

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

* Re: inserting a copy of an element at point (timestamps)
  2015-11-30 22:59 inserting a copy of an element at point (timestamps) Matt Price
@ 2015-11-30 23:34 ` John Kitchin
  2015-11-30 23:42 ` Rasmus
  1 sibling, 0 replies; 3+ messages in thread
From: John Kitchin @ 2015-11-30 23:34 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

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

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

* Re: inserting a copy of an element at point (timestamps)
  2015-11-30 22:59 inserting a copy of an element at point (timestamps) Matt Price
  2015-11-30 23:34 ` John Kitchin
@ 2015-11-30 23:42 ` Rasmus
  1 sibling, 0 replies; 3+ messages in thread
From: Rasmus @ 2015-11-30 23:42 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Matt Price <moptop99@gmail.com> 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)))

aka save-excursion.  Also, you should limit your search to the current
heading.

>       (re-search-backward "<[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"  )

org-ts-regexp or maybe org-ts-regexp-both.


>       (let* ((previous-ts (org-element-context)))
>         (goto-char curpos)
>         (INSERT COPY OF PREVIOUS-TS) ;; obviously this is fake. But what to
> replace it with?

(save-excursion (insert (org-element-interpret-data previous-ts))
                (org-timestamp-change 7 'day))

>         (org-timestamp-change 7 'dat)     )))

You need to use ’day.

You probably don’t need org-element in this case, but then again why
not...

Rasmus

-- 
Warning: Everything saved will be lost

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

end of thread, other threads:[~2015-11-30 23:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30 22:59 inserting a copy of an element at point (timestamps) Matt Price
2015-11-30 23:34 ` John Kitchin
2015-11-30 23:42 ` Rasmus

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).