aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichael Albinus2015-10-26 16:46:48 +0100
committerMichael Albinus2015-10-26 16:46:48 +0100
commit0d9c67236cab3ffe9a8f1276e93a32e437c09bfc (patch)
treecb63c930538f2761c47aadaa49e5f099a1b330d2 /lisp
parent934bfb933f4981b2edaa208186e2f8781ab6cb9f (diff)
downloademacs-0d9c67236cab3ffe9a8f1276e93a32e437c09bfc.tar.gz
emacs-0d9c67236cab3ffe9a8f1276e93a32e437c09bfc.zip
Further work on `stopped' events in filenotify.el
* doc/lispref/os.texi (File Notifications): Rework examples. * lisp/filenotify.el (file-notify--rm-descriptor): Optional parameter. (file-notify--rm-descriptor, file-notify-callback): Improve check for sending `stopped' event. (file-notify-add-watch): Check for more events for `inotify'. * test/automated/file-notify-tests.el (file-notify--test-expected-events): New defvar. (file-notify--test-with-events): Use it. (file-notify--test-cleanup): Make it more robust when deleting directories. (file-notify--test-event-test): Check also for watched directories. (file-notify--test-event-handler): Suppress temporary .#files. (file-notify-test02-events, file-notify-test04-file-validity): Rework `stopped' events. (file-notify-test05-dir-validity): Wait for events when appropriate.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/filenotify.el44
1 files changed, 25 insertions, 19 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 55d9028f252..6a180a86570 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -48,32 +48,33 @@ The value in the hash table is a list
48Several values for a given DIR happen only for `inotify', when 48Several values for a given DIR happen only for `inotify', when
49different files from the same directory are watched.") 49different files from the same directory are watched.")
50 50
51(defun file-notify--rm-descriptor (descriptor) 51(defun file-notify--rm-descriptor (descriptor &optional what)
52 "Remove DESCRIPTOR from `file-notify-descriptors'. 52 "Remove DESCRIPTOR from `file-notify-descriptors'.
53DESCRIPTOR should be an object returned by `file-notify-add-watch'. 53DESCRIPTOR should be an object returned by `file-notify-add-watch'.
54If it is registered in `file-notify-descriptors', a stopped event is sent." 54If it is registered in `file-notify-descriptors', a stopped event is sent.
55WHAT is a file or directory name to be removed, needed just for `inotify'."
55 (let* ((desc (if (consp descriptor) (car descriptor) descriptor)) 56 (let* ((desc (if (consp descriptor) (car descriptor) descriptor))
56 (file (if (consp descriptor) (cdr descriptor))) 57 (file (if (consp descriptor) (cdr descriptor)))
57 (registered (gethash desc file-notify-descriptors)) 58 (registered (gethash desc file-notify-descriptors))
58 (dir (car registered))) 59 (dir (car registered)))
59 60
60 (when (consp registered) 61 (when (and (consp registered) (or (null what) (string-equal dir what)))
61 ;; Send `stopped' event. 62 ;; Send `stopped' event.
62 (dolist (entry (cdr registered)) 63 (dolist (entry (cdr registered))
63 (funcall (cdr entry) 64 (funcall (cdr entry)
64 `(,(file-notify--descriptor desc) stopped 65 `(,(file-notify--descriptor desc) stopped
65 ,(or (and (stringp (car entry)) 66 ,(or (and (stringp (car entry))
66 (expand-file-name (car entry) dir)) 67 (expand-file-name (car entry) dir))
67 dir)))) 68 dir))))
68 69
69 ;; Modify `file-notify-descriptors'. 70 ;; Modify `file-notify-descriptors'.
70 (if (not file) 71 (if (not file)
71 (remhash desc file-notify-descriptors) 72 (remhash desc file-notify-descriptors)
72 (setcdr registered 73 (setcdr registered
73 (delete (assoc file (cdr registered)) (cdr registered))) 74 (delete (assoc file (cdr registered)) (cdr registered)))
74 (if (null (cdr registered)) 75 (if (null (cdr registered))
75 (remhash desc file-notify-descriptors) 76 (remhash desc file-notify-descriptors)
76 (puthash desc registered file-notify-descriptors)))))) 77 (puthash desc registered file-notify-descriptors))))))
77 78
78;; This function is used by `gfilenotify', `inotify' and `w32notify' events. 79;; This function is used by `gfilenotify', `inotify' and `w32notify' events.
79;;;###autoload 80;;;###autoload
@@ -85,6 +86,7 @@ If EVENT is a filewatch event, call its callback. It has the format
85 86
86Otherwise, signal a `file-notify-error'." 87Otherwise, signal a `file-notify-error'."
87 (interactive "e") 88 (interactive "e")
89 ;;(message "file-notify-handle-event %S" event)
88 (if (and (eq (car event) 'file-notify) 90 (if (and (eq (car event) 'file-notify)
89 (>= (length event) 3)) 91 (>= (length event) 3))
90 (funcall (nth 2 event) (nth 1 event)) 92 (funcall (nth 2 event) (nth 1 event))
@@ -224,6 +226,7 @@ EVENT is the cadr of the event in `file-notify-handle-event'
224 (setq pending-event nil)) 226 (setq pending-event nil))
225 227
226 ;; Check for stopped. 228 ;; Check for stopped.
229 ;;(message "file-notify-callback %S %S" file registered)
227 (setq 230 (setq
228 stopped 231 stopped
229 (or 232 (or
@@ -232,7 +235,9 @@ EVENT is the cadr of the event in `file-notify-handle-event'
232 (memq action '(deleted renamed)) 235 (memq action '(deleted renamed))
233 (= (length (cdr registered)) 1) 236 (= (length (cdr registered)) 1)
234 (string-equal 237 (string-equal
235 (or (file-name-nondirectory file) "") (car (cadr registered)))))) 238 (file-name-nondirectory file)
239 (or (file-name-nondirectory (car registered))
240 (car (cadr registered)))))))
236 241
237 ;; Apply callback. 242 ;; Apply callback.
238 (when (and action 243 (when (and action
@@ -257,7 +262,7 @@ EVENT is the cadr of the event in `file-notify-handle-event'
257 262
258 ;; Modify `file-notify-descriptors'. 263 ;; Modify `file-notify-descriptors'.
259 (when stopped 264 (when stopped
260 (file-notify--rm-descriptor (file-notify--descriptor desc)))))) 265 (file-notify--rm-descriptor (file-notify--descriptor desc) file)))))
261 266
262;; `gfilenotify' and `w32notify' return a unique descriptor for every 267;; `gfilenotify' and `w32notify' return a unique descriptor for every
263;; `file-notify-add-watch', while `inotify' returns a unique 268;; `file-notify-add-watch', while `inotify' returns a unique
@@ -324,8 +329,8 @@ FILE is the name of the file whose event is being reported."
324 (setq desc (funcall 329 (setq desc (funcall
325 handler 'file-notify-add-watch dir flags callback)) 330 handler 'file-notify-add-watch dir flags callback))
326 331
327 ;; Check, whether Emacs has been compiled with file 332 ;; Check, whether Emacs has been compiled with file notification
328 ;; notification support. 333 ;; support.
329 (unless file-notify--library 334 (unless file-notify--library
330 (signal 'file-notify-error 335 (signal 'file-notify-error
331 '("No file notification package available"))) 336 '("No file notification package available")))
@@ -344,7 +349,8 @@ FILE is the name of the file whose event is being reported."
344 (setq 349 (setq
345 l-flags 350 l-flags
346 (cond 351 (cond
347 ((eq file-notify--library 'inotify) '(create modify move delete)) 352 ((eq file-notify--library 'inotify)
353 '(create delete delete-self modify move-self move))
348 ((eq file-notify--library 'w32notify) 354 ((eq file-notify--library 'w32notify)
349 '(file-name directory-name size last-write-time))))) 355 '(file-name directory-name size last-write-time)))))
350 (when (memq 'attribute-change flags) 356 (when (memq 'attribute-change flags)