tags:

views:

83

answers:

2

I'm looking for a way to check periodically if a files under a certain directory were changed from the last check (a functionality symilar to FAM daemon or to gio.monitor_directory). In emacs lisp.

  • Are there any library/snippet that provide this functionality?
  • If not, how can I implement such a function?
+2  A: 

I don't have a proper solution but maybe a couple of pointer to get you on the right direction.

According to some quick googling it seems that dbus has an inotify interface built-ins. Since latest version of emacs you can access to dbus interface via Emacs lisp (under Linux at least) maybe you can plug all of this together to make it works. See an example here about using dbus with Emacs :

http://emacs-fu.blogspot.com/2009/01/using-d-bus-example.html

Chmouel Boudjnah
+2  A: 
(defun install-monitor (file secs)
  (run-with-timer
   0 secs
   (lambda (f p)
     (unless (< p (second (time-since (elt (file-attributes f) 5))))
       (message "File %s changed!" f)))
   file secs))

(defvar monitor-timer (install-monitor "/tmp" 5)
  "Check if /tmp is changed every 5s.")

To cancel,

(cancel-timer monitor-timer)
huaiyuan