1417 |
;;; 5K |
;;; 5K |
1418 |
;;;###begin dired-re.el |
;;;###begin dired-re.el |
1419 |
(defun dired-do-create-files-regexp |
(defun dired-do-create-files-regexp |
1420 |
(file-creator operation arg regexp newname &optional whole-path marker-char) |
(file-creator operation arg regexp newname &optional whole-name marker-char) |
1421 |
;; Create a new file for each marked file using regexps. |
;; Create a new file for each marked file using regexps. |
1422 |
;; FILE-CREATOR and OPERATION as in dired-create-files. |
;; FILE-CREATOR and OPERATION as in dired-create-files. |
1423 |
;; ARG as in dired-get-marked-files. |
;; ARG as in dired-get-marked-files. |
1424 |
;; Matches each marked file against REGEXP and constructs the new |
;; Matches each marked file against REGEXP and constructs the new |
1425 |
;; filename from NEWNAME (like in function replace-match). |
;; filename from NEWNAME (like in function replace-match). |
1426 |
;; Optional arg WHOLE-PATH means match/replace the whole file name |
;; Optional arg WHOLE-NAME means match/replace the whole file name |
1427 |
;; instead of only the non-directory part of the file. |
;; instead of only the non-directory part of the file. |
1428 |
;; Optional arg MARKER-CHAR as in dired-create-files. |
;; Optional arg MARKER-CHAR as in dired-create-files. |
1429 |
(let* ((fn-list (dired-get-marked-files nil arg)) |
(let* ((fn-list (dired-get-marked-files nil arg)) |
1436 |
(downcase operation))) |
(downcase operation))) |
1437 |
(regexp-name-constructor |
(regexp-name-constructor |
1438 |
;; Function to construct new filename using REGEXP and NEWNAME: |
;; Function to construct new filename using REGEXP and NEWNAME: |
1439 |
(if whole-path ; easy (but rare) case |
(if whole-name ; easy (but rare) case |
1440 |
(function |
(function |
1441 |
(lambda (from) |
(lambda (from) |
1442 |
(let ((to (dired-string-replace-match regexp from newname)) |
(let ((to (dired-string-replace-match regexp from newname)) |
1451 |
to) |
to) |
1452 |
(dired-log "%s: %s did not match regexp %s\n" |
(dired-log "%s: %s did not match regexp %s\n" |
1453 |
operation from regexp))))) |
operation from regexp))))) |
1454 |
;; not whole-path, replace non-directory part only |
;; not whole-name, replace non-directory part only |
1455 |
(function |
(function |
1456 |
(lambda (from) |
(lambda (from) |
1457 |
(let* ((new (dired-string-replace-match |
(let* ((new (dired-string-replace-match |
1474 |
|
|
1475 |
(defun dired-mark-read-regexp (operation) |
(defun dired-mark-read-regexp (operation) |
1476 |
;; Prompt user about performing OPERATION. |
;; Prompt user about performing OPERATION. |
1477 |
;; Read and return list of: regexp newname arg whole-path. |
;; Read and return list of: regexp newname arg whole-name. |
1478 |
(let* ((whole-path |
(let* ((whole-name |
1479 |
(equal 0 (prefix-numeric-value current-prefix-arg))) |
(equal 0 (prefix-numeric-value current-prefix-arg))) |
1480 |
(arg |
(arg |
1481 |
(if whole-path nil current-prefix-arg)) |
(if whole-name nil current-prefix-arg)) |
1482 |
(regexp |
(regexp |
1483 |
(dired-read-regexp |
(dired-read-regexp |
1484 |
(concat (if whole-path "Path " "") operation " from (regexp): "))) |
(concat (if whole-name "Abs. " "") operation " from (regexp): "))) |
1485 |
(newname |
(newname |
1486 |
(read-string |
(read-string |
1487 |
(concat (if whole-path "Path " "") operation " " regexp " to: ")))) |
(concat (if whole-name "Abs. " "") operation " " regexp " to: ")))) |
1488 |
(list regexp newname arg whole-path))) |
(list regexp newname arg whole-name))) |
1489 |
|
|
1490 |
;;;###autoload |
;;;###autoload |
1491 |
(defun dired-do-rename-regexp (regexp newname &optional arg whole-path) |
(defun dired-do-rename-regexp (regexp newname &optional arg whole-name) |
1492 |
"Rename selected files whose names match REGEXP to NEWNAME. |
"Rename selected files whose names match REGEXP to NEWNAME. |
1493 |
|
|
1494 |
With non-zero prefix argument ARG, the command operates on the next ARG |
With non-zero prefix argument ARG, the command operates on the next ARG |
1505 |
(interactive (dired-mark-read-regexp "Rename")) |
(interactive (dired-mark-read-regexp "Rename")) |
1506 |
(dired-do-create-files-regexp |
(dired-do-create-files-regexp |
1507 |
(function dired-rename-file) |
(function dired-rename-file) |
1508 |
"Rename" arg regexp newname whole-path dired-keep-marker-rename)) |
"Rename" arg regexp newname whole-name dired-keep-marker-rename)) |
1509 |
|
|
1510 |
;;;###autoload |
;;;###autoload |
1511 |
(defun dired-do-copy-regexp (regexp newname &optional arg whole-path) |
(defun dired-do-copy-regexp (regexp newname &optional arg whole-name) |
1512 |
"Copy selected files whose names match REGEXP to NEWNAME. |
"Copy selected files whose names match REGEXP to NEWNAME. |
1513 |
See function `dired-do-rename-regexp' for more info." |
See function `dired-do-rename-regexp' for more info." |
1514 |
(interactive (dired-mark-read-regexp "Copy")) |
(interactive (dired-mark-read-regexp "Copy")) |
1516 |
(dired-do-create-files-regexp |
(dired-do-create-files-regexp |
1517 |
(function dired-copy-file) |
(function dired-copy-file) |
1518 |
(if dired-copy-preserve-time "Copy [-p]" "Copy") |
(if dired-copy-preserve-time "Copy [-p]" "Copy") |
1519 |
arg regexp newname whole-path dired-keep-marker-copy))) |
arg regexp newname whole-name dired-keep-marker-copy))) |
1520 |
|
|
1521 |
;;;###autoload |
;;;###autoload |
1522 |
(defun dired-do-hardlink-regexp (regexp newname &optional arg whole-path) |
(defun dired-do-hardlink-regexp (regexp newname &optional arg whole-name) |
1523 |
"Hardlink selected files whose names match REGEXP to NEWNAME. |
"Hardlink selected files whose names match REGEXP to NEWNAME. |
1524 |
See function `dired-do-rename-regexp' for more info." |
See function `dired-do-rename-regexp' for more info." |
1525 |
(interactive (dired-mark-read-regexp "HardLink")) |
(interactive (dired-mark-read-regexp "HardLink")) |
1526 |
(dired-do-create-files-regexp |
(dired-do-create-files-regexp |
1527 |
(function add-name-to-file) |
(function add-name-to-file) |
1528 |
"HardLink" arg regexp newname whole-path dired-keep-marker-hardlink)) |
"HardLink" arg regexp newname whole-name dired-keep-marker-hardlink)) |
1529 |
|
|
1530 |
;;;###autoload |
;;;###autoload |
1531 |
(defun dired-do-symlink-regexp (regexp newname &optional arg whole-path) |
(defun dired-do-symlink-regexp (regexp newname &optional arg whole-name) |
1532 |
"Symlink selected files whose names match REGEXP to NEWNAME. |
"Symlink selected files whose names match REGEXP to NEWNAME. |
1533 |
See function `dired-do-rename-regexp' for more info." |
See function `dired-do-rename-regexp' for more info." |
1534 |
(interactive (dired-mark-read-regexp "SymLink")) |
(interactive (dired-mark-read-regexp "SymLink")) |
1535 |
(dired-do-create-files-regexp |
(dired-do-create-files-regexp |
1536 |
(function make-symbolic-link) |
(function make-symbolic-link) |
1537 |
"SymLink" arg regexp newname whole-path dired-keep-marker-symlink)) |
"SymLink" arg regexp newname whole-name dired-keep-marker-symlink)) |
1538 |
|
|
1539 |
(defun dired-create-files-non-directory |
(defun dired-create-files-non-directory |
1540 |
(file-creator basename-constructor operation arg) |
(file-creator basename-constructor operation arg) |