Mercurial > emacs
comparison lisp/dired.el @ 62373:6b68d72075c1
(dired-map-over-marks): New arg distinguish-one-marked.
(dired-get-marked-files): New arg distinguish-one-marked.
(dired-mark-pop-up): Handle FILES = (t FILE) specially.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 15 May 2005 21:33:25 +0000 |
parents | d64b656073ca |
children | af763a03ded2 |
comparison
equal
deleted
inserted
replaced
62372:4560134d21fa | 62373:6b68d72075c1 |
---|---|
448 (if (eq dired-marker-char ?\040) "un" "") | 448 (if (eq dired-marker-char ?\040) "un" "") |
449 (if (eq dired-marker-char dired-del-marker) | 449 (if (eq dired-marker-char dired-del-marker) |
450 "flagged" "marked")))) | 450 "flagged" "marked")))) |
451 (and (> count 0) count))) | 451 (and (> count 0) count))) |
452 | 452 |
453 (defmacro dired-map-over-marks (body arg &optional show-progress) | 453 (defmacro dired-map-over-marks (body arg &optional show-progress |
454 distinguish-one-marked) | |
454 "Eval BODY with point on each marked line. Return a list of BODY's results. | 455 "Eval BODY with point on each marked line. Return a list of BODY's results. |
455 If no marked file could be found, execute BODY on the current line. | 456 If no marked file could be found, execute BODY on the current line. |
456 If ARG is an integer, use the next ARG (or previous -ARG, if ARG<0) | 457 If ARG is an integer, use the next ARG (or previous -ARG, if ARG<0) |
457 files instead of the marked files. | 458 files instead of the marked files. |
458 In that case point is dragged along. This is so that commands on | 459 In that case point is dragged along. This is so that commands on |
463 No guarantee is made about the position on the marked line. | 464 No guarantee is made about the position on the marked line. |
464 BODY must ensure this itself if it depends on this. | 465 BODY must ensure this itself if it depends on this. |
465 Search starts at the beginning of the buffer, thus the car of the list | 466 Search starts at the beginning of the buffer, thus the car of the list |
466 corresponds to the line nearest to the buffer's bottom. This | 467 corresponds to the line nearest to the buffer's bottom. This |
467 is also true for (positive and negative) integer values of ARG. | 468 is also true for (positive and negative) integer values of ARG. |
468 BODY should not be too long as it is expanded four times." | 469 BODY should not be too long as it is expanded four times. |
470 | |
471 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file, | |
472 return (t FILENAME) instead of (FILENAME)." | |
469 ;; | 473 ;; |
470 ;;Warning: BODY must not add new lines before point - this may cause an | 474 ;;Warning: BODY must not add new lines before point - this may cause an |
471 ;;endless loop. | 475 ;;endless loop. |
472 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10. | 476 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10. |
473 `(prog1 | 477 `(prog1 |
503 (goto-char next-position) | 507 (goto-char next-position) |
504 (forward-line 1) | 508 (forward-line 1) |
505 (set-marker next-position nil) | 509 (set-marker next-position nil) |
506 (setq next-position (and (re-search-forward regexp nil t) | 510 (setq next-position (and (re-search-forward regexp nil t) |
507 (point-marker))))) | 511 (point-marker))))) |
512 (if (and ,distinguish-one-marked (= (length results) 1)) | |
513 (setq results (cons t results))) | |
508 (if found | 514 (if found |
509 results | 515 results |
510 (list ,body))))) | 516 (list ,body))))) |
511 ;; save-excursion loses, again | 517 ;; save-excursion loses, again |
512 (dired-move-to-filename))) | 518 (dired-move-to-filename))) |
513 | 519 |
514 (defun dired-get-marked-files (&optional localp arg filter) | 520 (defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked) |
515 "Return the marked files' names as list of strings. | 521 "Return the marked files' names as list of strings. |
516 The list is in the same order as the buffer, that is, the car is the | 522 The list is in the same order as the buffer, that is, the car is the |
517 first marked file. | 523 first marked file. |
518 Values returned are normally absolute file names. | 524 Values returned are normally absolute file names. |
519 Optional arg LOCALP as in `dired-get-filename'. | 525 Optional arg LOCALP as in `dired-get-filename'. |
520 Optional second argument ARG specifies files near point | 526 Optional second argument ARG specifies files near point |
521 instead of marked files. If ARG is an integer, use the next ARG files. | 527 instead of marked files. If ARG is an integer, use the next ARG files. |
522 If ARG is otherwise non-nil, use file. Usually ARG comes from | 528 If ARG is otherwise non-nil, use file. Usually ARG comes from |
523 the command's prefix arg. | 529 the command's prefix arg. |
524 Optional third argument FILTER, if non-nil, is a function to select | 530 Optional third argument FILTER, if non-nil, is a function to select |
525 some of the files--those for which (funcall FILTER FILENAME) is non-nil." | 531 some of the files--those for which (funcall FILTER FILENAME) is non-nil. |
526 (let ((all-of-them | 532 |
527 (save-excursion | 533 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file, |
528 (dired-map-over-marks (dired-get-filename localp) arg))) | 534 return (t FILENAME) instead of (FILENAME). |
529 result) | 535 Don't use that together with FILTER." |
536 (let* ((all-of-them | |
537 (save-excursion | |
538 (dired-map-over-marks | |
539 (dired-get-filename localp) | |
540 arg nil distinguish-one-marked))) | |
541 result) | |
530 (if (not filter) | 542 (if (not filter) |
531 (nreverse all-of-them) | 543 (if (and distinguish-one-marked (eq (car all-of-them) t)) |
544 all-of-them | |
545 (nreverse all-of-them)) | |
532 (dolist (file all-of-them) | 546 (dolist (file all-of-them) |
533 (if (funcall filter file) | 547 (if (funcall filter file) |
534 (push file result))) | 548 (push file result))) |
535 result))) | 549 result))) |
536 | 550 |
2535 | 2549 |
2536 FUNCTION should not manipulate files, just read input | 2550 FUNCTION should not manipulate files, just read input |
2537 (an argument or confirmation). | 2551 (an argument or confirmation). |
2538 The window is not shown if there is just one file or | 2552 The window is not shown if there is just one file or |
2539 OP-SYMBOL is a member of the list in `dired-no-confirm'. | 2553 OP-SYMBOL is a member of the list in `dired-no-confirm'. |
2540 FILES is the list of marked files." | 2554 FILES is the list of marked files. It can also be (t FILENAME) |
2555 in the case of one marked file, to distinguish that from using | |
2556 just the current file." | |
2541 (or bufname (setq bufname " *Marked Files*")) | 2557 (or bufname (setq bufname " *Marked Files*")) |
2542 (if (or (eq dired-no-confirm t) | 2558 (if (or (eq dired-no-confirm t) |
2543 (memq op-symbol dired-no-confirm) | 2559 (memq op-symbol dired-no-confirm) |
2560 ;; If FILES defaulted to the current line's file. | |
2544 (= (length files) 1)) | 2561 (= (length files) 1)) |
2545 (apply function args) | 2562 (apply function args) |
2546 (with-current-buffer (get-buffer-create bufname) | 2563 (with-current-buffer (get-buffer-create bufname) |
2547 (erase-buffer) | 2564 (erase-buffer) |
2548 (dired-format-columns-of-files files) | 2565 ;; Handle (t FILE) just like (FILE), here. |
2566 ;; That value is used (only in some cases), to mean | |
2567 ;; just one file that was marked, rather than the current line file. | |
2568 (dired-format-columns-of-files (if (eq (car files) t) (cdr files) files)) | |
2549 (remove-text-properties (point-min) (point-max) | 2569 (remove-text-properties (point-min) (point-max) |
2550 '(mouse-face nil help-echo nil))) | 2570 '(mouse-face nil help-echo nil))) |
2551 (save-window-excursion | 2571 (save-window-excursion |
2552 (dired-pop-to-buffer bufname) | 2572 (dired-pop-to-buffer bufname) |
2553 (apply function args)))) | 2573 (apply function args)))) |