Function: treemacs--bulk-copy-or-move

treemacs--bulk-copy-or-move is a byte-compiled function defined in treemacs-file-management.el.

Signature

(treemacs--bulk-copy-or-move &key ACTION ACTION-FN PROMPT FINISH-VERB)

Documentation

Internal implementation for bulk-copying and -moving files.

ACTION: either copy or move ACTION-FN: function to actually copy or move a file PROMPT: prompt to read the target directory FINISH-VERB: finisher for the success message.

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-file-management.el
(cl-defun treemacs--bulk-copy-or-move
    (&key
     action
     action-fn
     prompt
     finish-verb)
  "Internal implementation for bulk-copying and -moving files.
ACTION: either `copy' or `move'
ACTION-FN: function to actually copy or move a file
PROMPT: prompt to read the target directory
FINISH-VERB: finisher for the success message."
  (treemacs-block
   (let* ((to-move (-filter #'file-exists-p treemacs--marked-paths))
          (destination-dir (treemacs--canonical-path
                            (read-directory-name prompt nil default-directory)))
          (projects (->> to-move
                         (-map #'treemacs--find-project-for-path)
                         (cl-remove-duplicates)
                         (-filter #'identity))))
     (treemacs-save-position
      (dolist (source to-move)
        (let ((target (->> source
                           (treemacs--filename)
                           (treemacs-join-path destination-dir)
                           (treemacs--find-repeated-file-name))))
          (unless (string= source target)
            (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"))))))

      (dolist (project projects)
        (treemacs-project->refresh! project)))

     (when (treemacs-is-path destination-dir :in-workspace)
       (treemacs-goto-file-node destination-dir))

     (setf treemacs--marked-paths (-difference treemacs--marked-paths to-move))

     (treemacs-pulse-on-success "%s %s files to %s"
       finish-verb
       (propertize (number-to-string (length to-move)) 'face 'font-lock-constant-face)
       (propertize destination-dir 'face 'font-lock-string-face)))))