aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2017-03-26 09:42:40 +0200
committerMichael Albinus2017-03-26 09:42:40 +0200
commit74129db63d690747c008b1b5d442fe41056584c3 (patch)
tree9823da4c0bd892cd7348ba9037a59e8ea2ef558f
parent158bb8555dfefa50f6118be6794d0424cc52d291 (diff)
downloademacs-74129db63d690747c008b1b5d442fe41056584c3.tar.gz
emacs-74129db63d690747c008b1b5d442fe41056584c3.zip
; Format files from last commit
-rw-r--r--lisp/filenotify.el30
-rw-r--r--src/inotify.c23
2 files changed, 26 insertions, 27 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 0f8c945a79e..55ce94a1cad 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -42,7 +42,8 @@ could use another implementation.")
42 42
43(cl-defstruct (file-notify--watch 43(cl-defstruct (file-notify--watch
44 (:constructor nil) 44 (:constructor nil)
45 (:constructor file-notify--watch-make (directory filename callback))) 45 (:constructor
46 file-notify--watch-make (directory filename callback)))
46 ;; Watched directory 47 ;; Watched directory
47 directory 48 directory
48 ;; Watched relative filename, nil if watching the directory. 49 ;; Watched relative filename, nil if watching the directory.
@@ -61,14 +62,13 @@ could use another implementation.")
61 "Hash table for registered file notification descriptors. 62 "Hash table for registered file notification descriptors.
62A key in this hash table is the descriptor as returned from 63A key in this hash table is the descriptor as returned from
63`inotify', `kqueue', `gfilenotify', `w32notify' or a file name 64`inotify', `kqueue', `gfilenotify', `w32notify' or a file name
64handler. The value in the hash table is file-notify--watch 65handler. The value in the hash table is `file-notify--watch'
65struct.") 66struct.")
66 67
67(defun file-notify--rm-descriptor (descriptor) 68(defun file-notify--rm-descriptor (descriptor)
68 "Remove DESCRIPTOR from `file-notify-descriptors'. 69 "Remove DESCRIPTOR from `file-notify-descriptors'.
69DESCRIPTOR should be an object returned by 70DESCRIPTOR should be an object returned by `file-notify-add-watch'.
70`file-notify-add-watch'. If it is registered in 71If it is registered in `file-notify-descriptors', a stopped event is sent."
71`file-notify-descriptors', a stopped event is sent."
72 (when-let (watch (gethash descriptor file-notify-descriptors)) 72 (when-let (watch (gethash descriptor file-notify-descriptors))
73 ;; Send `stopped' event. 73 ;; Send `stopped' event.
74 (unwind-protect 74 (unwind-protect
@@ -123,8 +123,7 @@ This is available in case a file has been moved."
123 (and (stringp (nth 3 event)) 123 (and (stringp (nth 3 event))
124 (directory-file-name 124 (directory-file-name
125 (expand-file-name 125 (expand-file-name
126 (nth 3 event) 126 (nth 3 event) (file-notify--watch-directory watch))))))
127 (file-notify--watch-directory watch))))))
128 127
129;; Cookies are offered by `inotify' only. 128;; Cookies are offered by `inotify' only.
130(defun file-notify--event-cookie (event) 129(defun file-notify--event-cookie (event)
@@ -187,11 +186,13 @@ EVENT is the cadr of the event in `file-notify-handle-event'
187 ((memq action '(attrib link)) 'attribute-changed) 186 ((memq action '(attrib link)) 'attribute-changed)
188 ((memq action '(create added)) 'created) 187 ((memq action '(create added)) 'created)
189 ((memq action '(modify modified write)) 'changed) 188 ((memq action '(modify modified write)) 'changed)
190 ((memq action '(delete delete-self move-self removed)) 'deleted) 189 ((memq action
190 '(delete delete-self move-self removed)) 'deleted)
191 ;; Make the event pending. 191 ;; Make the event pending.
192 ((memq action '(moved-from renamed-from)) 192 ((memq action '(moved-from renamed-from))
193 (setq file-notify--pending-event 193 (setq file-notify--pending-event
194 `((,desc ,action ,file ,(file-notify--event-cookie event)) 194 `((,desc ,action ,file
195 ,(file-notify--event-cookie event))
195 ,(file-notify--watch-callback watch))) 196 ,(file-notify--watch-callback watch)))
196 nil) 197 nil)
197 ;; Look for pending event. 198 ;; Look for pending event.
@@ -222,8 +223,8 @@ EVENT is the cadr of the event in `file-notify-handle-event'
222 ;; Apply callback. 223 ;; Apply callback.
223 (when (and action 224 (when (and action
224 (or 225 (or
225 ;; If there is no relative file name for that watch, 226 ;; If there is no relative file name for that
226 ;; we watch the whole directory. 227 ;; watch, we watch the whole directory.
227 (null (file-notify--watch-filename watch)) 228 (null (file-notify--watch-filename watch))
228 ;; File matches. 229 ;; File matches.
229 (string-equal 230 (string-equal
@@ -241,8 +242,7 @@ EVENT is the cadr of the event in `file-notify-handle-event'
241 (file-name-nondirectory file1))))) 242 (file-name-nondirectory file1)))))
242 ;;(message 243 ;;(message
243 ;;"file-notify-callback %S %S %S %S %S" 244 ;;"file-notify-callback %S %S %S %S %S"
244 ;;desc 245 ;;desc action file file1 watch)
245 ;;action file file1 watch)
246 (if file1 246 (if file1
247 (funcall (file-notify--watch-callback watch) 247 (funcall (file-notify--watch-callback watch)
248 `(,desc ,action ,file ,file1)) 248 `(,desc ,action ,file ,file1))
@@ -382,8 +382,8 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
382 'file-notify-rm-watch))) 382 'file-notify-rm-watch)))
383 (condition-case nil 383 (condition-case nil
384 (if handler 384 (if handler
385 ;; A file name handler could exist even if there is no local 385 ;; A file name handler could exist even if there is no
386 ;; file notification support. 386 ;; local file notification support.
387 (funcall handler 'file-notify-rm-watch descriptor) 387 (funcall handler 'file-notify-rm-watch descriptor)
388 388
389 (funcall 389 (funcall
diff --git a/src/inotify.c b/src/inotify.c
index a084552adcb..470b60ba893 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -61,7 +61,7 @@ static int inotifyfd = -1;
61 IN_ONLYDIR 61 IN_ONLYDIR
62 62
63 Format: (descriptor . ((id filename callback mask) ...)) 63 Format: (descriptor . ((id filename callback mask) ...))
64 */ 64*/
65static Lisp_Object watch_list; 65static Lisp_Object watch_list;
66 66
67static Lisp_Object 67static Lisp_Object
@@ -204,9 +204,10 @@ inotifyevent_to_event (Lisp_Object watch, struct inotify_event const *ev)
204 204
205/* Add a new watch to watch-descriptor WD watching FILENAME and using 205/* Add a new watch to watch-descriptor WD watching FILENAME and using
206 CALLBACK. Returns a cons (DESCRIPTOR . ID) uniquely identifying the 206 CALLBACK. Returns a cons (DESCRIPTOR . ID) uniquely identifying the
207 new watch. */ 207 new watch. */
208static Lisp_Object 208static Lisp_Object
209add_watch (int wd, Lisp_Object filename, Lisp_Object aspect, Lisp_Object callback) 209add_watch (int wd, Lisp_Object filename,
210 Lisp_Object aspect, Lisp_Object callback)
210{ 211{
211 Lisp_Object descriptor = make_number (wd); 212 Lisp_Object descriptor = make_number (wd);
212 Lisp_Object elt = Fassoc (descriptor, watch_list); 213 Lisp_Object elt = Fassoc (descriptor, watch_list);
@@ -260,7 +261,7 @@ remove_descriptor (Lisp_Object descriptor, bool invalid_p)
260 } 261 }
261} 262}
262 263
263/* Remove watch associated with (descriptor, id). */ 264/* Remove watch associated with (descriptor, id). */
264static void 265static void
265remove_watch (Lisp_Object descriptor, Lisp_Object id) 266remove_watch (Lisp_Object descriptor, Lisp_Object id)
266{ 267{
@@ -273,7 +274,7 @@ remove_watch (Lisp_Object descriptor, Lisp_Object id)
273 if (! NILP (watch)) 274 if (! NILP (watch))
274 XSETCDR (elt, Fdelete (watch, XCDR (elt))); 275 XSETCDR (elt, Fdelete (watch, XCDR (elt)));
275 276
276 /* Remove the descriptor if noone is watching it. */ 277 /* Remove the descriptor if noone is watching it. */
277 if (NILP (XCDR (elt))) 278 if (NILP (XCDR (elt)))
278 remove_descriptor (descriptor, false); 279 remove_descriptor (descriptor, false);
279 } 280 }
@@ -378,13 +379,12 @@ unmount
378 379
379If a directory is watched then NAME is the name of file that caused the event. 380If a directory is watched then NAME is the name of file that caused the event.
380 381
381COOKIE is an object that can be compared using `equal' to identify two matchingt 382COOKIE is an object that can be compared using `equal' to identify two matching
382renames (moved-from and moved-to). 383renames (moved-from and moved-to).
383 384
384See inotify(7) and inotify_add_watch(2) for further information. The inotify fd 385See inotify(7) and inotify_add_watch(2) for further information. The inotify fd
385is managed internally and there is no corresponding inotify_init. Use 386is managed internally and there is no corresponding inotify_init. Use
386`inotify-rm-watch' to remove a watch. 387`inotify-rm-watch' to remove a watch. */)
387 */)
388 (Lisp_Object filename, Lisp_Object aspect, Lisp_Object callback) 388 (Lisp_Object filename, Lisp_Object aspect, Lisp_Object callback)
389{ 389{
390 Lisp_Object encoded_file_name; 390 Lisp_Object encoded_file_name;
@@ -417,8 +417,7 @@ DEFUN ("inotify-rm-watch", Finotify_rm_watch, Sinotify_rm_watch, 1, 1, 0,
417 417
418WATCH-DESCRIPTOR should be an object returned by `inotify-add-watch'. 418WATCH-DESCRIPTOR should be an object returned by `inotify-add-watch'.
419 419
420See inotify_rm_watch(2) for more information. 420See inotify_rm_watch(2) for more information. */)
421 */)
422 (Lisp_Object watch_descriptor) 421 (Lisp_Object watch_descriptor)
423{ 422{
424 423
@@ -462,13 +461,13 @@ it invalid. */)
462 461
463#ifdef INOTIFY_DEBUG 462#ifdef INOTIFY_DEBUG
464DEFUN ("inotify-watch-list", Finotify_watch_list, Sinotify_watch_list, 0, 0, 0, 463DEFUN ("inotify-watch-list", Finotify_watch_list, Sinotify_watch_list, 0, 0, 0,
465 doc: /* Return a copy of the internal watch_list. */) 464 doc: /* Return a copy of the internal watch_list. */)
466{ 465{
467 return Fcopy_sequence (watch_list); 466 return Fcopy_sequence (watch_list);
468} 467}
469 468
470DEFUN ("inotify-allocated-p", Finotify_allocated_p, Sinotify_allocated_p, 0, 0, 0, 469DEFUN ("inotify-allocated-p", Finotify_allocated_p, Sinotify_allocated_p, 0, 0, 0,
471 doc: /* Return non-nil, if a inotify instance is allocated. */) 470 doc: /* Return non-nil, if a inotify instance is allocated. */)
472{ 471{
473 return inotifyfd < 0 ? Qnil : Qt; 472 return inotifyfd < 0 ? Qnil : Qt;
474} 473}