all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: <mafeusek@gmail.com>, "'emacs mailing list'" <help-gnu-emacs@gnu.org>
Subject: RE: To Drew Adams?: `dired-get-marked-files' returns error when not onfile
Date: Tue, 6 Jul 2010 14:10:05 -0700	[thread overview]
Message-ID: <FC6BBF10F49044C8A8F9F1F2A5AB7A6A@us.oracle.com> (raw)
In-Reply-To: <umt41vbgz6br.fsf@gmail.com>

> 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.  

(defun my-dired-get-marked-files
 (&optional localp arg filter distinguish-one-marked)
 "Mine."
  (condition-case nil
      (dired-get-marked-files localp arg filter
                              distinguish-one-marked)
    (error nil)))

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.




  parent reply	other threads:[~2010-07-06 21:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-06 20:46 To Drew Adams?: `dired-get-marked-files' returns error when not on file mafeusek
2010-07-06 20:58 ` Deniz Dogan
2010-07-06 21:10 ` Drew Adams [this message]
2010-07-07 16:39   ` To Drew Adams?: `dired-get-marked-files' returns error when notonfile Drew Adams
2010-07-08  7:27   ` To Drew Adams?: `dired-get-marked-files' returns error when not onfile mafeusek
2010-07-08 13:32     ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FC6BBF10F49044C8A8F9F1F2A5AB7A6A@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mafeusek@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.