emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Pedro <pedro@cas.cat>
To: emacs-orgmode@gnu.org
Subject: Re: insert a header and automatically a timestamp with date/time
Date: Sat, 1 Feb 2025 22:04:41 +0100	[thread overview]
Message-ID: <0ffad4d4-45de-46ad-a95d-66fb20d97c46@cas.cat> (raw)
In-Reply-To: <87wme94l3k.fsf@mat.ucm.es>


[-- Attachment #1.1.1.1: Type: text/plain, Size: 2429 bytes --]




On 2025-02-01 18:43, Uwe Brauer via General discussions about Org-mode. 
wrote:
> (BTW do you speak Spanish , since there is some Spanish text in the
> files that are attached)
>
> Anyhow.
>
> Let me see if I understand that correctly
>
>      - Your code does not insert
> * <2025-02-01>
>      But instead
> * Some heading
> :PROPERTIES:
> :CREATED:  [2023-11-17 Fri 19:32]
> :END:
>     that is also ok, but for the moment I prefer the timestamp in the
>     heading, because if I use outline-hide-body I obtain a nice overview
>     with the dates.
>
>
>      - Another problem is that I don't get your code to work for example
>        the one in the file  auto-insert-created-timestamp-as-property.org
>        gives me

Yes, I speak Spanish :)

To generate dates as you said, you can use the following code [0], on 
~man date~ you can find other strftime format constructions, or 
alternatively, visit this [1]

The scheduled thing [2] had an if for certain conditions where you want 
that hook to get triggered (that uses specific buffer names that in my 
case are [2]), for a more simple approach, you might want to experiment 
with a simpler function [3]

I attach again the script migrate-from-ts-header-to-created-property.org 
because I got confused; I hope "soon" I could have a git public repo 
with my emacs config

[0]
#+begin_src emacs-lisp
(defun my/org-add-timestamp-on-heading ()
   (save-excursion
     (org-back-to-heading)
     (org-edit-headline (format-time-string "<%F>"))
     (my/set-property-with-inactive-timestamp "CREATED")))

(add-hook 'org-insert-heading-hook 'my/org-add-timestamp-on-heading 'append)
;; to remove it
;; (remove-hook 'org-insert-heading-hook 'my/org-add-timestamp-on-heading)
#+end_src

[1] https://strftime.org/

[2]

#+begin_src emacs-lisp
(setq my/diary-file "1activity.org")
(setq my/board-file "board.org")
(setq my/proj-file "projects.org")
(setq my/proj-candidates-file "projects-candidates.org")
#+end_src

[3]
#+begin_src emacs-lisp
(defun my/org-heading-insert-scheduled ()
   (save-excursion
     ;; src 
https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
     (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

[-- Attachment #1.1.1.2: Type: text/html, Size: 3347 bytes --]

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

**** script: migrate from old heading format
:PROPERTIES:
:CREATED:  [2023-07-24 Mon 03:38]
:CUSTOM_ID: emacsconf_51
:END:

#+name: created on [2023-07-24 Mon 03:38:47]
#+begin_src emacs-lisp
(defun my/migrate-legacy-created-format ()
  (interactive)
  (org-map-entries
   (lambda ()
     (let* ((title (org-entry-get nil "ITEM"))
            (regexp "^\\(.*\\) <\\(20.*\\)>")
            (current-created (org-entry-get (point) "CREATED")))
       (when (string-match regexp title)
         (let ((new-title (match-string 1 title))
               (new-created (match-string 2 title)))
           (if current-created
               (message "Warning: \"%s\" not added as created property" title)
             (progn
               ;; move match to CREATED property
               (org-entry-put (point) "CREATED" (format "[%s]" new-created))
               ;; delete heading text
               (org-edit-headline new-title)))))))
   nil 'file))
#+end_src

[-- Attachment #1.1.3: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3323 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  reply	other threads:[~2025-02-01 21:05 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.
2025-02-01 17:43   ` Uwe Brauer via General discussions about Org-mode.
2025-02-01 21:04     ` Pedro [this message]
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=0ffad4d4-45de-46ad-a95d-66fb20d97c46@cas.cat \
    --to=pedro@cas.cat \
    --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).