Function: treemacs--copy-or-move
treemacs--copy-or-move is a byte-compiled function defined in
treemacs-file-management.el.
Signature
(treemacs--copy-or-move &key ACTION NO-NODE-MSG WRONG-TYPE-MSG ACTION-FN PROMPT FLAT-PROMPT FINISH-VERB)
Documentation
Internal implementation for copying and moving files.
ACTION: either copy or move
NO-NODE-MSG: error message in case there is no node in the current line
WRONG-TYPE-MSG: error message in case current node is not a file
ACTION-FN: function to actually copy or move a file
PROMPT: prompt to read the target directory
FLAT-PROMPT: prompt to select source file when node is flattened
FINISH-VERB: finisher for the success message.
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-file-management.el
(cl-defun treemacs--copy-or-move
(&key
action
no-node-msg
wrong-type-msg
action-fn
prompt
flat-prompt
finish-verb)
"Internal implementation for copying and moving files.
ACTION: either `copy' or `move'
NO-NODE-MSG: error message in case there is no node in the current line
WRONG-TYPE-MSG: error message in case current node is not a file
ACTION-FN: function to actually copy or move a file
PROMPT: prompt to read the target directory
FLAT-PROMPT: prompt to select source file when node is flattened
FINISH-VERB: finisher for the success message."
(treemacs-block
(let ((btn (treemacs-current-button)))
(treemacs-error-return-if (null btn)
no-node-msg)
(treemacs-error-return-if
(not (memq (treemacs-button-get btn :state)
'(file-node-open file-node-closed dir-node-open dir-node-closed)))
wrong-type-msg)
(let* ((source (treemacs--select-file-from-btn btn flat-prompt))
(destination (treemacs--canonical-path
(read-directory-name prompt nil default-directory)))
(destination-dir (if (file-directory-p destination)
destination
(treemacs--parent-dir destination)))
(target-name (treemacs--filename
(if (file-directory-p destination)
source
destination)))
(target (->> target-name
(treemacs-join-path destination-dir)
(treemacs--find-repeated-file-name))))
(unless (file-exists-p destination-dir)
(make-directory destination-dir :parents))
(when (eq action 'move)
;; do the deletion *before* moving the file, otherwise it will
;; no longer exist and treemacs will not recognize it as a file path
(treemacs-do-delete-single-node source))
(treemacs--without-filewatch
(funcall action-fn source target))
(pcase action
('move
(run-hook-with-args 'treemacs-copy-file-functions source target)
(treemacs--on-file-deletion source))
('copy
(run-hook-with-args 'treemacs-move-file-functions source target)
(treemacs-remove-annotation-face source "treemacs-marked-paths")))
(treemacs-update-node destination-dir)
(when (treemacs-is-path target :in-workspace)
(treemacs-goto-file-node target))
(treemacs-pulse-on-success "%s %s to %s"
finish-verb
(propertize (treemacs--filename target) 'face 'font-lock-string-face)
(propertize destination-dir 'face 'font-lock-string-face))))))