Function: treemacs--start-watching

treemacs--start-watching is a byte-compiled function defined in treemacs-filewatch-mode.el.

Signature

(treemacs--start-watching PATH &optional COLLAPSE)

Documentation

Watch PATH for file system events.

Assumes to be run in the treemacs buffer as it will set PATH to be watched by current-buffer. Also add PATH to treemacs--collapsed-filewatch-index when COLLAPSE is non-nil.

PATH: Filepath COLLAPSE: Bool

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-filewatch-mode.el
(define-inline treemacs--start-watching (path &optional collapse)
  "Watch PATH for file system events.
Assumes to be run in the treemacs buffer as it will set PATH to be watched by
`current-buffer'.
Also add PATH to `treemacs--collapsed-filewatch-index' when COLLAPSE is non-nil.

PATH: Filepath
COLLAPSE: Bool"
  (inline-letevals (path collapse)
    (inline-quote
     (progn
       (when ,collapse
         (ht-set! treemacs--collapsed-filewatch-index ,path t))
       (-if-let (watch-info (ht-get treemacs--filewatch-index ,path))
           ;; just add current buffer to watch list if path is watched already
           (unless (memq (current-buffer) (car watch-info))
             (setcar watch-info (cons (current-buffer) (car watch-info))))
         ;; if the Tramp connection does not support watches, don't show an error
         ;; every time a watch is started.
         (treemacs-with-ignored-errors
          ((file-notify-error "No file notification program found"))
          ;; make new entry otherwise and set a new watcher
          (ht-set! treemacs--filewatch-index
                   ,path
                   (cons (list (current-buffer))
                         (file-notify-add-watch ,path '(change) #'treemacs--filewatch-callback)))))))))