emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: pinmacs via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
To: emacs-orgmode@gnu.org
Subject: Re: insert a header and automatically a timestamp with date/time
Date: Sat, 1 Feb 2025 12:11:38 +0100	[thread overview]
Message-ID: <f37eb816-3b89-4d3e-b2d8-bab16721928f@cas.cat> (raw)
In-Reply-To: <87seoy3xqg.fsf@mat.ucm.es>


[-- Attachment #1.1: Type: text/plain, Size: 2366 bytes --]

On 2025-02-01 08:55, Uwe Brauer via General discussions about Org-mode. 
wrote:
> Is there any way to insert a header and automatically a timestamp with
> date/time?
>
> I can write me a small function doing this and bind it to some unused
> key, but is there a more general/elegant way I just miss?

Hi Uwe,

TL DR; I add the timestamp automatically on entry creation as a hook 
[2], in fact, I have several hooks on entry creation and I think is a 
good way to handle this. I am happy with my setup since I started using 
it in 2023.

Let me share my experience on that topic (and very happy to hear other 
experiences and/or feedback), I hope the offtopic inside is welcome and 
useful:

1. Before, I was manually adding timestamp headers as a postfix for the 
creation of the header (and this is how I reverted using this script per 
target buffer [1]) to transform to CREATED properties (see here the 
automation on how I add the timestamp automatically on entry creation 
[2]), which I think are even better, specially, because then you can add 
that column to your table-reports such as clocktable, org-ql, propview, 
custom org-map-entries stuff.
2. After, as a prefix, in the journal files, for facilitating 
alphanumeric sorting of items in my customized journal (with a structure 
of year > week > day). I finally got rid of that, and brain and eyes 
appreciated that movement, it is too much noise to see a lot of items 
with timestamp. I discovered that problem when I started using 
variable-pitch mode, which with modes themes works very nice with 
(enable variable: (setq modus-themes-mixed-fonts t) ). Then, 
alternatively, sorting can be done by adding "SCHEDULED" to all items 
created on certain buffers and levels [3], which I also add for certain 
org-agenda files (then I use schedule as a poor's man alternative to 
anki [4] for space repetition [5], which could of course involve real 
tasks and projects apart from the typical usecase of memorizing concepts).

I do it this way and it works fine for me since that date I use it:

Cheers,
pinmacs



[1] see attached file: migrate-from-ts-header-to-created-property.org

[2] see attached file: auto-insert-created-timestamp-as-property.org

[3] see attached file: autoadd-scheduled-entry

[4] https://en.wikipedia.org/wiki/Anki_(software)

[5] https://en.wikipedia.org/wiki/Spaced_repetition

[-- Attachment #1.2: Type: text/html, Size: 3154 bytes --]

[-- Attachment #2: auto-insert-created-timestamp-as-property.org --]
[-- Type: text/org, Size: 930 bytes --]

** org-insert-heading-hook(s) (7)
:PROPERTIES:
:CREATED:  [2023-04-29 Sat 16:04]
:CUSTOM_ID: 2023-04-29_16:04:47.146113
:END:

*** 1. always add CREATED property
:PROPERTIES:
:CREATED:  [2023-04-29 Sat 16:05]
:CUSTOM_ID: 2023-04-29_16:05:16.930966
:END:

#+name: created on [2023-04-29 Sat 16:06:09]
#+begin_src emacs-lisp
(defun my/org-heading-insert-heading-inactive-timestamp ()
  (save-excursion
    ;; src https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
    (org-back-to-heading)
    (my/set-property-with-inactive-timestamp "CREATED")))

;; src https://emacs-orgmode.gnu.narkive.com/xdMIn5QZ/o-how-can-i-calculate-the-age-of-a-headline
;; extra src https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
(add-hook 'org-insert-heading-hook 'my/org-heading-insert-heading-inactive-timestamp 'append)
#+end_src


[-- Attachment #3: migrate-from-ts-header-to-created-property.org --]
[-- Type: text/org, Size: 929 bytes --]

** org-insert-heading-hook(s) (7)
:PROPERTIES:
:CREATED:  [2023-04-29 Sat 16:04]
:CUSTOM_ID: 2023-04-29_16:04:47.146113
:END:

*** 1. always add CREATED property
:PROPERTIES:
:CREATED:  [2023-04-29 Sat 16:05]
:CUSTOM_ID: 2023-04-29_16:05:16.930966
:END:

#+name: created on [2023-04-29 Sat 16:06:09]
#+begin_src emacs-lisp
(defun my/org-heading-insert-heading-inactive-timestamp ()
  (save-excursion
    ;; src https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
    (org-back-to-heading)
    (my/set-property-with-inactive-timestamp "CREATED")))

;; src https://emacs-orgmode.gnu.narkive.com/xdMIn5QZ/o-how-can-i-calculate-the-age-of-a-headline
;; extra src https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
(add-hook 'org-insert-heading-hook 'my/org-heading-insert-heading-inactive-timestamp 'append)
#+end_src

[-- Attachment #4: autoadd-scheduled-entry.org --]
[-- Type: text/org, Size: 1339 bytes --]

*** 4. always add SCHEDULED when in journal and project files
:PROPERTIES:
:CREATED:  [2023-11-17 Fri 19:32]
:CUSTOM_ID: emacsconf_61
:END:
:BACKLINKS:
[2024-01-12 Fri 09:20] <- [[file:~/org/1activity.org::#1activity_3774][org agenda cleanup/puesta a punto, y vaciado de notas de móvil]]
:END:

#+name: created on [2023-11-17 Fri 19:33:09]
#+begin_src emacs-lisp
(defun my/org-heading-insert-scheduled ()
  (if (or
       (and (string-match-p my/diary-file (buffer-name))
            (= (org-current-level) 4))
       (and (string-match-p my/board-file (buffer-name))
            (= (org-current-level) 4))
       (and (string-match-p my/proj-file (buffer-name))
            ;; projects are 3-level (tasks start at 5-level, we don't care on its children)
            (> (org-current-level) 4))
       (and (string-match-p my/proj-candidates-file (buffer-name))
            ;; projects are 4-level (tasks start at 3-level, we don't care on its children)
            (> (org-current-level) 3))
       )
      (save-excursion
        ;; src https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
        ;;(org-back-to-heading)
        (org-schedule nil (format-time-string "[%Y-%m-%d %a]" nil)))))

(add-hook 'org-insert-heading-hook 'my/org-heading-insert-scheduled 'append)
#+end_src

  reply	other threads:[~2025-02-01 11:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-01  7:55 insert a header and automatically a timestamp with date/time Uwe Brauer via General discussions about Org-mode.
2025-02-01 11:11 ` pinmacs via General discussions about Org-mode. [this message]
2025-02-01 17:43   ` Uwe Brauer via General discussions about Org-mode.
2025-02-01 21:04     ` Pedro
2025-02-02  7:38       ` Uwe Brauer via General discussions about Org-mode.
2025-02-02 12:03         ` pinmacs
2025-02-02 20:02           ` Uwe Brauer via General discussions about Org-mode.
2025-02-02 20:47             ` pinmacs
2025-02-03 18:07               ` Uwe Brauer via General discussions about Org-mode.

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=f37eb816-3b89-4d3e-b2d8-bab16721928f@cas.cat \
    --to=emacs-orgmode@gnu.org \
    --cc=pinmacs@cas.cat \
    /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).