1

I use about 15 orgmode agenda files, and a number of them I use passively only. Examples are my wife's agenda converted from Google calendar, a work agenda from Outlook and a list of git commits (which gives you the idea that you actually did do something today). All are periodically updated outside emacs, usually by a cron job.

My problem is that reloading my agenda view does not (always) seem to reload these files, and often the only way to find this out is to try and edit an entry, at which point emacs will indicate that the file was changed and can be reverted. The file is then reloaded by emacs, and pressing 'r' in the agenda view gives the updated entries.

Is there a way to have emacs regularly (e.g. every hour) reload selected agenda files, so that the info in my agenda is uptodate? Alternatively, doing such a reload when pressing 'r' would be fine too.

AstroFloyd
  • 409
  • 3
  • 11

4 Answers4

3

you could use a local variable in your org files this way:

# Local Variables:
# eval: (auto-revert-mode)
# End:

Just append those lines at the end of each generated file. It'll work next time you open them. That should take care of those passive files.

Muihlinn
  • 2,576
  • 1
  • 14
  • 22
  • Nice, thanks, I'll have a look at this. Of course, the lines need to be added in the conversion script, otherwise they'd be overwritten at the next sync. – AstroFloyd Oct 20 '19 at 09:05
1

See: https://www.gnu.org/software/emacs/manual/html_node/elisp/Idle-Timers.html

To see the mandatory and optional arguments to functions such as run-with-timer and revert-buffer, type C-h f (aka M-x describe-function).

How about something like this?

(run-with-timer 0 (* 60 60)
  (mapc (lambda (buffer)
          (with-current-buffer buffer
            (when (eq major-mode 'org-mode)
              (revert-buffer nil 'noconfirm))))
        (buffer-list)))

In terms of selected files, rather than all org-mode files, feel free to use a custom list of file-visiting-buffers (instead of the buffer-list), or modify the test (eq major-mode 'org-mode) to include additional criteria such as (equal (buffer-name buffer) "NAME") or (member (buffer-name buffer) '("foo" "bar "baz")).

lawlist
  • 18,826
  • 5
  • 37
  • 118
  • Thank you! Since I only have a couple of files, could I replace `(buffer-list)` with something like `'("foo.org" "bar.org "baz.org")` (is this the correct syntax?) and remove the `when()` test? – AstroFloyd Oct 20 '19 at 09:13
  • This answer contains a `mapc` looping function that expects a buffer Lisp object for each element that is mapped from the `buffer-list`. "foo.org" is a buffer-name, which is a string (rather than a buffer Lisp object). The function `get-file-buffer` can be used to locate a buffer and, if found, will return a buffer Lisp object. Thus, you may also wish to use something that filters out any `nil` entries in the list in the event that a buffer is not found:: `(delq nil '((get-file-buffer "foo.org") (get-file-buffer "bar.org") (get-file-buffer "baz.org")))` – lawlist Oct 20 '19 at 16:40
0

I ended up using this answer, since emacs seems to revert the changed files within (a) second(s). I don't get the impression that there is much overhead from the fact that there are more files in my orgmode directory that the targeted ones. So "my" solution is a file called .dir-locals.el in my orgmode dir which contains the single line (I kept the nil)

((nil . ((eval . (auto-revert-mode 1)))))

AstroFloyd
  • 409
  • 3
  • 11
0

The simplest way is to add an org-mode-hook:

(add-hook 'org-mode-hook
          '(lambda ()
             (auto-revert-mode 1)))