emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Automatic mtime and ctime on all or select group of trees?


From: Jorge Morais Neto
Subject: Re: [O] Automatic mtime and ctime on all or select group of trees?
Date: Sat, 2 Sep 2017 20:18:02 -0300

On 31 August 2017 at 08:55, Tim Visher <address@hidden> 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/



reply via email to

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