diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2015-09-23 20:34:22 +0200 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2015-09-23 20:34:22 +0200 |
commit | cad8aef3241efa0873fb0c003b563cf31a4c0f2e (patch) | |
tree | 1649ac34fcef3f59900b6860360460d230e3f7b6 /src/gfilenotify.c | |
parent | 4c0fed13e5ca1826bab52cd9c3fc31ad0e5c765c (diff) | |
download | emacs-cad8aef3241efa0873fb0c003b563cf31a4c0f2e.tar.gz |
Continue gfilenotify.c implementation of missing parts
* lisp/filenotify.el (file-notify-add-watch): Append `flags' to
`gfile-add-watch' call.
(file-notify-rm-watch): Modify `file-notify-descriptors' only
after calling the low level functions.
* src/gfilenotify.c (dir_monitor_callback): Check, whether
event_type is expected.
(Fgfile_add_watch): Allow also `change'and `attribute-change' for FLAGS.
(Fgfile_rm_watch): Fix typo.
(syms_of_gfilenotify): Declare Qchange and Qattribute_change.
Diffstat (limited to 'src/gfilenotify.c')
-rw-r--r-- | src/gfilenotify.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/src/gfilenotify.c b/src/gfilenotify.c index 1439666f5f8..b5baa30d7a4 100644 --- a/src/gfilenotify.c +++ b/src/gfilenotify.c @@ -29,7 +29,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include "process.h" -/* This is a list, elements are triples (DESCRIPTOR FILE CALLBACK) */ +/* This is a list, elements are triples (DESCRIPTOR FILE FLAGS CALLBACK) */ static Lisp_Object watch_list; /* This is the callback function for arriving signals from @@ -42,7 +42,7 @@ dir_monitor_callback (GFileMonitor *monitor, GFileMonitorEvent event_type, gpointer user_data) { - Lisp_Object symbol, monitor_object, watch_object; + Lisp_Object symbol, monitor_object, watch_object, flags; char *name = g_file_get_parse_name (file); char *oname = other_file ? g_file_get_parse_name (other_file) : NULL; @@ -84,26 +84,35 @@ dir_monitor_callback (GFileMonitor *monitor, if (CONSP (watch_object)) { - /* Construct an event. */ struct input_event event; Lisp_Object otail = oname ? list1 (build_string (oname)) : Qnil; - EVENT_INIT (event); - event.kind = FILE_NOTIFY_EVENT; - event.frame_or_window = Qnil; - event.arg = list2 (Fcons (monitor_object, - Fcons (symbol, - Fcons (build_string (name), - otail))), - XCAR (XCDR (XCDR (watch_object)))); - - /* Store it into the input event queue. */ - kbd_buffer_store_event (&event); + + /* Check, whether event_type is expected. */ + flags = XCAR (XCDR (XCDR (watch_object))); + if ((!NILP (Fmember (Qchange, flags)) && + !NILP (Fmember (symbol, list5 (Qchanged, Qchanges_done_hint, + Qdeleted, Qcreated, Qmoved)))) || + (!NILP (Fmember (Qattribute_change, flags)) && + ((EQ (symbol, Qattribute_changed))))) + { + /* Construct an event. */ + EVENT_INIT (event); + event.kind = FILE_NOTIFY_EVENT; + event.frame_or_window = Qnil; + event.arg = list2 (Fcons (monitor_object, + Fcons (symbol, + Fcons (build_string (name), + otail))), + XCAR (XCDR (XCDR (XCDR (watch_object))))); + + /* Store it into the input event queue. */ + kbd_buffer_store_event (&event); + // XD_DEBUG_MESSAGE ("%s", XD_OBJECT_TO_STRING (event.arg)); + } /* Cancel monitor if file or directory is deleted. */ - if (((event_type == G_FILE_MONITOR_EVENT_DELETED) || - (event_type == G_FILE_MONITOR_EVENT_MOVED)) && - (strcmp (name, SSDATA (XCAR (XCDR (watch_object)))) == 0) && - (!g_file_monitor_is_cancelled (monitor))) + if (!NILP (Fmember (symbol, list2 (Qdeleted, Qmoved))) && + !g_file_monitor_is_cancelled (monitor)) g_file_monitor_cancel (monitor); } @@ -127,9 +136,13 @@ watched for some reason, this function signals a `file-notify-error' error. FLAGS is a list of conditions to set what will be watched for. It can include the following symbols: - `watch-mounts' -- watch for mount events - `send-moved' -- pair `deleted' and `created' events caused by file - renames and send a single `renamed' event instead + `change' -- watch for file changes + `attribute-change' -- watch for file attributes changes, like + permissions or modification time + `watch-mounts' -- watch for mount events + `send-moved' -- pair `deleted' and `created' events caused by + file renames and send a single `renamed' event + instead When any event happens, Emacs will call the CALLBACK function passing it a single argument EVENT, which is of the form @@ -206,13 +219,13 @@ will be reported only in case of the `moved' event. */) (GCallback) dir_monitor_callback, NULL); /* Store watch object in watch list. */ - watch_object = list3 (watch_descriptor, file, callback); + watch_object = list4 (watch_descriptor, file, flags, callback); watch_list = Fcons (watch_object, watch_list); return watch_descriptor; } -DEFUN ("gfile-rm-watc", Fgfile_rm_watch, Sgfile_rm_watch, 1, 1, 0, +DEFUN ("gfile-rm-watch", Fgfile_rm_watch, Sgfile_rm_watch, 1, 1, 0, doc: /* Remove an existing WATCH-DESCRIPTOR. WATCH-DESCRIPTOR should be an object returned by `gfile-add-watch'. */) @@ -279,6 +292,8 @@ syms_of_gfilenotify (void) defsubr (&Sgfile_valid_p); /* Filter objects. */ + DEFSYM (Qchange, "change"); + DEFSYM (Qattribute_change, "attribute-change"); DEFSYM (Qwatch_mounts, "watch-mounts"); /* G_FILE_MONITOR_WATCH_MOUNTS */ DEFSYM (Qsend_moved, "send-moved"); /* G_FILE_MONITOR_SEND_MOVED */ |