Commit 81606b10 authored by Rüdiger Sonderfeld's avatar Rüdiger Sonderfeld Committed by Eli Zaretskii

Support filesystem notification through inotify on GNU/Linux. (inotify): New option.
 (HAVE_INOTIFY): Test for inotify.

 src/termhooks.h (enum event_kind) [HAVE_INOTIFY]: Add
 src/lisp.h (syms_of_inotify) [HAVE_INOTIFY]: Add prototype.
 src/keyboard.c (Qfile_inotify) [HAVE_INOTIFY]: New variable.
 (syms_of_keyboard): DEFSYM it.
 (kbd_buffer_get_event) [HAVE_INOTIFY]: Generate FILE_NOTIFY_EVENT.
 (make_lispy_event): Support FILE_NOTIFY_EVENT by generating
 Qfile_inotify events.
 (keys_of_keyboard) [HAVE_INOTIFY]: Bind file-inotify events in
 special-event-map to inotify-handle-event.
 src/emacs.c (main) [HAVE_INOTIFY]: Call syms_of_inotify.
 src/ (base_obj): Add inotify.o.
 src/inotify.c: New file.

 lisp/subr.el (inotify-event-p, inotify-handle-event): New functions.

 test/automated/inotify-test.el: New test.
parent 265c2fbf
2012-12-10 Rüdiger Sonderfeld <>
* (inotify): New option.
(HAVE_INOTIFY): Test for inotify.
2012-12-09 Andreas Schwab <>
* Fix source command in .gdbinit.
......@@ -185,6 +185,7 @@ OPTION_DEFAULT_ON([gconf],[don't compile with GConf support])
OPTION_DEFAULT_ON([gsettings],[don't compile with GSettings support])
OPTION_DEFAULT_ON([selinux],[don't compile with SELinux support])
OPTION_DEFAULT_ON([gnutls],[don't use -lgnutls for SSL/TLS support])
OPTION_DEFAULT_ON([inotify],[don't compile with inotify (file-watch) support])
## For the times when you want to build Emacs but don't have
## a suitable makeinfo, and can live without the manuals.
......@@ -2175,6 +2176,18 @@ fi
dnl inotify is only available on GNU/Linux.
if test "${with_inotify}" = "yes"; then
if test "$ac_cv_header_sys_inotify_h" = yes ; then
AC_CHECK_FUNCS(inotify_init1 inotify_add_watch inotify_rm_watch, HAVE_INOTIFY=yes)
if test "${HAVE_INOTIFY}" = "yes"; then
AC_DEFINE(HAVE_INOTIFY, [1], [Define to 1 to use inotify])
dnl Do not put whitespace before the #include statements below.
dnl Older compilers (eg sunos4 cc) choke on it.
......@@ -133,6 +133,11 @@ spurious warnings about an unused var.
* Lisp changes in Emacs 24.4
** Support for filesystem notifications.
Emacs now supports notifications of filesystem changes, such as
creation, modification, and deletion of files. This requires the
'inotify' API on GNU/Linux systems.
** Face changes
*** The `face-spec-set' is now analogous to `setq' for face specs.
2012-12-10 Rüdiger Sonderfeld <>
* subr.el (inotify-event-p, inotify-handle-event): New functions.
2012-12-10 Dani Moncayo <>
* simple.el (just-one-space): Doc fix.
......@@ -4322,6 +4322,26 @@ convenience wrapper around `make-progress-reporter' and friends.
(progress-reporter-done ,temp2)
nil ,@(cdr (cdr spec)))))
;;;; Support for watching filesystem events.
(defun inotify-event-p (event)
"Check if EVENT is an inotify event."
(and (listp event)
(>= (length event) 3)
(eq (car event) 'file-inotify)))
(defun inotify-handle-event (event)
"Handle file system monitoring event.
If EVENT is a filewatch event then the callback is called. If EVENT is
not a filewatch event then a `filewatch-error' is signaled."
(interactive "e")
(unless (inotify-event-p event)
(signal 'filewatch-error (cons "Not a valid inotify event" event)))
(funcall (nth 2 event) (nth 1 event)))
;;;; Comparing version strings.
2012-12-10 Rüdiger Sonderfeld <>
* termhooks.h (enum event_kind) [HAVE_INOTIFY]: Add
* lisp.h (syms_of_inotify) [HAVE_INOTIFY]: Add prototype.
* keyboard.c (Qfile_inotify) [HAVE_INOTIFY]: New variable.
(syms_of_keyboard): DEFSYM it.
(kbd_buffer_get_event) [HAVE_INOTIFY]: Generate FILE_NOTIFY_EVENT.
(make_lispy_event): Support FILE_NOTIFY_EVENT by generating
Qfile_inotify events.
(keys_of_keyboard) [HAVE_INOTIFY]: Bind file-inotify events in
special-event-map to inotify-handle-event.
* emacs.c (main) [HAVE_INOTIFY]: Call syms_of_inotify.
* (base_obj): Add inotify.o.
* inotify.c: New file.
2012-12-10 Jan Djärv <>
* nsterm.m (fd_handler:): FD_ZERO fds (Bug#13103).
......@@ -344,7 +344,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
syntax.o $(UNEXEC_OBJ) bytecode.o \
process.o gnutls.o callproc.o \
region-cache.o sound.o atimer.o \
doprnt.o intervals.o textprop.o composite.o xml.o \
doprnt.o intervals.o textprop.o composite.o xml.o inotify.o \
profiler.o \
......@@ -1442,6 +1442,10 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
syms_of_gnutls ();
syms_of_inotify ();
#endif /* HAVE_INOTIFY */
#ifdef HAVE_DBUS
syms_of_dbusbind ();
#endif /* HAVE_DBUS */
This diff is collapsed.
......@@ -319,6 +319,9 @@ static Lisp_Object Qsave_session;
#ifdef HAVE_DBUS
static Lisp_Object Qdbus_event;
static Lisp_Object Qfile_inotify;
#endif /* HAVE_INOTIFY */
static Lisp_Object Qconfig_changed_event;
/* Lisp_Object Qmouse_movement; - also an event header */
......@@ -3960,6 +3963,13 @@ kbd_buffer_get_event (KBOARD **kbp,
obj = make_lispy_event (event);
kbd_fetch_ptr = event + 1;
else if (event->kind == FILE_NOTIFY_EVENT)
obj = make_lispy_event (event);
kbd_fetch_ptr = event + 1;
else if (event->kind == CONFIG_CHANGED_EVENT)
......@@ -5874,6 +5884,13 @@ make_lispy_event (struct input_event *event)
#endif /* HAVE_DBUS */
return Fcons (Qfile_inotify, event->arg);
#endif /* HAVE_INOTIFY */
return Fcons (Qconfig_changed_event,
Fcons (event->arg,
......@@ -11337,6 +11354,10 @@ syms_of_keyboard (void)
DEFSYM (Qdbus_event, "dbus-event");
DEFSYM (Qfile_inotify, "file-inotify");
#endif /* HAVE_INOTIFY */
DEFSYM (QCenable, ":enable");
DEFSYM (QCvisible, ":visible");
DEFSYM (QChelp, ":help");
......@@ -12093,6 +12114,13 @@ keys_of_keyboard (void)
/* Define a special event which is raised for inotify callback
functions. */
initial_define_lispy_key (Vspecial_event_map, "file-inotify",
#endif /* HAVE_INOTIFY */
initial_define_lispy_key (Vspecial_event_map, "config-changed-event",
#if defined (WINDOWSNT)
......@@ -3516,6 +3516,11 @@ extern void syms_of_fontset (void);
extern Lisp_Object Qfont_param;
/* Defined in inotify.c */
extern void syms_of_inotify (void);
/* Defined in xfaces.c. */
extern Lisp_Object Qdefault, Qtool_bar, Qfringe;
extern Lisp_Object Qheader_line, Qscroll_bar, Qcursor;
......@@ -211,6 +211,11 @@ enum event_kind
/* File or directory was changed. */
/* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
2012-12-10 Rüdiger Sonderfeld <>
* automated/inotify-test.el: New test.
2012-12-02 Chong Yidong <>
* automated/ruby-mode-tests.el
;;; inotify-tests.el --- Test suite for inotify. -*- lexical-binding: t -*-
;; Copyright (C) 2012 Free Software Foundation, Inc.
;; Author: Rüdiger Sonderfeld <>
;; Keywords: internal
;; Human-Keywords: internal
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <>.
;;; Code:
(require 'ert)
(when (featurep 'inotify)
;; (ert-deftest filewatch-file-watch-aspects-check ()
;; "Test whether `file-watch' properly checks the aspects."
;; (let ((temp-file (make-temp-file "filewatch-aspects")))
;; (should (stringp temp-file))
;; (should-error (file-watch temp-file 'wrong nil)
;; :type 'error)
;; (should-error (file-watch temp-file '(modify t) nil)
;; :type 'error)
;; (should-error (file-watch temp-file '(modify all-modify) nil)
;; :type 'error)
;; (should-error (file-watch temp-file '(access wrong modify) nil)
;; :type 'error)))
(ert-deftest inotify-file-watch-simple ()
"Test if watching a normal file works."
(let ((temp-file (make-temp-file "inotify-simple"))
(events 0))
(let ((wd
(inotify-add-watch temp-file t (lambda (ev)
(setq events (1+ events))))))
(with-temp-file temp-file
(insert "Foo\n"))
(sit-for 5) ;; Hacky. Wait for 5s until events are processed
(should (> events 0)))
(inotify-rm-watch wd)))))
(provide 'inotify-tests)
;;; inotify-tests.el ends here.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment