2

I have an existing dired buffer created of arbitrary files (basically as described here). How could I add additional files to this existing buffer?

The files may, or may not, be in the same directory as any files in the existing dired buffer.

3

See command diredp-dired-union (bound to C-x D, aka C-x S-d) from Dired+. The doc string:

diredp-dired-union is an interactive compiled Lisp function in `dired+.el'.

(diredp-dired-union DIRBUFS &optional SWITCHES)

Create a Dired buffer that is the union of some existing Dired buffers.
With a prefix arg, read `ls' switches.
You are prompted for the Dired buffers.  Use `C-g' when done choosing
them.  Then you are prompted for the name of the new Dired buffer.
Its `default-directory' is the same as the `default-directory' before
invoking the command.

The selected Dired listings are included in the order that you choose
them, and each entry is listed only once in the new Dired buffer.  The
new Dired listing respects the markings, subdirectory insertions, and
hidden subdirectories of the selected Dired listings.

However, in case of conflict between marked or unmarked status for the
same entry, the entry is marked.  Similarly, in case of conflict over
an included subdirectory between it being hidden or shown, it is
hidden, but its contained files are also listed.

Update, in reply to your comment question -

Yes, for now you need to first open a new Dired buffer with only the file(s) to add. You can do that by providing a non-positive prefix arg (e.g. C--) to dired (e.g. C-- C-x 4 d). (You are prompted for the files to list.) Then use diredp-dired-union to combine that Dired listing with any other Dired listings.

I've been intending to add a command that does just what you request, directly, but haven't gotten around to it yet. (Maybe this will incite me to do so, when I get a moment.) I have this in my TODO list:

Add command to add files/dirs to the current Dired buffer. Use code similar to diredp-dired-union-1. It just needs to call dired, passing a cons of:

  1. The current buffer name (might need to kill it first).
  2. The current default-directory plus the newly read files/dirs.

Or if the current listing was already from a cons (how to know: dired-directory is a cons or not) then just append the newly read files/dirs.

This should be simple to do; I just haven't gotten around to it. For now, just add files to a new Dired buffer and then union that with your other Dired buffer.


UPDATE #2

I've added such commands now.

  • Commands diredp-add-to-dired-buffer and diredp-add-to-dired-buffer-other-window, bound globally to C-x E and C-x 4 E, let you add arbitrary file and directory names to an existing Dired buffer.

  • Commands diredp-dired-union and diredp-dired-union-other-window, bound globally to C-x D and C-x 4 D (mentioned above), now also let you add arbitrary file and dir names (in addition to unioning Dired buffers), if you use a non-positive prefix argument (e.g. C--).

  • Thanks, I don't have dired+ installed to test but would this require two dired buffers? That's how I'm reading it. I would prefer to be able to add it based only on a full path if possible? – tosh Jan 30 '15 at 15:07
  • Great, thanks for the update. I think it would be a great feature to have. I use it to have quick access to files related to a particular task I'm working on when they are spread out across large projects. I currently use a "scratch" org-mode file. It works but is not ideal. – tosh Jan 30 '15 at 16:00
  • I've added this feature to Dired+ now - you can now add arbitrary files to a Dired buffer. I updated the answer above. See Dired+ for more information about the behavior. – Drew Feb 3 '15 at 5:18
0

The variable dired-directory basically holds the value of the DIRNAME argument in

(dired DIRNAME &optional SWITCHES)

, which you can manipulate at will. Don't forget to revert the buffer afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.