Function: send-to--dired-filenames-in-region

send-to--dired-filenames-in-region is a byte-compiled function defined in send-to.el.gz.

Signature

(send-to--dired-filenames-in-region)

Documentation

If in a dired buffer, return region files. nil otherwise.

Source Code

;; Defined in /usr/src/emacs/lisp/send-to.el.gz
(defun send-to--dired-filenames-in-region ()
  "If in a `dired' buffer, return region files.  nil otherwise."
  (when (and (derived-mode-p 'dired-mode)
             (use-region-p))
    (let* ((start (region-beginning))
           (end (region-end))
           (marked-files (dired-get-marked-files nil nil nil t))
           (active-marks-p (if (= (length marked-files) 1)
                               nil ;; File found at point (not marked)
                             (not (seq-empty-p marked-files))))
           (filenames))
      (when active-marks-p
        (user-error "Either mark `dired' files or select a region, but not both"))
      (save-excursion
        (save-restriction
          (goto-char start)
          (while (< (point) end)
            ;; Skip non-file lines.
            (while (and (< (point) end) (dired-between-files))
              (forward-line 1))
            (when (and (dired-get-filename nil t)
                       ;; Filename must be in region.
                       (< (save-excursion
                            (forward-line 0)
                            (dired-move-to-filename))
                          end))
              (setq filenames (append filenames (list (dired-get-filename nil t)))))
            (forward-line 1))))
      filenames)))