summaryrefslogtreecommitdiff
path: root/lisp/filenotify.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/filenotify.el')
-rw-r--r--lisp/filenotify.el33
1 files changed, 22 insertions, 11 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 4fc7f0a8ec0..26954cc73f2 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -19,7 +19,7 @@
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-;;; Commentary
+;;; Commentary:
;; This package is an abstraction layer from the different low-level
;; file notification packages `inotify', `kqueue', `gfilenotify' and
@@ -76,16 +76,17 @@ struct.")
"Remove DESCRIPTOR from `file-notify-descriptors'.
DESCRIPTOR should be an object returned by `file-notify-add-watch'.
If it is registered in `file-notify-descriptors', a `stopped' event is sent."
- (when-let* ((watch (gethash descriptor file-notify-descriptors)))
- (let ((callback (file-notify--watch-callback watch)))
- ;; Make sure this is the last time the callback is invoked.
+ (when-let ((watch (gethash descriptor file-notify-descriptors)))
+ (unwind-protect
+ ;; Send `stopped' event.
+ (file-notify-handle-event
+ (make-file-notify
+ :-event `(,descriptor stopped
+ ,(file-notify--watch-absolute-filename watch))
+ :-callback (file-notify--watch-callback watch)))
+ ;; Make sure this is the last time the callback was invoked.
(setf (file-notify--watch-callback watch) nil)
- ;; Send `stopped' event.
- (unwind-protect
- (funcall
- callback
- `(,descriptor stopped ,(file-notify--watch-absolute-filename watch)))
- (remhash descriptor file-notify-descriptors)))))
+ (remhash descriptor file-notify-descriptors))))
(cl-defstruct (file-notify (:type list) :named)
"A file system monitoring event, coming from the backends."
@@ -389,7 +390,9 @@ include the following symbols:
permissions or modification time
If FILE is a directory, `change' watches for file creation or
-deletion in that directory. This does not work recursively.
+deletion in that directory. Some of the file notification
+backends report also file changes. This does not work
+recursively.
When any event happens, Emacs will call the CALLBACK function passing
it a single argument EVENT, which is of the form
@@ -477,6 +480,14 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
;; Modify `file-notify-descriptors' and send a `stopped' event.
(file-notify--rm-descriptor descriptor))))
+(defun file-notify-rm-all-watches ()
+ "Remove all existing file notification watches from Emacs."
+ (interactive)
+ (maphash
+ (lambda (key _value)
+ (file-notify-rm-watch key))
+ file-notify-descriptors))
+
(defun file-notify-valid-p (descriptor)
"Check a watch specified by its DESCRIPTOR.
DESCRIPTOR should be an object returned by `file-notify-add-watch'."