3

There is a project with 100 files in a flat directory. I want to navigate a subset of the files, depending on what part of the project I am working on. Creating files with links to files of interest would do the job. For example, To navigate alphabet files of project, open alphabet.org:

file:fA.cpp
file:fB.cpp
file:fC.cpp

To navigate number files of project, open numbers.org:

file:f1.cpp
file:f2.cpp
file:f3.cpp

Does Dired or Ranger have a similar functionality?

This might be what Lorefnon is describing, but I don't know enough Emacs to understand it: quote from https://lorefnon.me/2015/11/15/utilities-for-efficient-filesystem-navigation-in-emacs.html

Dired buffers can be bookmarked just like ordinary buffers and we can use bookmark-jump to quickly jump to important Dired buffers opened before

I am using Emacs 25.2.1 with Evil Spacemacs and Ivy; but haven't learned Dired or Ranger yet.

UPDATE

I went with Drew's Dired+ and it works well. It lets you open Dired for an arbitrary set of files.

On Spacemacs, add dired+ to your dotspacemacs-additional-packages list.

From diredp-dired-plus-help:

C-x D A      Add files to a Dired buffer.
             You are prompted for the Dired buffer name and for each file or dir to include.

Usage with Spacemacs:

SPC f c      (spacemacs/copy-file) Write the file under new name.
             Saves Dired buffer to a file.
SPC f s      (save-buffer) Save current buffer in visited file if modified.
             Does not save Dired buffer to file unless it's a visited file.
  • I've never done this but you can look at projectile. Maybe you can create multiple projects and switch projectile projects based on organizational preferences. Then use projectile-switch-project and projectile-find-file – eflanigan00 Sep 11 '17 at 2:56
  • 3
    Please write a more informative question title. – Dan Sep 11 '17 at 11:44
2

Not exactly sure what you're asking, but perhaps this will help. Offhand, a guess is that bookmarking Dired buffers is close to what you are looking for.

  1. Dired itself lets you have a Dired buffer that contains (only) a given set of files and directories - from anywhere in your file system. You do this by passing a list of them to function dired. See C-h f dired.

  2. You can mark a set of files and subdirs in a Dired buffer, and then act on them in arbitrary or predefined ways. Such a set of marked files can represent the files in a given project, for instance.

  3. You can hide the marked files and subdirs in Dired. This can give you a "project" view of a larger set of files.

  4. Dired+ can make these Dired things easier. It also lets you easily combine arbitrary Dired listings (e.g. subprojects) and otherwise add to Dired listings, search, including recursively, and more.

  5. If you use library Bookmark+ then you can bookmark Dired buffers, and return to them later. Bookmarking records all markings, which files are hidden, etc. So after configuring a given Dired buffer the way you want, to represent the files and dirs of a project, for example, you can bookmark that configured state - and restore it later just by "jumping" to that bookmark. You can have any number of bookmarks to the same Dired buffer, representing different views of it - different subsets etc.

  6. Bookmark+ also provides many other ways to support defining and managing projects as sets of files. Just search for "project" here, to get an idea.

  7. Library Icicles also provides various kinds of support for projects

  • Thanks Drew. I don't completely understand, but it sounds good enough for me to learn Dired and Bookmark, and maybe Dired+ and Bookrmark+. If it works I will accept your answer, but it may take me a few days. – wolfv Sep 11 '17 at 2:21
  • I'm sure you will get other suggestions here. There is no hurry to try or decide on this or that. Get acquainted with various ways to organize files etc. Also, this question is a bit broad, because at this point you are looking for ideas about what is available. Future, more-specific questions will likely get more (specifically) helpful answers. – Drew Sep 11 '17 at 3:30
  • How to install Dired+? M-x diredp-dired-plus-help is not on my Spacemacs. And there are no install instructions on emacswiki.org/emacs/DiredPlus – wolfv Sep 12 '17 at 3:42
  • Found the Dired+ install instructions on wikemacs.org/wiki/Dired%2B , the installer then said: Status: Available Obsolete from melpa -- Install Archive: melpa Version: 20170818.1411 – wolfv Sep 12 '17 at 5:14
  • No idea what that means. I'd say maybe ignore wikemacs.org (which itself is obsolete, if I remember right). The latest of my libraries is always on Emacs Wiki, and from there it is mirrored automatically to MELPA. You should be able to get Dired+ from either dired+.el or MELPA. In the latest you see this in the file header: "Last-Updated: Fri Aug 18 14:10:39 2017 (-0700)" and this: "Update #: 10354". The doc page, with a link to the source code, is here. – Drew Sep 12 '17 at 14:09
2

fA.cpp
fB.cpp
fC.cpp

No-frills approach in Dired:

  • %m f[A-Z]\.cpp RET to mark files
  • t to invert the marks
  • k to hide the marked files
1

Install https://github.com/technomancy/find-file-in-project (available at http://melpa.org)

  • M-x find-file-in-current-directory or find-file-in-project-by-selected or find-file-in-project

  • you got interactive UI to filter candidates. The UI is based on ivy (https://github.com/abo-abo/swiper), so you could input keyword1 keyword2 to tweak the final result (Please note space is converted to regex ".*" by ivy)

  • Press C-c C-o to output the file list to a new buffer. Done!

Now you can press ENTER key on any item of that file list to open a file

BTW, ivy supports more advanced syntax (like negative pattern), for example keyword1 !keyword2 keyword3 corresponds to grep keyword1 | grep -v keyword2 | grep -v keyword3

Other solutions:

  • M-x find-name-dired, same backend (GNU Find) as find-file-in-project but UI is different

  • M-x find-lisp-find-dired, pure lisp implementation. Slower but works out of box (If you use Emacs on Windows, this might be the only solution to search file name containing East Asian character).

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.