emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Marco Wahl <marcowahlsoft@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Timestamped items with M-RET
Date: Sat, 17 Mar 2018 10:41:45 +0100	[thread overview]
Message-ID: <84zi37f38m.fsf@gmail.com> (raw)

Hi!

Possibly you also like the feature to create list items including the
current time with key M-RET when in such item.  This is for creating
lists like the following:

- [2018-03-17 Sat 10:19] Write to the list.
- [2018-03-17 Sat 10:22] Think about wording.

This is similar to the functionality already available for timer
items.  (info "(org) Timers")

Get the functionality by adding the following code to your init file.

#+begin_src emacs-lisp
(defun mw-org-insert-item-with-ina-ts-when-on-such-item ()
  "When on org timestamp item insert org timestamp item with current time.
This holds only for inactive timestamps."
  (when (save-excursion
          (let ((item-pos (org-in-item-p)))
            (when item-pos
              (goto-char item-pos)
              (org-list-at-regexp-after-bullet-p org-ts-regexp-inactive))))
    (let ((item-pos (org-in-item-p))
          (pos (point)))
      (assert item-pos)
      (goto-char item-pos)
      (let* ((struct (org-list-struct))
	     (prevs (org-list-prevs-alist struct))
	     (s (concat (with-temp-buffer
                          (org-insert-time-stamp nil t t)
                          (buffer-string)) " ")))
        (setq struct (org-list-insert-item pos struct prevs nil s))
        (org-list-write-struct struct (org-list-parents-alist struct))
        (looking-at org-list-full-item-re)
	(goto-char (match-end 0))
        (end-of-line)))
    t))

(add-hook
'org-metareturn-hook 'mw-org-insert-item-with-ina-ts-when-on-such-item)
#+end_src

The snippet can be found also at
https://gist.github.com/marcowahl/8b229ec0979e901d7d90a248c85e3ede .

As always, critique is welcome.


In the hope that this snippet is useful also for someone else,
                                                              Marco

             reply	other threads:[~2018-03-17  9:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-17  9:41 Marco Wahl [this message]
2018-03-17  9:55 ` Timestamped items with M-RET Nicolas Goaziou
2018-03-17 10:17   ` Marco Wahl

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=84zi37f38m.fsf@gmail.com \
    --to=marcowahlsoft@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).