Emacs: what are good tactics for navigating directories and opening files? - emacs

Last week, infuriated (again) by having to cope with different IDEs for R and Perl, neither of which I like or use enough to get really comfortable in, I decided to try Emacs. This decision was not made without a certain trepidation on my part. My main use is for Perl with cperl and for R with ESS. My environment is Windows 7 Ultimate 64-bit and I am running v23.4.1, which I think is what the ESS package installed on my behalf.
Nearly a week in and so far it has been surprisingly painless, no more involved than any other significant piece of software. I have remapped my ctrl key to caps-lock, changed default folders, messed around with .emacs and made some additions such as auto-install, yasnippet, color-theme, icicles and a few others. Clearly there is some very sophisticated stuff out there. In addition of course certain features of base Emacs are immediately very powerful and useful, such as isearching up and down. On the whole I have been pleasantly surprised and reassured.
One thing that is cruder than I was expecting is the process of finding and opening files. After a cursory read of various tutorials I had this image of quasi-magical file location and filename auto-completion. The main directories in my setup have paths like g:/roaming/code/perl or g:/roaming/code/R/ but I often need to branch into completely different paths like g:/pricedata/support files/sector/project01/ and so on.
Currently I laboriously delete the file path when I need to take a different fork, then use auto-complete to move deeper into that branch of the filesystem. It kinda takes me back to running a bash shell on the Amiga twenty years ago.
What had I expected? Something like (using the above example) typing 'project01' to skip immediately into the folder at the bottom of the path. For some reason I had got the idea in my head that Emacs would preload directories. So maybe this wasn't realistic.
My guess is that my difficulties probably stem from my own lack of familiarity rather than a structural shortcoming in Emacs and leads on to my questions. I can't complain that there is not enough documentation; rather there is abundant information that it is scattered around rather haphazardly. Icicles has a similar problem - if anything there's too much.
1) What is the best tactic for moving around different branches of the file tree when trying to open files in the minibuffer or using some other method? Are there aliases that can be used to shortcut from one place to another or can one specify directories to be preloaded? Do people just cd around a lot? Or am I coming at this from completely the wrong angle and need to adopt a different strategy?
2) With additional setup, can auto-complete be used to find files in (say) the project01 directly above by prefixing with wildcards etc? What should I focus on to become more efficient here? Am I not tapping the power of add-ons like icicles, anything etc?
I realise these questions veer dangerously close the deprecated category of not having clear answers. My defence is that some tips/guidance at this stage before I commit myself to bad habits or a poor long-term solution would be welcome and I suspect the answers will benefit others who might be considering the switch. I am happy to withdraw or rephrase if there are problems.

helm (formerly known as anything) might suit you. You can install it manually, or using a auto-install extension.
For the auto-install way: download it, put in Your load-path, then add to .emacs:
(add-to-list 'load-path "~/.emacs.d/site-lisp/auto-install")
(require 'auto-install)
(setq auto-install-directory "~/.emacs.d/site-lisp/auto-install/")
Then do M-x auto-install-batch anything. After that is done, put in .emacs:
(require 'anything)
(require 'anything-match-plugin)
(require 'anything-config)
(require 'anything-show-completion)
Then do M-x anything for anything.
Also give a try to ECB (stands for Emacs Code Browser). If you're on Linux, you probably have it available in a standard repository.

You could benefit from using ido-mode, which greatly enhances autocompletion nearly everywhere in emacs (especially when finding files or buffers)
(setq ido-enable-flex-matching t
ido-auto-merge-work-directories-length -1
ido-create-new-buffer 'always
ido-use-filename-at-point 'guess
ido-everywhere t
ido-default-buffer-method 'selected-window)
(ido-mode 1)
(put 'ido-exit-minibuffer 'disabled nil)
(when (require 'ido-ubiquitous nil t)
(ido-ubiquitous-mode 1))
While this might help you quickly finding files "not far away", it probably won't help you much finding files in entirely different locations.
If find that one way to begin tackling this problem is using recentf-mode to quickly jump to recent locations (if you have only a small number of usual project directories, this might do the trick). recentf can be coupled with ido using something like this (I'm not sure where I got this snippet from):
(recentf-mode 1)
(setq recentf-max-saved-items 50)
(defun ido-recentf-open ()
"Use `ido-completing-read' to \\[find-file] a recent file"
(interactive)
(if (find-file (ido-completing-read "Find recent file: " recentf-list))
(message "Opening file...")
(message "Aborting")))
(global-set-key (kbd "C-x C-r") 'ido-recentf-open)
With this, you can use C-x C-f (ido-find-file) to look for files near you current location, and C-x C-r (ido-recentf-open) to look for recently opened files (hoping one of them is not too far away from where you want to go).

There are various approaches. File name cache is a built in solution. Opening files from recent files is also very effective, especially if you set the stored files to a high number (e.g. 1000). There are also packages for opening files from anywhere on the file system. And there are meta solutions like anything.el which can show you file completions from multiple sources (history, project files, etc.) in a common interface.
You should investigate the different options to find out which is the most suitable for you.

In addition to IDO and recetf you can use the following methods:
Open the directory recursively.
(defun op-i:dired (rec)
"customized dired: will display directory recursively when called with an argument"
(interactive "P")
(let ((dir (car (find-file-read-args "Dired: " nil)))
(opts (if rec (read-string "options: " "-lhAR") "-lhA")))
(if (file-directory-p dir) (dired dir opts))))
(define-key (current-global-map) (kbd "C-x C-d") 'op-i:dired)
Then you can navigate in the directory buffer as in any other buffer using a (wildcard) search.
Use Emacs registers to point to often used directories. You can initialize them in your .emacs
(set-register ?0 (cons 'file "c:/path/to/my-project0"))
(set-register ?1 (cons 'file "c:/path/to/my-project1"))
Then jump to register using C-x r j

Other people have already mentioned anything, suffice it to say, I believe it solves all your problems. :)
Calling out one specific feature of anything is anything-locate. On *nix systems, this uses the DB created by the locate command to quickly find files. On Windows, I believe it works with "Everything", which should give you near instantaneous search results across all your files. I mean all.
Tom has mentioned file-cache. Anything works with that.
Just as a side note, Dired is an absolute monster once you get used to it. You should read the emacswiki pages related to it. In particular dired-x, which comes with Emacs binds C-x C-j, jumps to current buffer in Dired was a revelation for me. Also dired-find, wdired.
Edit: some details on why C-x C-j is awesome.
When you pop the current buffer in a Dired buffer, you can modify it, i.e. rename, delete, etc. And Emacs is aware of what you've done, and adjusts accordingly.

Other possibilities:
Bookmarks. If you use Bookmark+ then you can also:
Bookmark Dired buffers, which remembers their inserted subdirs, their markings, and their file omissions. You can have a bookmark that opens Dired to a specific set of files that need not be in the same directory or even the same directory tree.
From Dired you can hit a key to create a separate bookmark to each marked file or subdir.
Bookmark files automatically (autofiles).
Tag bookmarks and files (autofile bookmarks) with arbitrary-text tags. (Tags can even be non-text Lisp objects). Use tags to organize, search, etc. different categories of bookmarks.
Bookmark sets of bookmarks or bookmark files or Emacs desktops. Jump to such a bookmark to restore a given project state/context.
Icicles.
Define temporary or persistent sets of files on the fly, even from different directories. Operate on the files in a set in various ways. (Use Emacs filesets, less powerful, the same way.)
Complete against file names from such saved sets during any completion command, not just file-finding.
Act in different ways on candidate files during completion.
Search bookmarked objects or saved sets of files or buffers.
Dired+.
Additional navigation, including i bouncing between a subdirectory listing and the subdirectory's line in the parent listing.
Refs:
http://www.emacswiki.org/cgi-bin/wiki/BookmarkPlus
http://www.emacswiki.org/emacs/Icicles_-_Support_for_Projects
http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input
http://www.emacswiki.org/cgi-bin/wiki/DiredPlus

Related

How do I find org-mode files with completion in Emacs?

I have a growing set of org files stored in org-directory. How can I navigate between them, preferably with interactive filtering and completion?
I thought there was a way to get org-mode to produce a list of known org files for quick navigation, but I can't seem to find it. If org-mode does not have this feature, how can I make a simple command that launches something like helm or icicles to find them?
The question is not very clear to me. But if your Org-mode files all have a certain file-name pattern (e.g. *.org) and all are in the same directory (org-directory) then you can use several methods Emacs method to access them:
C-x C-f *.org RETURN in org-directory opens them all (the buffers are visiting them but only the last one is shown).
C-x C-f *.org TAB in org-directory, to show them using completion, then pick whichever one you want (or pick more than one, using a glob pattern, as in #1).
The same as #2, using Icicles or Helm. In Icicles, at least, you can also match using regexps and in other ways.
Open Dired for just those files: C-x d *.org.
There are really any number of ways to do what you've described. But I'm guessing that you have not really described your request/problem/question well enough, and when you do you will get a narrower set of answers.
UPDATE after your comments:
Here's one way: Open Dired on all of your Org files in and under org-directory.
(defun foo ()
"Open Dired for (only) the Org files in and under `org-directory`."
(interactive)
(cd org-directory)
(dired "*.org" "-lRF"))
Test it with M-x foo. Put this in your init file:
(foo)
And here's another way: M-x bar or bind bar to a key.
(defun bar ()
"Open an Org file in or under `org-directory`."
(interactive)
(let ((default-directory org-directory)
(icicle-file-match-regexp ".*\\.org"))
(icicle-locate-file-of-content)))
I have a package that does just that: plain-org-wiki.
It's nothing too elaborate: I just dump all of my 45 org files into a single directory and get completion for them.
How about org-iswitchb, which is provided by org already?
Switch between Org buffers.
With one prefix argument, restrict available buffers to files.
With two prefix arguments, restrict available buffers to agenda files.
Add this to your startup file after org is loaded:
(global-set-key "\C-cb" 'org-iswitchb)
My favorite solution to this is helm-mode which is activated with the helm package from MELPA. Here's a demo:
It really makes for a great environment for searching ones files quickly. In addition, one can enable fuzzy completion! Here's a minimal configuration (after installing the helm package):
(require 'helm-config)
(helm-mode 1)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
You can also run grep on the files if you'd like to search their content. Take a look at this amazing guide if you'd like to learn more.

Open multiple instance of a file-

How can I open multiple different instances of file in Emacs? That is to say, the instances are totally independent of each other but write to the same file.
I actually want to have a reference to the original file in one buffers side-by-side with the buffer in which I will be editing while referring to the original content. I don't find opening a temporary buffer, yanking the entire original content into it and have it side-by-side, as an elegant solution.
Other solutions are welcome as well.
I have tried using clone-indirect-buffer and C-x C-v but it doesn't server the purpose.
You can create a new buffer (C-xb*new*) and insert the content of the file to it with C-xifilename.
As I read through the find-file code, I see this warning coded into it:
"The file %s is already visited normally.
You have asked to visit it literally,
meaning no coding system decoding, format conversion, or local variables.
But Emacs can only visit a file in one way at a time.
Do you want to revisit the file literally now? "
Something that would imply that Emacs' code specifically tries to protect against the situation when the same file is visited multiple times, but the buffers are out of sync with each other. However... you could open two copies of Emacs, in which case they would not know about each other visiting the same file and so would allow this situation to happen.
I can understand that the above isn't a very nice option, but it looks like adding that kind of functionality will require some time understanding the reasons behind it being specifically prevented in the first place.
I've tried this:
M-:(switch-to-buffer (find-file-noselect-1 (create-file-buffer (buffer-file-name)) (buffer-file-name) t nil (buffer-file-name) 1))
And it seems like it would work, but I'm not sure of consequences - maybe different major modes may rely on the original Emacs treatment of files and their editing history, so use with care. The last number 1 is the number to be displayed after the file name, as in Foo.bar<1> So, you'd need to change that, if you need more copies.
As mentioned, you might be able to use clone-buffer, although you'll have to let-bind buffer-file-name around the call since clone-buffer otherwise will refuse to clone it. Another option is to do:
M-x set-visited-file-name RET toto RET
C-x C-f thefile RET
C-x b RET
M-x set-visited-file-name RET thefile RET
the last set-visited-file-name should ask you if you really want to do that, but you can answer that you do and Emacs will accept your choice. Arguably, clone-buffer should not reject to do it, so you might like to submit a bug-report asking to make it behave similarly to what set-visited-file-name does.
You may have some luck with clone-buffer, depending on your mode. It has certain limitations that you can read about in the docs.
Otherwise, here's something quick and dirty:
(defun dodgy-clone-buffer ()
"Clone the current buffer. The clone will write to the original file."
(interactive)
(switch-to-buffer-other-window
(eval `(with-current-buffer
;; Create a new buffer or clear an existing one.
(get-buffer-create ,(format "*clone: %s*" (buffer-name)))
(delete-region (point-min) (point-max))
(insert ,(buffer-string))
(setq buffer-file-name ,(buffer-file-name))
(funcall ',major-mode)
(current-buffer)))))

How can I more easily switch between buffers in Emacs?

I've recently started using emacs and I'm enjoying using it for the most part. The only thing I'm not enjoying, is switching between buffers. I often have a few buffers open and I've grown tired of using C-x b and C-x C-b, are there any packages that make switching between buffers easier? I've looked into emacs wiki on switching buffers and I'd appreciate insight/feedback on what are are using/enjoying. Thanks.
UPDATE: iswitchb-mode is obsolete in Emacs >= 24.4, replaced by ido.
All of the features of iswitchdb are now provided by ido. Ross provided a link to the documentation in his answer. You can activate with the following in your .emacs (or use the customization interface as Ross suggests):
(require 'ido)
(ido-mode 'buffers) ;; only use this line to turn off ido for file names!
(setq ido-ignore-buffers '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
By default, ido provides completions for buffer names and file names. If you only want to replace the features of iswitchb, the second line turns off this feature for file names. ido will ignore any buffers that match the regexps listed in ido-ignore-buffers.
The behaviour described below for iswitchb-mode applies equally to ido for switching buffers.
iswitchb-mode (Emacs < 24.4)
iswitchb-mode replaces the default C-x b behaviour with a very intuitive buffer-switching-with-completion system. There are more sophisticated options, but I've never needed more than this.
After you hit C-x b, you are presented with a list of all buffers. Start typing the name of the buffer you want (or part of its name), and the list is narrowed until only one buffer matches. You don't need to complete the name, though, as soon as the buffer you want is highlighted hitting enter will move you to it. You can also use C-s and C-r to move through the list in order.
You can turn it on by default with this in your .emacs:
(iswitchb-mode 1)
You can also tell it to ignore certain buffers that you never (or very rarely) need to switch to:
(setq iswitchb-buffer-ignore '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
You can use C-x <right> (next-buffer) and C-x <left> (previous-buffer) to cycle around in the buffer ring. You could bind S-<right> and S-<left> to these functions. (S is the "super-key" or windows-key). This way you can save some keystrokes.
Moreover, note that C-x b has a default entry, i.e. it displays a standard value (most of the time this is the previously viewed buffer), so that you don't always need to enter the buffer name explicitly.
Another nice trick is to open separate windows using C-x 2 and C-x 3. This displays several buffers simultaneously. Then you can bind C-<tab> to other-window and get something similar to tabbed browsing.
M-x customize-group ido then set Ido Mode to Turn on both buffer and file and set Ido Everywhere to on. Then click the Save for future sessions button at the top and enjoy ido magic for both files and buffers. Read the docs to get a sense of how to use ido.
Also, take a look at smex.
ido-mode provides an efficient way to switch buffers.
ibuffer is best for managing all opened buffers.
anything is good for selecting an interested thing from different
sources. (for eg: a single key can be used to switch to another
buffer or to open recently closed file or to open a file residing
in the same directory or ... anything you want ... )
If you've looked at the Emacs Wiki, you probably have all this information already, but here are a few other relevant Q&As:
Emacs: help me understand file/buffer management
Buffer switching in Emacs
How to invoke the buffer list in Emacs
My toolkit consists of ibuffer, windmove+framemove, winner-mode, and a custom binding to make C-xleft/right and C-cleft/right less of a hassle to use.
I have mapped the "ยง"-key to 'buffer-list and I find it to be very efficient.
I've started using anything for a couple of days and I'm really liking it: http://www.emacswiki.org/emacs/Anything .
Emacs-fu has an good intro to anything: http://emacs-fu.blogspot.com/2011/09/finding-just-about-anything.html
My favourite function for this is helm-mini which is part of helm.
As other helm functions, it allows incremental narrowing of the selection. It also searches your recently visited buffers, which is a really nice way to re-open a buffer. Helm can be a little surprising at first and as a new Emacs user, I found it visually overwhelming and I preferred ido or ibuffer which have been suggested in other replies. But now I absolutely love it and use it all the time for countless things.
Something that I realized by accident and that can be useful:
mouse-buffer-menu is by default bound to <C-mouse-1> (Control key + mouse left click) and opens a popup with a list of the current buffers.

Don't show uninteresting files in Emacs completion window

How do I prevent Emacs from showing me all the files I'm not interested in (such as ~ backup files, .pyc files, or .orig files) when I: C-x C-f TAB ?
It is working in one respect: if I know the file I want to open begins with foo and I type foo TAB then the mini-buffer correctly autocompletes all the way to foo.py. It correctly ignored foo~ and foo.pyc, because both ~ and .pyc are in completion-ignored-extensions. It also correctly lets me open either ignored file if I really want to by typing in all the letters my self.
However, if I just hit TAB to to bring up the completion list buffer then that list includes files with extensions in completion-ignored-extensions, which makes it very difficult to find what I'm looking for.
Clearly the code to ignore uninteresting files is there and working. How do I get the completion list buffer to respect completion-ignored-extensions?
(by-the-by, can I make dired behave similarly?)
This piece of advice filters out files with extensions listed in 'completion-ignored-extensions:
(defadvice completion--file-name-table (after
ignoring-backups-f-n-completion
activate)
"Filter out results when they match `completion-ignored-extensions'."
(let ((res ad-return-value))
(if (and (listp res)
(stringp (car res))
(cdr res)) ; length > 1, don't ignore sole match
(setq ad-return-value
(completion-pcm--filename-try-filter res)))))
Note: This doesn't affect dired.
For the dired issue, add this to your .emacs
(eval-after-load "dired"
'(require 'dired-x))
(add-hook 'dired-mode-hook
(lambda ()
(dired-omit-mode 1)))
Read the documentation for dired-x to get an idea of what's available there.
I would recommend using ido-mode to ignore files; it comes with Emacs by default and adds many other useful enhancements that you'll quickly learn to love. The Ignorance is Bliss section from this Mastering Emacs blog post covers how to ignore files, directories, and buffers:
ido-ignore-buffers Takes a list of buffers to ignore in C-x b
ido-ignore-directories Takes a list of directories to ignore in C-x d and C-x C-f
ido-ignore-files Takes a list of files to ignore in C-x C-f
Icicles does what you expect by default. It always respects completion-ignored-extensions for file-name completion, including for buffer *Completions*. And you can toggle this ignoring on/off at anytime, by hitting C-. in the minibuffer.
In addition, if you use library completion-ignored-build.el by Kevin Ryde, then Icicles automatically takes advantage of that library's dynamic adjustment of ignored file extensions. (Just load completion-ignored-build.el -- do not enable its minor mode or advice.)
I don't know of an answer for completion, I'm afraid. I think this is by design - when you know the name you're looking for, you probably don't want e.g. the backup file. But when you don't know, it's probably better to have a list of all of the files.
However, for dired, you can load the 'dired-x' package on startup (in your .emacs), and this provides dired-omit-mode:
(load "dired-x")
You can use 'M-x customize-variable<RET>dired-omit-files' to set the actual patterns to ignore. Then when you are in dired mode you can use M-O (the letter, not the number) to toggle 'omission' on and off.

Using Emacs as an IDE

Currently my workflow with Emacs when I am coding in C or C++ involves three windows. The largest on the right contains the file I am working with. The left is split into two, the bottom being a shell which I use to type in compile or make commands, and the top is often some sort of documentation or README file that I want to consult while I am working. Now I know there are some pretty expert Emacs users out there, and I am curious what other Emacs functionally is useful if the intention is to use it as a complete IDE. Specifically, most IDEs usually fulfill these functions is some form or another:
Source code editor
Compiler
Debugging
Documentation Lookup
Version Control
OO features like class lookup and object inspector
For a few of these, it's pretty obvious how Emacs can fit these functions, but what about the rest? Also, if a specific language must be focused on, I'd say it should be C++.
Edit: One user pointed out that I should have been more specific when I said 'what about the rest'. Mostly I was curious about efficient version control, as well as documentation lookup. For example, in SLIME it is fairly easy to do a quick hyperspec lookup on a Lisp function. Is there a quick way to look up something in C++ STL documentation (if I forgot the exact syntax of hash_map, for example)?
You'll have to be specific as to what you mean by "the rest". Except for the object inspector (that I"m aware of), emacs does all the above quite easily:
editor (obvious)
compiler - just run M-x compile and enter your compile command. From there on, you can just M-x compile and use the default. Emacs will capture C/C++ compiler errors (works best with GCC) and help you navigate to lines with warnings or errors.
Debugging - similarly, when you want to debug, type M-x gdb and it will create a gdb buffer with special bindings
Documentation Lookup - emacs has excellent CScope bindings for code navigation. For other documentation: Emacs also has a manpage reader, and for everything else, there's the web and books.
version control - there are lots of Emacs bindings for various VCS backends (CVS, SCCS, RCS, SVN, GIT all come to mind)
Edit: I realize my answer about documentation lookup really pertained to code navigation. Here's some more to-the-point info:
Looking up manpages, info manuals, and Elisp documentation from within emacs
Looking up Python documentation from within Emacs.
Google searching will no doubt reveal further examples.
As the second link shows, looking up functions (and whatever) in other documentation can be done, even if not supported out of the box.
I have to recommend Emacs Code Browser as a more "traditional" IDE style environment for emacs.
EDIT: I also now recommend Magit highly over the standard VCS interface in emacs.
Instead of running a make command in the shell window, have you tried M-x compile? It will run your make command, display errors, and in many cases make it very easy to jump to the line of code that caused the error if the output includes filenames and line numbers.
If you're a fan of IDEs, you might also want to look at emacs' speedbar package (M-x speedbar). And, if you haven't already, learn about how to use tags tables to navigate your code.
There are corners of emacs that once discovered make you more productive in ways you never thought of. As others have mentioned, using tags is a fantastic and fast way to zoom around your source code and using M-/ (dabbrev-expand) often does exactly what you expect when completing a variable name.
Using occur is useful to get a buffer with all occurences of a regular expression in a buffer. That's really handy when refactoring code and looking for fragments of code or uses of variables, or if you use TODO markers in your source files and you want to visit them all.
flush-lines, sort-numeric-fields, replace-regexp and rectangle functions can be really useful for taking a dump from some tool and converting it to useful data such as an elisp program or a comma delimited spreadsheet.
I wrote a page about IDE like things you can do with emacs
http://justinsboringpage.blogspot.com/2007/09/11-visual-studio-tricks-in-emacs.html
Learning elisp is a another great way to answer for yourself what else emacs can do beyond what a typical IDE can do.
For example I've blogged about writing Perforce helper functions like blame (writing your own means you can make it behave exactly as you want)...
http://justinsboringpage.blogspot.com/2009/01/who-changed-line-your-working-on-last.html
I've also written code that dynamically creates comments for a function at point, that matches the coding standards I'm working with.
None of my elisp code is particularly great, and most of it exists already in libraries, but it's really useful to be able to make emacs do custom stuff that just comes up during a working day.
You can find detailed description of emacs & version control integration on my site. I'm also working on article about using Emacs as Development Environment for many languages - C/C++, Java, Perl, Lisp/Scheme, Erlang, etc...
For version control, there are several things that you can use, depending on what version control system you use. But some of the functionality is common to all of them.
vc.el is the built-in way to handle version control at a file level. It has backends for most version control systems. For instance, the Subversion backend comes with Emacs, and there are git backends and others available from other sources.
The most useful command is C-x v v (vc-next-action) that does the appropriate next action for the file you are visiting. This might mean updating from the repository or commiting your changes, vc.el also rebinds C-x C-q to check in and out files if you are using a system that needs it (like RCS).
Other very useful commands are C-x v l and C-x v = that show you the log and current diff for the file you are using.
But for real productivity, you should avoid using the single-file vc.el commands other than for simple things. There are several packages that can give you an overview of the status of your whole tree, and give you more power, and not to mention the ability to create coherent commits spanning several files.
Most of these are heavily influenced or based on the original pcl-cvs/pcvs for CVS. There are even two of them that comes with subversion, psvn.el and dsvn.el. There are packages for git etc.
Okay, everyone here is giving perfect hints to make emacs a great IDE.
But anyone should keep in mind that, when you customize your emacs with a lot of extension (especially with the ones for type-checking on the fly, function definition lookups etc) your emacs will load very, very slow for an editor.
To workaround this, I would highly recommend to use emacs in server mode.
It is pretty simple to use, no need to customize your init file.
You just need to start emacs in daemon mode;
emacs --daemon
This will create an emacs server, then you can connect it either from terminal, or from gui. I'd also recommend to create some aliases to make it easy to call.
alias ec="emacsclient -t"
alias ecc="emacsclient -c &"
# some people also prefer this but no need to fight here;
alias vi="emacsclient -t"
This way, emacs will fire up even faster than gedit, promise.
The one possible problem here, if you are running emacs daemon from your casual user, you probably can't connect emacs server as root.
So, if you need to open a file that has root access; use tramp instead. Just run your emacs client with your normal user and open files like this;
C-x C-f
/sudo:root#localhost/some/file/that/has/root/access/permissions
# on some linux distro it might be `/su:root#...`
This made my life easier, I can open my heavy customized python IDE in miliseconds this way. You may also want to add emacs --daemon to your system startup, or create a desktop file for emacsclient. Thats up to you.
More on emacs daemon and emacs client can be found at wiki;
http://www.emacswiki.org/emacs/EmacsAsDaemon
http://www.emacswiki.org/emacs/EmacsClient
I agree that you should learn about M-x compile (bind that and M-x next-error to a short key sequence).
Learn about the bindings for version control (e.g. vc-diff, vc-next-action, etc.)
Look into registers. You not only can remember locations in buffers but whole window configurations (C-x r w -- window-configuration-to-register).
A starting point (which may be non-obvious) for exploring the VC features of Emacs is M-x vc-next-action.
It does the "next logical version control operation" on the current file, depending on the state of the file and the VC backend. So if the file is not under version control, it registers it, if the file has been changed, the changes are submitted etc.
It takes a little getting used to, but I find it very useful.
Default keybinding is C-x v v
I know this is a very old post. But this question is valid for emacs beginners.
IMO the best way to use emacs as an ide is to use a language server protocol with emacs. You can find all the information about language servers in the linked website.
For a quick setup, i would urge you to go to this page eglot . IMO eglot does it's job pretty well. It integrates well with auto completions packages like company. Provides find reference, and more.
Also for a debugger, you may need specific debuggers for specific languages. You can use gdb from within emacs. Just type M-x gdb .
For compiling your code, it's best to use shell-commands. I am working on this project eproj. It's gonna take a while to complete it. But all it does is maps shell command to project type. And builds you project via shell. It does the same to execute command. I may need help completing this project. It's not ready for use, but if you know a bit of elisp you can go through the code.
That aside, it's always best to use the emacs compile command.
For version control, I haven't yet seen any other package which can match the power of magit. It's specific to git. Also for git there is another package git-timemachine, which i find very useful.
Object lookup and class lookup is provided by language server protocol.
A project tree can be used for ide like interface with treemacs.
There is also a project Interaction Library called projectile.
For auto completion, I find company-mode very useful.
Truly emacs can be made to do anything.
There's a TFS.el for emacs integration into Microsoft TFS. It works with any TFS, including the TFS that runs Codeplex.com.
Basic steps to setup:
Place tfs.el in your load-path.
In your .emacs file:
(require 'tfs)
(setq tfs/tf-exe "c:\\vs2008\\common7\\ide\\tf.exe")
(setq tfs/login "/login:domain\\userid,password")
-or-
(setq tfs/login (getenv "TFSLOGIN")) ;; if you have this set
also in your .emacs file, set local or global key bindings for tfs commands. like so:
(global-set-key "\C-xvo" 'tfs/checkout)
(global-set-key "\C-xvi" 'tfs/checkin)
(global-set-key "\C-xvp" 'tfs/properties)
(global-set-key "\C-xvr" 'tfs/rename)
(global-set-key "\C-xvg" 'tfs/get)
(global-set-key "\C-xvh" 'tfs/history)
(global-set-key "\C-xvu" 'tfs/undo)
(global-set-key "\C-xvd" 'tfs/diff)
(global-set-key "\C-xv-" 'tfs/delete)
(global-set-key "\C-xv+" 'tfs/add)
(global-set-key "\C-xvs" 'tfs/status)
(global-set-key "\C-xva" 'tfs/annotate)
(global-set-key "\C-xvw" 'tfs/workitem)
compile, next-error, and previous-error are all pretty important commands for C++ development in Emacs (works great on grep output too). Etags, visit-tags-table, and find-tag are important as well. completion.el is one of the great unsung hacks of the 20th century, and can speed up your C++ hacking by an order of magnitude. Oh and let's not forget ediff.
I've yet to learn how to use version control without visiting a shell, but now that I'm running commits so much more frequently (with git) I will probably have to.
You might also find tabbar useful. It emulates the only behavior I missed when moving from Eclipse to Emacs. Bound to "," and "." for moving to the previous and next tab bar, it relives you from switching the buffer by Ctrl-x b all the time.
Unfortunately, the mentioned web page does not provide the correct version to download. Most Ubuntu versions, however, deliver it in their emacs-goodies packages.
I use emacs on Windows. the compile module is nice, but I wanted compile to be smarter about the compile command line it suggests. It's possible to use "File Variables" to specify compile-command, but I wanted something a little smarter than that. So I wrote a little function to help out. It guesses the compile command to use, to prompt the user with, when running compile.
The guess function looks for a vbproj or csproj or sln file, and if found, it suggests msbuild. Then it looks at the buffer file name, and depending on that, suggests different things. A .wxs file means it's a WIX project, and you likely want to build an MSI, so the guess logic suggests an nmake command for the MSI. If it's a Javascript module, then the suggestion is to run jslint-for-wsh.js to lint the .js file. As a fallback, it suggests nmake.
The code I use looks like this:
(defun cheeso-guess-compile-command ()
"set `compile-command' intelligently depending on the
current buffer, or the contents of the current directory."
(interactive)
(set (make-local-variable 'compile-command)
(cond
((or (file-expand-wildcards "*.csproj" t)
(file-expand-wildcards "*.vcproj" t)
(file-expand-wildcards "*.vbproj" t)
(file-expand-wildcards "*.shfbproj" t)
(file-expand-wildcards "*.sln" t))
"msbuild ")
;; sometimes, not sure why, the buffer-file-name is
;; not set. Can use it only if set.
(buffer-file-name
(let ((filename (file-name-nondirectory buffer-file-name)))
(cond
;; editing a .wxs (WIX Soluition) file
((string-equal (substring buffer-file-name -4) ".wxs")
(concat "nmake "
;; (substring buffer-file-name 0 -4) ;; includes full path
(file-name-sans-extension filename)
".msi" ))
;; a javascript file - run jslint
((string-equal (substring buffer-file-name -3) ".js")
(concat (getenv "windir")
"\\system32\\cscript.exe c:\\users\\cheeso\\bin\\jslint-for-wsh.js "
filename))
;; something else - do a typical .exe build
(t
(concat "nmake "
(file-name-sans-extension filename)
".exe")))))
(t
"nmake "))))
(defun cheeso-invoke-compile-interactively ()
"fn to wrap the `compile' function. This simply
checks to see if `compile-command' has been previously set, and
if not, invokes `cheeso-guess-compile-command' to set the value.
Then it invokes the `compile' function, interactively."
(interactive)
(cond
((not (boundp 'cheeso-local-compile-command-has-been-set))
(cheeso-guess-compile-command)
(set (make-local-variable 'cheeso-local-compile-command-has-been-set) t)))
;; local compile command has now been set
(call-interactively 'compile))
;; in lieu of binding to `compile', bind to my monkeypatched function
(global-set-key "\C-x\C-e" 'cheeso-invoke-compile-interactively)
I tried doing this as "before advice" for the compile function but couldn't get it to work satisfactorily. So I defined a new function and bound it to the same keystroke combination I have been using for compile.
EDIT there is now "smarter-compile.el" which takes this idea one step further.
In the recent years, Clang became an important part of the Emacs C++ support. Atila Neves had a talk on CppCon 2015:
"Emacs as a C++ IDE"
It is a 16 minute talk, where he shows solutions for the following topics:
Jump to definition
Auto-completion
On-the-fly syntax highlighting
Find file in project
Slides can be found here.
On documentation lookup: that depends on your programming language(s).
C libraries and system calls are typically documented in man pages. For that you can use M-x man. Some things may be documented better in info pages; use M-x info.
For elisp itself, use C-h f. For python, use >>> help(<function, class, module>) in the interpreter.
I find that most other languages offer documentation in html form. For that, try an embedded browser (I use w3m). Set your BROWSER environment variable to a wrapper script around emacsclient -e "(w3m-goto-url-new-session \"$#\")" (on *nix), in case something might open a browser and you want it opened inside emacs.
Try lsp-mode. Now you can use other IDE functionality inside emacs connecting to server. Look for more info: lsp-mode
In the Unix or X windows style, I don't know that there is an integrated IDE that works for everything.
For interacting with debuggers, just one component of an IDE, consider realgud. The other thing it has that I find useful are parsers for location messages, so that if you have a call stack trace and want to edit at a particular place in the callstack, this front-end interface will can do that.
By far this program could use improvement. But then it could also use people working on it to improve it.
Disclaimer: I work on realgud