aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichael Albinus2015-11-09 20:26:10 +0100
committerMichael Albinus2015-11-11 12:10:48 +0100
commit0198c3066e8866d464690a9a7924d42e9c2663bf (patch)
treef0b6e7771a4372da7a6476984e0d401974c9c3ca /lisp
parent662ee733257d573deaadd2e217894b70265fb5fe (diff)
downloademacs-0198c3066e8866d464690a9a7924d42e9c2663bf.tar.gz
emacs-0198c3066e8866d464690a9a7924d42e9c2663bf.zip
Work on kqueue
* lisp/filenotify.el (file-notify--library) (file-notify-descriptors, file-notify-callback) (file-notify-add-watch, file-notify-rm-watch) (file-notify-valid-p): Add kqueue support. * src/keyboard.c (make_lispy_event): Check also for HAVE_KQUEUE.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/filenotify.el40
1 files changed, 23 insertions, 17 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 4c5d43fb44e..f7c97569825 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -22,15 +22,16 @@
22;;; Commentary 22;;; Commentary
23 23
24;; This package is an abstraction layer from the different low-level 24;; This package is an abstraction layer from the different low-level
25;; file notification packages `gfilenotify', `inotify' and 25;; file notification packages `inotify', `kqueue', `gfilenotify' and
26;; `w32notify'. 26;; `w32notify'.
27 27
28;;; Code: 28;;; Code:
29 29
30(defconst file-notify--library 30(defconst file-notify--library
31 (cond 31 (cond
32 ((featurep 'gfilenotify) 'gfilenotify)
33 ((featurep 'inotify) 'inotify) 32 ((featurep 'inotify) 'inotify)
33 ((featurep 'kqueue) 'kqueue)
34 ((featurep 'gfilenotify) 'gfilenotify)
34 ((featurep 'w32notify) 'w32notify)) 35 ((featurep 'w32notify) 'w32notify))
35 "Non-nil when Emacs has been compiled with file notification support. 36 "Non-nil when Emacs has been compiled with file notification support.
36The value is the name of the low-level file notification package 37The value is the name of the low-level file notification package
@@ -40,8 +41,8 @@ could use another implementation.")
40(defvar file-notify-descriptors (make-hash-table :test 'equal) 41(defvar file-notify-descriptors (make-hash-table :test 'equal)
41 "Hash table for registered file notification descriptors. 42 "Hash table for registered file notification descriptors.
42A key in this hash table is the descriptor as returned from 43A key in this hash table is the descriptor as returned from
43`gfilenotify', `inotify', `w32notify' or a file name handler. 44`inotify', `kqueue', `gfilenotify', `w32notify' or a file name
44The value in the hash table is a list 45handler. The value in the hash table is a list
45 46
46 (DIR (FILE . CALLBACK) (FILE . CALLBACK) ...) 47 (DIR (FILE . CALLBACK) (FILE . CALLBACK) ...)
47 48
@@ -76,7 +77,8 @@ WHAT is a file or directory name to be removed, needed just for `inotify'."
76 (remhash desc file-notify-descriptors) 77 (remhash desc file-notify-descriptors)
77 (puthash desc registered file-notify-descriptors)))))) 78 (puthash desc registered file-notify-descriptors))))))
78 79
79;; This function is used by `gfilenotify', `inotify' and `w32notify' events. 80;; This function is used by `inotify', `kqueue', `gfilenotify' and
81;; `w32notify' events.
80;;;###autoload 82;;;###autoload
81(defun file-notify-handle-event (event) 83(defun file-notify-handle-event (event)
82 "Handle file system monitoring event. 84 "Handle file system monitoring event.
@@ -159,7 +161,7 @@ EVENT is the cadr of the event in `file-notify-handle-event'
159 (setq actions nil)) 161 (setq actions nil))
160 162
161 ;; Loop over actions. In fact, more than one action happens only 163 ;; Loop over actions. In fact, more than one action happens only
162 ;; for `inotify'. 164 ;; for `inotify' and `kqueue'.
163 (dolist (action actions) 165 (dolist (action actions)
164 166
165 ;; Send pending event, if it doesn't match. 167 ;; Send pending event, if it doesn't match.
@@ -184,19 +186,17 @@ EVENT is the cadr of the event in `file-notify-handle-event'
184 ;; Map action. We ignore all events which cannot be mapped. 186 ;; Map action. We ignore all events which cannot be mapped.
185 (setq action 187 (setq action
186 (cond 188 (cond
187 ;; gfilenotify. 189 ((memq action
188 ((memq action '(attribute-changed changed created deleted)) 190 '(attribute-changed changed created deleted renamed))
189 action) 191 action)
190 ((eq action 'moved) 192 ((eq action 'moved)
191 (setq file1 (file-notify--event-file1-name event)) 193 (setq file1 (file-notify--event-file1-name event))
192 'renamed) 194 'renamed)
193
194 ;; inotify, w32notify.
195 ((eq action 'ignored) 195 ((eq action 'ignored)
196 (setq stopped t actions nil)) 196 (setq stopped t actions nil))
197 ((eq action 'attrib) 'attribute-changed) 197 ((memq action '(attrib link)) 'attribute-changed)
198 ((memq action '(create added)) 'created) 198 ((memq action '(create added)) 'created)
199 ((memq action '(modify modified)) 'changed) 199 ((memq action '(modify modified write)) 'changed)
200 ((memq action '(delete delete-self move-self removed)) 'deleted) 200 ((memq action '(delete delete-self move-self removed)) 'deleted)
201 ;; Make the event pending. 201 ;; Make the event pending.
202 ((memq action '(moved-from renamed-from)) 202 ((memq action '(moved-from renamed-from))
@@ -275,8 +275,8 @@ EVENT is the cadr of the event in `file-notify-handle-event'
275 (file-notify--rm-descriptor 275 (file-notify--rm-descriptor
276 (file-notify--descriptor desc file) file))))) 276 (file-notify--descriptor desc file) file)))))
277 277
278;; `gfilenotify' and `w32notify' return a unique descriptor for every 278;; `kqueue', `gfilenotify' and `w32notify' return a unique descriptor
279;; `file-notify-add-watch', while `inotify' returns a unique 279;; for every `file-notify-add-watch', while `inotify' returns a unique
280;; descriptor per inode only. 280;; descriptor per inode only.
281(defun file-notify-add-watch (file flags callback) 281(defun file-notify-add-watch (file flags callback)
282 "Add a watch for filesystem events pertaining to FILE. 282 "Add a watch for filesystem events pertaining to FILE.
@@ -349,8 +349,9 @@ FILE is the name of the file whose event is being reported."
349 ;; Determine low-level function to be called. 349 ;; Determine low-level function to be called.
350 (setq func 350 (setq func
351 (cond 351 (cond
352 ((eq file-notify--library 'gfilenotify) 'gfile-add-watch)
353 ((eq file-notify--library 'inotify) 'inotify-add-watch) 352 ((eq file-notify--library 'inotify) 'inotify-add-watch)
353 ((eq file-notify--library 'kqueue) 'kqueue-add-watch)
354 ((eq file-notify--library 'gfilenotify) 'gfile-add-watch)
354 ((eq file-notify--library 'w32notify) 'w32notify-add-watch))) 355 ((eq file-notify--library 'w32notify) 'w32notify-add-watch)))
355 356
356 ;; Determine respective flags. 357 ;; Determine respective flags.
@@ -362,11 +363,14 @@ FILE is the name of the file whose event is being reported."
362 (cond 363 (cond
363 ((eq file-notify--library 'inotify) 364 ((eq file-notify--library 'inotify)
364 '(create delete delete-self modify move-self move)) 365 '(create delete delete-self modify move-self move))
366 ((eq file-notify--library 'kqueue)
367 '(delete write extend rename))
365 ((eq file-notify--library 'w32notify) 368 ((eq file-notify--library 'w32notify)
366 '(file-name directory-name size last-write-time))))) 369 '(file-name directory-name size last-write-time)))))
367 (when (memq 'attribute-change flags) 370 (when (memq 'attribute-change flags)
368 (push (cond 371 (push (cond
369 ((eq file-notify--library 'inotify) 'attrib) 372 ((eq file-notify--library 'inotify) 'attrib)
373 ((eq file-notify--library 'kqueue) 'attrib)
370 ((eq file-notify--library 'w32notify) 'attributes)) 374 ((eq file-notify--library 'w32notify) 'attributes))
371 l-flags))) 375 l-flags)))
372 376
@@ -410,8 +414,9 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
410 414
411 (funcall 415 (funcall
412 (cond 416 (cond
413 ((eq file-notify--library 'gfilenotify) 'gfile-rm-watch)
414 ((eq file-notify--library 'inotify) 'inotify-rm-watch) 417 ((eq file-notify--library 'inotify) 'inotify-rm-watch)
418 ((eq file-notify--library 'kqueue) 'kqueue-rm-watch)
419 ((eq file-notify--library 'gfilenotify) 'gfile-rm-watch)
415 ((eq file-notify--library 'w32notify) 'w32notify-rm-watch)) 420 ((eq file-notify--library 'w32notify) 'w32notify-rm-watch))
416 desc)) 421 desc))
417 (file-notify-error nil))) 422 (file-notify-error nil)))
@@ -441,8 +446,9 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
441 (funcall handler 'file-notify-valid-p descriptor) 446 (funcall handler 'file-notify-valid-p descriptor)
442 (funcall 447 (funcall
443 (cond 448 (cond
444 ((eq file-notify--library 'gfilenotify) 'gfile-valid-p)
445 ((eq file-notify--library 'inotify) 'inotify-valid-p) 449 ((eq file-notify--library 'inotify) 'inotify-valid-p)
450 ((eq file-notify--library 'kqueue) 'kqueue-valid-p)
451 ((eq file-notify--library 'gfilenotify) 'gfile-valid-p)
446 ((eq file-notify--library 'w32notify) 'w32notify-valid-p)) 452 ((eq file-notify--library 'w32notify) 'w32notify-valid-p))
447 desc)) 453 desc))
448 t)))) 454 t))))