emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jorge Morais Neto <jorge13515@gmail.com>
To: Tim Visher <tim.visher@gmail.com>
Cc: org mode <emacs-orgmode@gnu.org>
Subject: Re: Automatic mtime and ctime on all or select group of trees?
Date: Sat, 2 Sep 2017 20:18:02 -0300	[thread overview]
Message-ID: <CAJR3QndF2+DEzv90yBc-UKOvyk9fNJwqZi0O3FW=Zt76aUc15g@mail.gmail.com> (raw)
In-Reply-To: <CAHa53uzdnFjuXwXKCDxjxuZXzTELoWVbm=QPoW46zuy1=fTXow@mail.gmail.com>

On 31 August 2017 at 08:55, Tim Visher <tim.visher@gmail.com> wrote:
> I would like to track the time I created a tree and the last time it was
> edited, like ctime and mtime on a filesystem. Is that possible to have
> happen automatically?

To insert a creation timestamp I use org-expiry.  I have added ~(require
'org-expiry)~ to my Org Mode setup file.  I could then have enabled
automatic CREATED property insertion by adding ~(org-expiry-insinuate)~.
However, that would make Org insert CREATED not only on heading
creation, but also whenever I performed certain actions – such as
scheduling or deadlining – on headings that lacked CREATED.  I do not
want that.  I want CREATED to reflect the actual creation time.  Old
headlines (from before I enabled org-expiry) are better off without
CREATED than with an inaccurate CREATED timestamp.  Also, I want to be
able to disable on certain files the automatic CREATED insertion.  So
instead of ~(org-expiry-insinuate)~, I added this:

;; HACK?
(defcustom J-insert-created t
  "Whether to automatically add CREATED property (org-expiry) on
heading creation"
  :type 'boolean :safe #'booleanp)

(defun J-insert-created ()
  (when J-insert-created
    (org-expiry-insert-created)))

(add-hook 'org-insert-heading-hook #'J-insert-created)

(add-hook 'org-capture-prepare-finalize-hook
          (lambda () (org-map-entries #'org-expiry-insert-created)))

So the CREATED timestamp is always added on capture, and also added on
headline creation except for manually typed headings and buffers where
option ~J-insert-created~ is nil.  I created that option as an option
(instead of a simple variable) so it could be file-local.  This works,
but I'm not sure it's correct and elegant.  I know little Elisp and very
little about defining Emacs options.  Suggestions welcome.  It currently
gives compile warnings, which I ignore for now:

    J-org.el:18:1:Warning: defcustom for ‘J-insert-created’ fails to specify
        containing group

Org-expiry can also add an EXPIRY property, so it can expire entries
after they become irrelevant with time.  And for entries without EXPIRY,
it can use a (customizable) default time span.  It is documented via
comments on ~org-expiry.el~.  That file comes with org-plus-contrib.

I also customized the following options:
- org-expiry-handler-function
- org-expiry-inactive-timestamps
- org-expiry-wait

Beware that org-expiry interacts badly with the
~org-clone-subtree-with-time-shift~ command.  It messes with org-expiry
timestamps on the clones.  For example, if the original entry is:

    * Meeting
    :PROPERTIES:
    :CREATED:  [2017-09-02 Sáb 20:10]
    :EXPIRY:   [2017-12-31]
    :END:
    <2017-09-04 Seg 10:00-11:00>

and one invokes ~org-clone-subtree-with-time-shift~, asking for one
clone and a ~+1w~ shift, the clone will be:

    * Meeting
    :PROPERTIES:
    :CREATED:  [2017-09-09 Sáb 20:10]
    :EXPIRY:   [2018-01-07 Dom]
    :END:
    <2017-09-11 Seg 10:00-11:00>

which is clearly wrong.

Regards

-- 
- I am Brazilian.  I hope my English is correct and I welcome feedback
- Please adopt free formats like PDF, ODF, Org, LaTeX, Opus, WebM and 7z
- Free (as in free speech) software for Android: https://f-droid.org/

  parent reply	other threads:[~2017-09-02 23:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 11:55 Automatic mtime and ctime on all or select group of trees? Tim Visher
2017-08-31 13:44 ` Eric S Fraga
2017-08-31 14:20   ` Tim Visher
2017-09-01  9:57     ` Eric S Fraga
2017-09-02  1:09       ` Adam Porter
2017-09-02 23:18 ` Jorge Morais Neto [this message]
2017-09-03  1:10   ` Adam Porter
2017-09-05 16:47     ` Jorge Morais Neto
2017-09-07  1:38       ` Adam Porter
2017-09-02 23:34 ` Samuel Wales
2017-09-03  1:06   ` Adam Porter

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='CAJR3QndF2+DEzv90yBc-UKOvyk9fNJwqZi0O3FW=Zt76aUc15g@mail.gmail.com' \
    --to=jorge13515@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tim.visher@gmail.com \
    /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).