Function: treemacs--find-repeated-file-name
treemacs--find-repeated-file-name is a byte-compiled function defined
in treemacs-core-utils.el.
Signature
(treemacs--find-repeated-file-name PATH)
Documentation
Find a fitting copy name for given file PATH.
Returns a name in the /file/name (Copy 1).ext. If that also already exists it returns /file/name (Copy 2).ext etc.
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-core-utils.el
(defun treemacs--find-repeated-file-name (path)
"Find a fitting copy name for given file PATH.
Returns a name in the /file/name (Copy 1).ext. If that also already
exists it returns /file/name (Copy 2).ext etc."
(let* ((n 0)
(dir (treemacs--parent-dir path))
(filename (treemacs--filename path))
(filename-no-ext (file-name-sans-extension path))
(ext (--when-let (file-name-extension filename) (concat "." it)))
(template " (Copy %d)")
(new-path path))
(while (file-exists-p new-path)
(cl-incf n)
(setf new-path (treemacs-join-path dir (concat filename-no-ext (format template n) ext))))
new-path))