emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Timestamped items with M-RET
@ 2018-03-17  9:41 Marco Wahl
  2018-03-17  9:55 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Wahl @ 2018-03-17  9:41 UTC (permalink / raw)
  To: emacs-orgmode

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

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

end of thread, other threads:[~2018-03-17 10:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-17  9:41 Timestamped items with M-RET Marco Wahl
2018-03-17  9:55 ` Nicolas Goaziou
2018-03-17 10:17   ` Marco Wahl

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