[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: To Drew Adams?: `dired-get-marked-files' returns error when not onfi
RE: To Drew Adams?: `dired-get-marked-files' returns error when not onfile
Tue, 6 Jul 2010 14:10:05 -0700
> I have the impression `dired-get-marked-files' should return
> nil instead signal an error (or at least parameterised) when
> I am in dired buffer and I am pointing on empty line after all files.
> why? because how can I handle such situation cleanly in elisp code?
In both Dired+ and vanilla Emacs, `dired-get-marked-files' raises an error in
this case. It calls `dired-get-filename', which raises the error because there
is no file listed on that line.
Your question is how to "handle such a situation". But it's not clear what you
mean. What is it that you are trying to do?
Your code can test whether there is a file on the current line in one of these
ways, depending on whether you want to consider `.' and `..' as file names (see
the doc of `dired-get-filename'):
1. Call (dired-get-filename nil 'NO-ERROR-IF-NOT-FILEP)
2. Call `dired-get-filename' inside `condition-case':
(condition-case nil (dired-get-filename) (error nil))
You can also suppress the error in `dired-get-marked-files' and instead return
nil, by wrapping that in `condition-case' the same way.
(&optional localp arg filter distinguish-one-marked)
(dired-get-marked-files localp arg filter
However, the particular error you are concerned about is not distinguished from
any other errors this way: any error condition here will return nil instead of
raising an error.