Is there a way to do this for both non-Elisp and Elisp? For Elisp, the only thing I can think of is to create a new Dired buffer from a new list of files, but is there a better way?

Note: I want to do this without external dependency.

  • Try out Dired-omit. – Malabarba Oct 27 '14 at 8:18
  • @Tu Do: you've posted a number of questions about dired that all specify that you don't want to introduce external dependencies. That's fine and all, but I'm kind of curious why beyond the general "avoid external dependencies when you can" -- it seems like you might be reinventing a number of wheels. – Dan Oct 27 '14 at 11:50
  • @Dan I need it to contribute to Projectile, specifically this feature. I finished the updating part. I don't want to introduce additional dependency when it's absolutely not necessary, because it will make it more difficult to review. Based on the answer, it seems there's no external package that satisfies my need: to add and update (add more or delete) Dired entries and still preserve state after updating. – Tu Do Oct 27 '14 at 12:12

Mark files (e.g. with m, but there are lots of marking functions), and then remove them with k.

Edit: The scenario in question appears to be a virtual dired buffer (or similar) using a custom source of file listings, and the problem is how, after modifications to the initial dired contents, to refresh the dired buffer without also reverting to the original contents (i.e. how to retain the modifications, even after reverting the dired buffer).

dired-revert (which re-runs the command to generate the original list of files) does remember a bunch of things already, but not killed lines (and one can easily argue that remembering killed lines is a bad idea), but you could provide a custom revert-buffer-function which did remember which lines had been killed.

I suspect if you're creating a dired buffer with custom contents, it's up to you to handle the revert-buffer case with similar custom logic.

  • This is close. But when refreshing, the entries still remain. – Tu Do Oct 27 '14 at 5:12
  • Well yes; that's because refreshing a dired buffer re-runs the original command to create the directory listing. So don't do that. – phils Oct 27 '14 at 5:15
  • So, effectively we have to create a new Dired buffer? Or is there a way to replace that original command? – Tu Do Oct 27 '14 at 5:17
  • It's not clear to me what your use-case is, but perhaps you want find-dired rather than regular dired? – phils Oct 27 '14 at 5:33
  • The use case is here (scroll down a bit). I can create a Dired buffer from arbitrary set of files, but now I want to update it. It is close now, but currently I have to kill buffer and recreate a new Dired buffer from the same name and having bizzare error. – Tu Do Oct 27 '14 at 5:37

dired-narrow may be a good place to look, both for a way to filter dired content interactively and for exploring a method for implementing this in elisp. To do this, it seems that dired-narrow adds the invisible property to lines for files that don't match the search criteria and then deletes these lines.

  • I've edited my question. I don't want to have external dependency. I don't just want to narrow, but actually delete the entries without affecting actual objects the entries represent. – Tu Do Oct 27 '14 at 4:49

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.