diff options
author | Juri Linkov <juri@linkov.net> | 2018-02-06 23:32:08 +0200 |
---|---|---|
committer | Juri Linkov <juri@linkov.net> | 2018-02-06 23:32:08 +0200 |
commit | 03722339060c7654e839d586cd9facc69593ddce (patch) | |
tree | aef39fbba459edd614326931894a5f755dfe3707 /lisp/dired.el | |
parent | 109237e23a01901e70c70c41166ebefc26b1b24f (diff) | |
download | emacs-03722339060c7654e839d586cd9facc69593ddce.tar.gz |
* 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.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r-- | lisp/dired.el | 21 |
1 files changed, 14 insertions, 7 deletions
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)." ;; save-excursion loses, again (dired-move-to-filename))) -(defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked) +(defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked error) "Return the marked files' names as list of strings. The list is in the same order as the buffer, that is, the car is the first marked file. @@ -662,7 +662,10 @@ Optional third argument FILTER, if non-nil, is a function to select If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file, return (t FILENAME) instead of (FILENAME). -Don't use that together with FILTER." +Don't use that together with FILTER. + +If ERROR is non-nil, signal an error when the list of found files is empty. +ERROR can be a string with the error message." (let ((all-of-them (save-excursion (delq nil (dired-map-over-marks @@ -672,13 +675,17 @@ Don't use that together with FILTER." (when (equal all-of-them '(t)) (setq all-of-them nil)) (if (not filter) - (if (and distinguish-one-marked (eq (car all-of-them) t)) - all-of-them - (nreverse all-of-them)) + (setq result + (if (and distinguish-one-marked (eq (car all-of-them) t)) + all-of-them + (nreverse all-of-them))) (dolist (file all-of-them) (if (funcall filter file) - (push file result))) - result))) + (push file result)))) + (when (and (null result) error) + (user-error (if (stringp error) error "No files specified"))) + result)) + ;; The dired command |