diff options
| author | Juri Linkov | 2018-02-06 23:32:08 +0200 |
|---|---|---|
| committer | Juri Linkov | 2018-02-06 23:32:08 +0200 |
| commit | 03722339060c7654e839d586cd9facc69593ddce (patch) | |
| tree | aef39fbba459edd614326931894a5f755dfe3707 | |
| parent | 109237e23a01901e70c70c41166ebefc26b1b24f (diff) | |
| download | emacs-03722339060c7654e839d586cd9facc69593ddce.tar.gz emacs-03722339060c7654e839d586cd9facc69593ddce.zip | |
* lisp/dired.el (dired-get-marked-files): Add new optional arg 'error'.
Call user-error when it's non-nil and result is empty (bug#30285).
* lisp/dired-aux.el (dired-do-chxxx, dired-do-chmod)
(dired-do-print, dired-do-async-shell-command)
(dired-do-shell-command, dired-do-compress-to)
(dired-mark-confirm, dired-do-create-files)
(dired-do-isearch, dired-do-isearch-regexp)
(dired-do-query-replace-regexp, dired-do-find-regexp):
* lisp/dired-x.el (dired-do-find-marked-files):
Set arg 'error' of dired-get-marked-files call to t.
| -rw-r--r-- | lisp/dired-aux.el | 24 | ||||
| -rw-r--r-- | lisp/dired-x.el | 3 | ||||
| -rw-r--r-- | lisp/dired.el | 21 |
3 files changed, 28 insertions, 20 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 55b68a372e3..6e3e3360099 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el | |||
| @@ -301,7 +301,7 @@ List has a form of (file-name full-file-name (attribute-list))." | |||
| 301 | ;; PROGRAM is the program used to change the attribute. | 301 | ;; PROGRAM is the program used to change the attribute. |
| 302 | ;; OP-SYMBOL is the type of operation (for use in `dired-mark-pop-up'). | 302 | ;; OP-SYMBOL is the type of operation (for use in `dired-mark-pop-up'). |
| 303 | ;; ARG describes which files to use, as in `dired-get-marked-files'. | 303 | ;; ARG describes which files to use, as in `dired-get-marked-files'. |
| 304 | (let* ((files (dired-get-marked-files t arg)) | 304 | (let* ((files (dired-get-marked-files t arg nil nil t)) |
| 305 | ;; The source of default file attributes is the file at point. | 305 | ;; The source of default file attributes is the file at point. |
| 306 | (default-file (dired-get-filename t t)) | 306 | (default-file (dired-get-filename t t)) |
| 307 | (default (when default-file | 307 | (default (when default-file |
| @@ -361,7 +361,7 @@ Symbolic modes like `g+w' are allowed. | |||
| 361 | Type M-n to pull the file attributes of the file at point | 361 | Type M-n to pull the file attributes of the file at point |
| 362 | into the minibuffer." | 362 | into the minibuffer." |
| 363 | (interactive "P") | 363 | (interactive "P") |
| 364 | (let* ((files (dired-get-marked-files t arg)) | 364 | (let* ((files (dired-get-marked-files t arg nil nil t)) |
| 365 | ;; The source of default file attributes is the file at point. | 365 | ;; The source of default file attributes is the file at point. |
| 366 | (default-file (dired-get-filename t t)) | 366 | (default-file (dired-get-filename t t)) |
| 367 | (modestr (when default-file | 367 | (modestr (when default-file |
| @@ -476,7 +476,7 @@ Uses the shell command coming from variables `lpr-command' and | |||
| 476 | `lpr-switches' as default." | 476 | `lpr-switches' as default." |
| 477 | (interactive "P") | 477 | (interactive "P") |
| 478 | (require 'lpr) | 478 | (require 'lpr) |
| 479 | (let* ((file-list (dired-get-marked-files t arg)) | 479 | (let* ((file-list (dired-get-marked-files t arg nil nil t)) |
| 480 | (lpr-switches | 480 | (lpr-switches |
| 481 | (if (and (stringp printer-name) | 481 | (if (and (stringp printer-name) |
| 482 | (string< "" printer-name)) | 482 | (string< "" printer-name)) |
| @@ -666,7 +666,7 @@ In shell syntax this means separating the individual commands with `;'. | |||
| 666 | 666 | ||
| 667 | The output appears in the buffer `*Async Shell Command*'." | 667 | The output appears in the buffer `*Async Shell Command*'." |
| 668 | (interactive | 668 | (interactive |
| 669 | (let ((files (dired-get-marked-files t current-prefix-arg))) | 669 | (let ((files (dired-get-marked-files t current-prefix-arg nil nil t))) |
| 670 | (list | 670 | (list |
| 671 | ;; Want to give feedback whether this file or marked files are used: | 671 | ;; Want to give feedback whether this file or marked files are used: |
| 672 | (dired-read-shell-command "& on %s: " current-prefix-arg files) | 672 | (dired-read-shell-command "& on %s: " current-prefix-arg files) |
| @@ -727,7 +727,7 @@ can be produced by `dired-get-marked-files', for example." | |||
| 727 | ;;Functions dired-run-shell-command and dired-shell-stuff-it do the | 727 | ;;Functions dired-run-shell-command and dired-shell-stuff-it do the |
| 728 | ;;actual work and can be redefined for customization. | 728 | ;;actual work and can be redefined for customization. |
| 729 | (interactive | 729 | (interactive |
| 730 | (let ((files (dired-get-marked-files t current-prefix-arg))) | 730 | (let ((files (dired-get-marked-files t current-prefix-arg nil nil t))) |
| 731 | (list | 731 | (list |
| 732 | ;; Want to give feedback whether this file or marked files are used: | 732 | ;; Want to give feedback whether this file or marked files are used: |
| 733 | (dired-read-shell-command "! on %s: " current-prefix-arg files) | 733 | (dired-read-shell-command "! on %s: " current-prefix-arg files) |
| @@ -1030,7 +1030,7 @@ Prompt for the archive file name. | |||
| 1030 | Choose the archiving command based on the archive file-name extension | 1030 | Choose the archiving command based on the archive file-name extension |
| 1031 | and `dired-compress-files-alist'." | 1031 | and `dired-compress-files-alist'." |
| 1032 | (interactive) | 1032 | (interactive) |
| 1033 | (let* ((in-files (dired-get-marked-files)) | 1033 | (let* ((in-files (dired-get-marked-files nil nil nil nil t)) |
| 1034 | (out-file (expand-file-name (read-file-name "Compress to: "))) | 1034 | (out-file (expand-file-name (read-file-name "Compress to: "))) |
| 1035 | (rule (cl-find-if | 1035 | (rule (cl-find-if |
| 1036 | (lambda (x) | 1036 | (lambda (x) |
| @@ -1153,7 +1153,7 @@ Return nil if no change in files." | |||
| 1153 | ;; Pass t for DISTINGUISH-ONE-MARKED so that a single file which | 1153 | ;; Pass t for DISTINGUISH-ONE-MARKED so that a single file which |
| 1154 | ;; is marked pops up a window. That will help the user see | 1154 | ;; is marked pops up a window. That will help the user see |
| 1155 | ;; it isn't the current line file. | 1155 | ;; it isn't the current line file. |
| 1156 | (let ((files (dired-get-marked-files t arg nil t)) | 1156 | (let ((files (dired-get-marked-files t arg nil t t)) |
| 1157 | (string (if (eq op-symbol 'compress) "Compress or uncompress" | 1157 | (string (if (eq op-symbol 'compress) "Compress or uncompress" |
| 1158 | (capitalize (symbol-name op-symbol))))) | 1158 | (capitalize (symbol-name op-symbol))))) |
| 1159 | (dired-mark-pop-up nil op-symbol files #'y-or-n-p | 1159 | (dired-mark-pop-up nil op-symbol files #'y-or-n-p |
| @@ -1845,7 +1845,7 @@ Optional arg HOW-TO determines how to treat the target. | |||
| 1845 | The rest of into-dir are optional arguments. | 1845 | The rest of into-dir are optional arguments. |
| 1846 | For any other return value, TARGET is treated as a directory." | 1846 | For any other return value, TARGET is treated as a directory." |
| 1847 | (or op1 (setq op1 operation)) | 1847 | (or op1 (setq op1 operation)) |
| 1848 | (let* ((fn-list (dired-get-marked-files nil arg)) | 1848 | (let* ((fn-list (dired-get-marked-files nil arg nil nil t)) |
| 1849 | (rfn-list (mapcar #'dired-make-relative fn-list)) | 1849 | (rfn-list (mapcar #'dired-make-relative fn-list)) |
| 1850 | (dired-one-file ; fluid variable inside dired-create-files | 1850 | (dired-one-file ; fluid variable inside dired-create-files |
| 1851 | (and (consp fn-list) (null (cdr fn-list)) (car fn-list))) | 1851 | (and (consp fn-list) (null (cdr fn-list)) (car fn-list))) |
| @@ -2799,14 +2799,14 @@ is part of a file name (i.e., has the text property `dired-filename')." | |||
| 2799 | "Search for a string through all marked files using Isearch." | 2799 | "Search for a string through all marked files using Isearch." |
| 2800 | (interactive) | 2800 | (interactive) |
| 2801 | (multi-isearch-files | 2801 | (multi-isearch-files |
| 2802 | (dired-get-marked-files nil nil 'dired-nondirectory-p))) | 2802 | (dired-get-marked-files nil nil 'dired-nondirectory-p nil t))) |
| 2803 | 2803 | ||
| 2804 | ;;;###autoload | 2804 | ;;;###autoload |
| 2805 | (defun dired-do-isearch-regexp () | 2805 | (defun dired-do-isearch-regexp () |
| 2806 | "Search for a regexp through all marked files using Isearch." | 2806 | "Search for a regexp through all marked files using Isearch." |
| 2807 | (interactive) | 2807 | (interactive) |
| 2808 | (multi-isearch-files-regexp | 2808 | (multi-isearch-files-regexp |
| 2809 | (dired-get-marked-files nil nil 'dired-nondirectory-p))) | 2809 | (dired-get-marked-files nil nil 'dired-nondirectory-p nil t))) |
| 2810 | 2810 | ||
| 2811 | ;;;###autoload | 2811 | ;;;###autoload |
| 2812 | (defun dired-do-search (regexp) | 2812 | (defun dired-do-search (regexp) |
| @@ -2827,7 +2827,7 @@ with the command \\[tags-loop-continue]." | |||
| 2827 | (query-replace-read-args | 2827 | (query-replace-read-args |
| 2828 | "Query replace regexp in marked files" t t))) | 2828 | "Query replace regexp in marked files" t t))) |
| 2829 | (list (nth 0 common) (nth 1 common) (nth 2 common)))) | 2829 | (list (nth 0 common) (nth 1 common) (nth 2 common)))) |
| 2830 | (dolist (file (dired-get-marked-files nil nil 'dired-nondirectory-p)) | 2830 | (dolist (file (dired-get-marked-files nil nil 'dired-nondirectory-p nil t)) |
| 2831 | (let ((buffer (get-file-buffer file))) | 2831 | (let ((buffer (get-file-buffer file))) |
| 2832 | (if (and buffer (with-current-buffer buffer | 2832 | (if (and buffer (with-current-buffer buffer |
| 2833 | buffer-read-only)) | 2833 | buffer-read-only)) |
| @@ -2851,7 +2851,7 @@ REGEXP should use constructs supported by your local `grep' command." | |||
| 2851 | (require 'grep) | 2851 | (require 'grep) |
| 2852 | (defvar grep-find-ignored-files) | 2852 | (defvar grep-find-ignored-files) |
| 2853 | (defvar grep-find-ignored-directories) | 2853 | (defvar grep-find-ignored-directories) |
| 2854 | (let* ((files (dired-get-marked-files)) | 2854 | (let* ((files (dired-get-marked-files nil nil nil nil t)) |
| 2855 | (ignores (nconc (mapcar | 2855 | (ignores (nconc (mapcar |
| 2856 | (lambda (s) (concat s "/")) | 2856 | (lambda (s) (concat s "/")) |
| 2857 | grep-find-ignored-directories) | 2857 | grep-find-ignored-directories) |
diff --git a/lisp/dired-x.el b/lisp/dired-x.el index a90f1f4adcd..fa36083e14e 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el | |||
| @@ -1335,7 +1335,8 @@ displayed this way is restricted by the height of the current window and | |||
| 1335 | To keep Dired buffer displayed, type \\[split-window-below] first. | 1335 | To keep Dired buffer displayed, type \\[split-window-below] first. |
| 1336 | To display just marked files, type \\[delete-other-windows] first." | 1336 | To display just marked files, type \\[delete-other-windows] first." |
| 1337 | (interactive "P") | 1337 | (interactive "P") |
| 1338 | (dired-simultaneous-find-file (dired-get-marked-files) noselect)) | 1338 | (dired-simultaneous-find-file (dired-get-marked-files nil nil nil nil t) |
| 1339 | noselect)) | ||
| 1339 | 1340 | ||
| 1340 | (defun dired-simultaneous-find-file (file-list noselect) | 1341 | (defun dired-simultaneous-find-file (file-list noselect) |
| 1341 | "Visit all files in FILE-LIST and display them simultaneously. | 1342 | "Visit all files in FILE-LIST and display them simultaneously. |
diff --git a/lisp/dired.el b/lisp/dired.el index eade11bc7f4..ef069d23453 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -645,7 +645,7 @@ marked file, return (t FILENAME) instead of (FILENAME)." | |||
| 645 | ;; save-excursion loses, again | 645 | ;; save-excursion loses, again |
| 646 | (dired-move-to-filename))) | 646 | (dired-move-to-filename))) |
| 647 | 647 | ||
| 648 | (defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked) | 648 | (defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked error) |
| 649 | "Return the marked files' names as list of strings. | 649 | "Return the marked files' names as list of strings. |
| 650 | The list is in the same order as the buffer, that is, the car is the | 650 | The list is in the same order as the buffer, that is, the car is the |
| 651 | first marked file. | 651 | first marked file. |
| @@ -662,7 +662,10 @@ Optional third argument FILTER, if non-nil, is a function to select | |||
| 662 | 662 | ||
| 663 | If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file, | 663 | If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file, |
| 664 | return (t FILENAME) instead of (FILENAME). | 664 | return (t FILENAME) instead of (FILENAME). |
| 665 | Don't use that together with FILTER." | 665 | Don't use that together with FILTER. |
| 666 | |||
| 667 | If ERROR is non-nil, signal an error when the list of found files is empty. | ||
| 668 | ERROR can be a string with the error message." | ||
| 666 | (let ((all-of-them | 669 | (let ((all-of-them |
| 667 | (save-excursion | 670 | (save-excursion |
| 668 | (delq nil (dired-map-over-marks | 671 | (delq nil (dired-map-over-marks |
| @@ -672,13 +675,17 @@ Don't use that together with FILTER." | |||
| 672 | (when (equal all-of-them '(t)) | 675 | (when (equal all-of-them '(t)) |
| 673 | (setq all-of-them nil)) | 676 | (setq all-of-them nil)) |
| 674 | (if (not filter) | 677 | (if (not filter) |
| 675 | (if (and distinguish-one-marked (eq (car all-of-them) t)) | 678 | (setq result |
| 676 | all-of-them | 679 | (if (and distinguish-one-marked (eq (car all-of-them) t)) |
| 677 | (nreverse all-of-them)) | 680 | all-of-them |
| 681 | (nreverse all-of-them))) | ||
| 678 | (dolist (file all-of-them) | 682 | (dolist (file all-of-them) |
| 679 | (if (funcall filter file) | 683 | (if (funcall filter file) |
| 680 | (push file result))) | 684 | (push file result)))) |
| 681 | result))) | 685 | (when (and (null result) error) |
| 686 | (user-error (if (stringp error) error "No files specified"))) | ||
| 687 | result)) | ||
| 688 | |||
| 682 | 689 | ||
| 683 | ;; The dired command | 690 | ;; The dired command |
| 684 | 691 | ||