Function: treemacs--on-rename
treemacs--on-rename is a byte-compiled function defined in
treemacs-dom.el.
Signature
(treemacs--on-rename OLD-NAME NEW-NAME DONT-RENAME-INITIAL)
Documentation
Renames dom entries after a file was renamed from OLD-NAME to NEW-NAME.
Renames the initial dom entry (the one backing the file that was actually renamed) only if DONT-RENAME-INITIAL is nil in case the entry is required for filewatch-mode to work.
OLD-NAME: File Path | Tag Path NEW-NAME: File Path | Tag Path DONT-RENAME-INITIAL: Boolean
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-dom.el
(defun treemacs--on-rename (old-name new-name dont-rename-initial)
"Renames dom entries after a file was renamed from OLD-NAME to NEW-NAME.
Renames the initial dom entry (the one backing the file that was actually
renamed) only if DONT-RENAME-INITIAL is nil in case the entry is required for
filewatch-mode to work.
OLD-NAME: File Path | Tag Path
NEW-NAME: File Path | Tag Path
DONT-RENAME-INITIAL: Boolean"
(-when-let (dom-node (treemacs-find-in-dom old-name))
(-let [migrate-keys
(lambda (it)
(let* ((old-key (treemacs-dom-node->key it))
(new-key (cond
((stringp old-key)
(s-replace old-name new-name old-key))
((and (consp old-key) (stringp (car old-key)))
(cons (s-replace old-name new-name (car old-key)) (cdr old-key))))))
(when new-key
(ht-remove! treemacs-dom old-key)
(ht-set! treemacs-dom new-key it)
(setf (treemacs-dom-node->key it) new-key))))]
;; when filewatch is enabled the acutally renamed file needs to keep
;; its dom entry until refresh actually runs so it can be deleted properly
(if dont-rename-initial
(progn
(treemacs-walk-reentry-dom-exclusive dom-node migrate-keys)
(treemacs-walk-dom-exclusive dom-node migrate-keys))
(treemacs-walk-dom dom-node migrate-keys)
(treemacs-walk-reentry-dom dom-node migrate-keys)))))