Is there any ECB (or other)-enhanced find file mojo? - emacs

Can I use ECB (or some other project aware thing, like eproject, ibuffer, etc.) to enhance emacs's find-file goodness?
Imagine this scenario: I have several projects/directories specified in my ecb-source-path, let's call them Project1 and Project2, and they look like so:
Project1
foo.c
bar.c
Project2
foo.c
baz.c
I'd like to have find-file (or another command) work to find and jump to the files there without having to navigate to the ecb directories buffer, or have the buffers open already.
I guess my ideal usage scenario would be like so:
I'd like to C-x C-f baz (or another special command) to open Project2/baz.c. Going even further, I'd love if I could use something like ido's flex matching to get p2foo open Project2/foo.c.
¿C'est posible?

If in your example you are in project1 foo.c, and you want to get to project1 bar.c, I think most of the project tools like ede, eproject, gnu global, idutils integration etc have "jump to file" type commands. I, of course, recommend the CEDET/EDE and ECB combination. The keybinding is C-c . f which is ede-find-file.
Setting up CEDET and EDE is pretty easy, but EDE knows only a small number of different project types, and you may need to configure it for your projects by hand which is less easy.
If you want to be in project1/foo.c and jump to project2/baz.c, you just need to use locate:
M-x locate RET baz.c RET
Now select from the list.

You could use the filecache package to index the directories you want, then use ido to choose a filename from the cache. Here is one example; there are other implementations you can Google for.

Take a look at find-file-in-project. It seems to me you're looking for something similar.

I've written a package find-file-in-tags which enables you to open files in your TAGS file without specifying the path to the file. If there are multiple files that match what you've entered, you're prompted to refine your choice (or open all).
Additionally, if you have multiple work areas for the same project, find-file-in-tags uses a single TAGS file for all those work areas but opens up the file in the same work area as the buffer in which you are invoking find-file-in-tags.

Related

Emacs command to Find and Open File similar to Eclipse

I've recently switched from using Eclipse to emacs. I'm trying to find a way to emulate eclipse's Ctrl-Shft-r functionality which lets you type in a file name and it begins showing all files in the current workspace that begin with the string you are typing.
C-x C-f seems to handle just tab-completion in the current directory, whereas Eclipse's functionality looked through all sub-directories to find matching files.
I'm looking for something (maybe there's a plugin that does this) that allows you to type the name of folder to look in, and then a partial file and returns back the results in a buffer. Possibly that uses auto-complete to list off matching files with their full paths.
First of all, steer clear of vanilla find-file function (that's the interactive function that is run when you hit C-x C-f). It is very limited, it forces you to hit TAB all the time, and the first thing most people do when switching to emacs is replace find-file with something more powefull.
There're a number of alternatives. ido-mode is one, helm is another. The former is light-weight, fast and comes built-in with emacs. The latter is immensely powerful and strives to be fast, too.
Second of all, there're two ways a recursive file search can usually be done:
directory search - that's when you just search a directory, no surprises here;
project search - that's when you setup a project your're working on, thus making emacs aware of which files are of interest to you right now.
For directory search, ido-find-file and helm-find-file are both viable options. Ido does its search automatically when you pause typing; helm uses (C-u) M-g s to activate grep. See this SO question for more info.
For project search, you need a library to manage your projects. Projectile is great for that. Set it up and use C-c p f or C-c p F to list files in current or all of your projects, respectively. Oh, and projectile uses ido by default, but there is helm support, too.
You're looking for projectile which indexes your project's files. I used it for a while but have recently switched to using helm-recentf
(global-set-key "\C-x\ \C-r" 'helm-recentf)
I have recent files set to a large number. Pretty much anything I've ever opened is a few keystrokes away. This even doubles up as a handy way to switch buffers.
(require 'recentf)
(setq recentf-auto-cleanup 'never)
(recentf-mode 1)
(setq recentf-max-saved-items 200)

The equivalent of a GUI "Quick Open" in Emacs on CLI?

The title probably doesn't describe this question well enough. Many GUI-based editors allow you to press a key combination and then start typing a file name (anywhere, in any directory) and as you're typing, a list is filtered down of all the files matching that pattern, in realtime. If you hit enter, the currently highlighted file will be opened, or if you hit the UP or DOWN arrows you can change the selection. For example, in TextMate and Sublime Text 2 (on OS X) this is achieved by hitting CMD+T.
Now I know about find-dired and find-grep in Emacs, but is there anything else available that's a little more instant? The annoying thing with dired is that you have to hit enter and perform the search in order to see if the filename was correct. This is ok if you know the filename, but not so good when you're going based on educated guesses. It seems like something emacs could be suited to. Set the directory to index (just once) then when searching filter the index using a Radix tree search or some such, using a split window to show files and responding to the UP and DOWN arrows to adjust the selection.
Anything out there? :)
ido-mode is perfect for this. It has countless useful applications, including fuzzy filename matching as you demonstrated in your picture.
Some things to get started:
What You Can Learn From ido-mode
EmacsWiki article
Introduction to Ido Mode
Anything.el does this with files and it can do much more. Here's a good introduction on how to use it.
ido-mode is great on its own, but you may find the likes of Find File In Project a better option for matching filename patterns anywhere within a directory tree.
M-x find-file-in-project RET chooses the root of the directory tree automatically (based on the directory-local variables file).
I'm just now noticing that the M-x ffip-find-file-in-dirtree RET which I also have available (and which works on arbitrary specified directory trees, irrespective of project files) is actually provided by the ffip.el included with nxhtml.
The latter also looks like it supports ido when it's enabled. (Actually, there's a bug, but change (if (memq ido-mode '(file 'both)) to (if (memq ido-mode (list 'file 'both)) in (defun ffip-find-file-in-project (file) ...)
There will doubtless be a variety of similar options available.
peepopen also provides this functionality
I found it where I didn't want to :( ...
A plugin, called "Control-P" for vim - provides the exact same functionality the author of the question is looking for.
For example - on this video - http://www.youtube.com/watch?v=YhqsjUUHj6g - go to 26:55, and there you'll find a quick and very clean example of it. So, with one command you point to the doc-root, and after that - you're good to go :) ...
Unfortunately, none of these work the same way :D ...
I've used "Sublime text 2" for a long time TOO ... and yesterday decided to try using "emacs" ("vim" is very uncomfortable). So, I wanted this functionality:
You point to the root folder of a project.
And voila - you have "quick-find" functionality.
But ... there is no such functionality :( ...
(for example - "find-file-in-project" - it requires you to set-up "a file" in the root directory of the project, so it will know that it's the root of your project ... but what if I have to work on several projects simultaneously? ... some of them - use git, some of them - SVN, and some of them - none of these ... :D ... "Sublime text" handle this situation on-the-fly ... but emacs and vim - no :( ...)
Still waiting for the answer though ...

How to find a file in Emacs without known exact directory?

In vim it's very easy to find a file without knowing which directory the file is in. Doing this ":args **/file.hpp" if the file exists, it will get it open.
Is there any substitution in Emacs to do so? The find-file seems work for wildcards, but it doesn't do the tricky like vim does with **.
M-x find-name-dired looks like what You want (You will be prompted for root directory to start search with and a file mask)
A more blunt but still handy tool: M-x locate
Using OS X? This makes emacs use spotlight instead of the standard locate:
(setq locate-command "mdfind")
A good tip if you use ido-find-file:
From a known root directory, you can use ido-wide-find-file-or-pop-dir, which by default is bound to M-f.
FindFileInProject may also be worth looking at.
In Icicles you can find files by matching not just the relative file name but any parts of the path. You can use substring, regexp, and fuzzy matching. You can AND together multiple search patterns (progressive completion). See multi-command icicle-locate-file. And you can even search against file contents, as well as or instead of file name.
http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input
I like
M-x ifind /some/path/to/start/file.hpp
or just
M-x ifind file.hpp
using the ifind package found here. Note: it does open up a *ifind* buffer which displays the results, which you can either select with the mouse, or navigate using C-x ` (aka M-x next-error).

Is there a function in Emacs to search the filesystem for a file by its name?

I want to open a file that is somewhere deep in my project tree. I know the name of the file, however I don't want to go searching the tree for it. I would like a way to enter just the file name, and have emacs search for me. I should also be able to enter the base directory I want to start the search from, and emacs should remember that for future searches.
Sounds like you are looking for the equivalent of Textmate's Command-T functionality. The closest I have found for emacs is find-file-in-project. It can be bound to C-t or a similar key for convenience: (global-set-key "\C-t" 'ido-find-file-in-tag-files)
M-x find-name-dired is the built-in solution for this. The default directory changes according to the current buffer, but the minibuffer history contains the previous selections.
I happen to like the ifind.el package which can be downloaded from the emacswiki here.
In Icicles you can find files by matching not just the relative file name but any parts of the path. You can use substring, regexp, and fuzzy matching. You can AND together multiple search patterns (progressive completion). See multi-command icicle-locate-file.
http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input

Is there a feature in Emacs for function call hierarchy

I am maintaining someone else's code. The code is written in C using GCC 4.4.3 on Linux platform. However, the code jumps around a lot and its difficult to find out where all the functions are called from.
In Visual Studio, there is a feature called 'Call Hierarchy' which will display where functions are called from and called to. Does Emacs (23.1.1) have any such feature?
The classic Emacs way to jump to calls is to use TAGS file and use the M-. command. I recommend using Exuberant C Tags with the following command in the root directory of your project :
ctags -e --c-kinds=+pxd -R .
Then using visit-tags-table you can open the TAGS file. With M-. you can jump to each definition or call to your keyword. Use C-u M-. to jump to another occurrence. Use C-x z z z... to repeat the search.
If you have many projects, you can create a TAGS file for each one of them and then call visit-tags-file to add the TAGS file to your list of TAGS files to search from.
Another classic way (the un*x way), is to use the command M-x find-grep to search for occurrences of your keyword.
http://cedet.sourceforge.net/symref.shtml