emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Timestamped items with M-RET


From: Marco Wahl
Subject: [O] Timestamped items with M-RET
Date: Sat, 17 Mar 2018 10:41:45 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]