Function: tramp-gvfs-monitor-process-filter
tramp-gvfs-monitor-process-filter is a byte-compiled function defined
in tramp-gvfs.el.gz.
Signature
(tramp-gvfs-monitor-process-filter PROC STRING)
Documentation
Read output from "gvfs-monitor-file" and add corresponding file-notify events.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-gvfs.el.gz
(defun tramp-gvfs-monitor-process-filter (proc string)
"Read output from \"gvfs-monitor-file\" and add corresponding \
`file-notify' events."
(let* ((events (process-get proc 'tramp-events))
(rest-string (process-get proc 'tramp-rest-string))
(dd (tramp-get-default-directory (process-buffer proc)))
(ddu (rx (literal (tramp-gvfs-url-file-name dd)))))
(when rest-string
(tramp-message proc 10 "Previous string:\n%s" rest-string))
(tramp-message proc 6 "%S\n%s" proc string)
(setq string (concat rest-string string)
;; Fix action names.
string (string-replace "attributes changed" "attribute-changed" string)
string (string-replace "changes done" "changes-done-hint" string)
string (string-replace "renamed to" "moved" string))
;; https://bugs.launchpad.net/bugs/1742946
(when
(string-match-p
(rx (| "Monitoring not supported" "No locations given")) string)
(delete-process proc))
(while (string-match
(rx
bol (+ nonl) ":"
blank (group (+ nonl)) ":"
blank (group (regexp (regexp-opt tramp-gio-events)))
(? (group blank (group (+ nonl)))) eol)
string)
(let ((file (match-string 1 string))
(file1 (match-string 4 string))
(action (intern-soft (match-string 2 string))))
(setq string (replace-match "" nil nil string))
;; File names are returned as URL paths. We must convert them.
(when (string-match ddu file)
(setq file (replace-match dd nil nil file)))
(while (string-match-p (rx "%" (= 2 xdigit)) file)
(setq file (url-unhex-string file)))
(when (string-match ddu (or file1 ""))
(setq file1 (replace-match dd nil nil file1)))
(while (string-match-p (rx "%" (= 2 xdigit)) (or file1 ""))
(setq file1 (url-unhex-string file1)))
;; Remove watch when file or directory to be watched is deleted.
(when (and (member action '(moved deleted))
(string-equal file (process-get proc 'tramp-watch-name)))
(delete-process proc))
;; Add an Emacs event now.
;; `insert-special-event' exists since Emacs 31.
(when (member action events)
(tramp-compat-funcall
(if (fboundp 'insert-special-event)
'insert-special-event
(lookup-key special-event-map [file-notify]))
`(file-notify
,(list proc action file file1) file-notify-callback)))))
;; Save rest of the string.
(when (string-empty-p string) (setq string nil))
(when string (tramp-message proc 10 "Rest string:\n%s" string))
(process-put proc 'tramp-rest-string string)))