aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2019-06-08 19:58:41 +0200
committerMattias EngdegÄrd2019-07-24 11:53:58 +0200
commit27f25d737c220afd8bf1902da72ee340704c47c2 (patch)
tree0d57ee1d35b81e09ccfff4c61874cce55f5eceba
parent5a80a9ded16b835ce42c5f4d2e3a5e711f7726cf (diff)
downloademacs-27f25d737c220afd8bf1902da72ee340704c47c2.tar.gz
emacs-27f25d737c220afd8bf1902da72ee340704c47c2.zip
Use defstruct instead of list for filenotify pending-rename
* lisp/filenotify.el (file-notify--rename): New defstruct. (file-notify--pending-rename): Changed type. (file-notify--handle-event): Adapt to new type.
-rw-r--r--lisp/filenotify.el55
1 files changed, 33 insertions, 22 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index ba8a9a34802..4860b4c46a7 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -105,10 +105,15 @@ Otherwise, signal a `file-notify-error'."
105 (signal 'file-notify-error 105 (signal 'file-notify-error
106 (cons "Not a valid file-notify event" event)))) 106 (cons "Not a valid file-notify event" event))))
107 107
108(cl-defstruct (file-notify--rename
109 (:constructor nil)
110 (:constructor
111 file-notify--rename-make (watch desc from-file cookie)))
112 watch desc from-file cookie)
113
108(defvar file-notify--pending-rename nil 114(defvar file-notify--pending-rename nil
109 "A pending rename event awaiting the destination file name. 115 "A pending rename event awaiting the destination file name.
110It is a list on the form (WATCH DESCRIPTOR FROM-FILE COOKIE) or nil, 116It is nil or a `file-notify--rename' where the cookie can be nil.")
111where COOKIE is a cookie (if used by the back-end) or nil.")
112 117
113(defun file-notify--expand-file-name (watch file) 118(defun file-notify--expand-file-name (watch file)
114 "Full file name of FILE reported for WATCH." 119 "Full file name of FILE reported for WATCH."
@@ -262,16 +267,20 @@ DESC is the back-end descriptor. ACTIONS is a list of:
262 ;; then send the former as a deletion (since we don't know the 267 ;; then send the former as a deletion (since we don't know the
263 ;; rename destination). 268 ;; rename destination).
264 (when file-notify--pending-rename 269 (when file-notify--pending-rename
265 (let ((pending-cookie (nth 3 file-notify--pending-rename))) 270 (unless (and (equal (file-notify--rename-cookie
266 (unless (and (equal pending-cookie file1-or-cookie) 271 file-notify--pending-rename)
267 (eq action 'renamed-to)) 272 file1-or-cookie)
268 (let* ((pending-watch (car file-notify--pending-rename)) 273 (eq action 'renamed-to))
269 (callback (file-notify--watch-callback pending-watch)) 274 (let ((callback (file-notify--watch-callback
270 (pending-desc (nth 1 file-notify--pending-rename)) 275 (file-notify--rename-watch
271 (from-file (nth 2 file-notify--pending-rename))) 276 file-notify--pending-rename))))
272 (when callback 277 (when callback
273 (funcall callback (list pending-desc 'deleted from-file))) 278 (funcall callback (list (file-notify--rename-desc
274 (setq file-notify--pending-rename nil))))) 279 file-notify--pending-rename)
280 'deleted
281 (file-notify--rename-from-file
282 file-notify--pending-rename))))
283 (setq file-notify--pending-rename nil))))
275 284
276 (let ((file1 nil)) 285 (let ((file1 nil))
277 (cond 286 (cond
@@ -289,24 +298,26 @@ DESC is the back-end descriptor. ACTIONS is a list of:
289 ;; Make the event pending. 298 ;; Make the event pending.
290 ((eq action 'renamed-from) 299 ((eq action 'renamed-from)
291 (setq file-notify--pending-rename 300 (setq file-notify--pending-rename
292 (list watch desc file file1-or-cookie)) 301 (file-notify--rename-make watch desc file file1-or-cookie))
293 (setq action nil)) 302 (setq action nil))
294 ;; Look for pending event. 303 ;; Look for pending event.
295 ((eq action 'renamed-to) 304 ((eq action 'renamed-to)
296 (if file-notify--pending-rename 305 (if file-notify--pending-rename
297 (let ((pending-watch (car file-notify--pending-rename)) 306 (let ((callback (file-notify--watch-callback
298 (pending-desc (nth 1 file-notify--pending-rename)) 307 (file-notify--rename-watch
299 (from-file (nth 2 file-notify--pending-rename))) 308 file-notify--pending-rename)))
309 (pending-desc (file-notify--rename-desc
310 file-notify--pending-rename))
311 (from-file (file-notify--rename-from-file
312 file-notify--pending-rename)))
300 (setq file1 file) 313 (setq file1 file)
301 (setq file from-file) 314 (setq file from-file)
302 ;; If the source is handled by another watch, we 315 ;; If the source is handled by another watch, we
303 ;; must fire the rename event there as well. 316 ;; must fire the rename event there as well.
304 (let ((callback 317 (when (and (not (equal desc pending-desc))
305 (file-notify--watch-callback pending-watch))) 318 callback)
306 (when (and (not (equal desc pending-desc)) 319 (funcall callback
307 callback) 320 (list pending-desc 'renamed file file1)))
308 (funcall callback
309 (list pending-desc 'renamed file file1))))
310 (setq file-notify--pending-rename nil) 321 (setq file-notify--pending-rename nil)
311 (setq action 'renamed)) 322 (setq action 'renamed))
312 (setq action 'created)))) 323 (setq action 'created))))