A gentle tutorial to Emacs/Swank/Paredit for Clojure - emacs

I am moving to Emacs to work on Clojure/Lisp.
What is all the information I need to setup on Emacs to be able to do the following?
automatic matching/generation of corresponding closing brackets
autoindent Lisp/Clojure style, not C++/Java style
Syntax highlighting
Invoking REPL
To be able to load a part of code from file into the REPL and evaluate it.
It would be great if I could also get the list of commands to get these things after setting things up on Emacs.

[Edit from non-author: this is from 2010, and the process has been significantly simplified since May 2011. I'll add a post to this answer with my setup notes as of Feb 2012.]
You'll need to put together a few pieces: Emacs, SLIME (which works perfectly well with Clojure -- see swank-clojure), swank-clojure (the Clojure implementation of SLIME's server counterpart), clojure-mode, Paredit and, of course, the Clojure jar for a start, then perhaps some extras among which Leiningen would perhaps be the most notable. Once you do set it all up, you'll have -- within Emacs -- all the workflow / editing features you mention in the question.
Basic setup:
The following are to great tutorials which describe how to set all of this up; there's more on the Web, but some of the others are quite outdated, whereas these two seem to be ok for now:
in which are found tricks of the trade concerning clojure authorship post on Phil Hagelberg's blog; Phil maintains swank-clojure and clojure-mode, as well as a package called the Emacs Starter Kit which is something any newcomer to the Emacs world would be well-advised to have a look at. These instructions seem to have been brought up to date with recent changes to the infrastructure; in case of doubt, look for additional information on Clojure's Google group.
Setting up Clojure, Incanter, Emacs, Slime, Swank, and Paredit post on the blog of the Incanter project. Incanter is a fascinating package providing an R-like DSL for statistical computations embedded right into Clojure. This post will be useful even if you don't plan on using -- or even installing -- Incanter.
Putting it all to work:
Once you set up all of this stuff, you could try and start using it right away, but I would strongly advise you to do the following:
Have a look at SLIME's manual -- it's included in the sources and is actually very readable. Also, there's absolutely no reason why you should read the whole 50-page monster manual; just have a look around to see what features are available.
Note: the autodoc feature of SLIME as found in the latest upstream sources is incompatible with swank-clojure -- this problem won't come up if you follow Phil Hagelberg's recommendation to use the ELPA version (see his aforementioned blog post for an explanation) or simply leave autodoc off (which is the default state of things). The latter option has some added appeal in that you can still use the latest SLIME with Common Lisp, in case you use that as well.
Have a look at the docs for paredit. There are two ways to go about this: (1) look at the source -- there's a huge amount of comments at the top of the file which contain all the information you're likely to need; (2) type C-h m in Emacs while paredit-mode is active -- a buffer will pop up with information on the current major mode followed by information on all active minor modes (paredit is one of those).
Update: I've just found this cool set of notes on Paredit by Phil Hagelberg... That's a link to a text file, I remember seeing a nice set of slides with this information somewhere, but can't seem to find it now. Anyway, it is a nice summary of how it works. Definitely take a look at it, I can't live without Paredit now and this file should make it very easy to start using it, I believe. :-)
In fact, the C-h m combination will tell you about all keybindings active at the SLIME REPL, in clojure-mode (you'll want to remember C-c C-k for sending the current buffer off for compilation) and indeed in any Emacs buffer.
As for loading the code from a file and then experimenting with it at the REPL: use the aforementioned C-c C-k combination to compile the current buffer, then use or require its namespace at the REPL. Next, experiment away.
Final notes:
Be prepared to have to tweak things for a while before it all clicks. There's a lot of tools involved and their interactions are mostly fairly smooth, but not to the point where it would be safe to assume you won't have to make some adjustments initially.
Finally, here's a bit of code I keep in .emacs which you won't find elsewhere (although it's based on a cool function by Phil Hagelberg). I alternate between starting my swank instances with lein swank (one of the cooler features of Leiningen) and using the clojure-project function as found below to start the whole thing from within Emacs. I've done my best to make the latter produce an environment closely matching that provided by lein swank. Oh, and if you just want a REPL in Emacs for a quick and dirty experiment, then with the correct setup you should be able to use M-x slime directly.
(setq clojure-project-extra-classpaths
'(
; "deps/"
"src/"
"classes/"
"test/"
))
(setq clojure-project-jar-classpaths
'(
; "deps/"
"lib/"
))
(defun find-clojure-project-jars (path)
(apply #'append
(mapcar (lambda (d)
(loop for jar in (remove-if (lambda (f) (member f '("." "..")))
(directory-files d t))
collect jar into jars
finally return jars))
(remove-if-not #'file-exists-p
clojure-project-jar-classpaths))))
(defun find-clojure-jar (jars)
(let ((candidates
(remove-if-not
(lambda (jar)
(string-match-p "clojure\\([0-9.-]+\\(SNAPSHOT|MASTER\\)?\\)?\\.jar$" jar))
jars)))
(if candidates
(car candidates)
(expand-file-name "~/.clojure/clojure.jar"))))
(defun find-clojure-contrib-jar (jars)
(let ((candidates
(remove-if-not
(lambda (jar)
(string-match-p "clojure-contrib\\([0-9.-]+\\(SNAPSHOT|MASTER\\)?\\)?\\.jar$" jar))
jars)))
(if candidates
(car candidates)
(expand-file-name "~/.clojure/clojure-contrib.jar"))))
;;; original due to Phil Hagelberg
;;; (see `Best practices for Slime with Clojure' thread on Clojure Google Group)
(defun clojure-project (path)
"Sets up classpaths for a clojure project and starts a new SLIME session.
Kills existing SLIME session, if any."
(interactive (list (ido-read-directory-name
"Project root:"
(locate-dominating-file default-directory "pom.xml"))))
(when (get-buffer "*inferior-lisp*")
(kill-buffer "*inferior-lisp*"))
(cd path)
;; I'm not sure if I want to mkdir; doing that would be a problem
;; if I wanted to open e.g. clojure or clojure-contrib as a project
;; (both lack "deps/")
; (mapcar (lambda (d) (mkdir d t)) '("deps" "src" "classes" "test"))
(let* ((jars (find-clojure-project-jars path))
(clojure-jar (find-clojure-jar jars))
(clojure-contrib-jar (find-clojure-contrib-jar jars)))
(setq swank-clojure-binary nil
;; swank-clojure-jar-path (expand-file-name "~/.clojure/clojure.jar")
swank-clojure-jar-path clojure-jar
swank-clojure-extra-classpaths
(cons clojure-contrib-jar
(append (mapcar (lambda (d) (expand-file-name d path))
clojure-project-extra-classpaths)
(find-clojure-project-jars path)))
swank-clojure-extra-vm-args
(list (format "-Dclojure.compile.path=%s"
(expand-file-name "classes/" path)))
slime-lisp-implementations
(cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init)
(remove-if #'(lambda (x) (eq (car x) 'clojure))
slime-lisp-implementations))))
(slime))

There is one more excelent tutorial:
http://www.braveclojure.com/basic-emacs/ (1st part)
http://www.braveclojure.com/using-emacs-with-clojure/ (2nd part)
In 30 to 45 minutes one can have everything setup from scratch.
The tutorial does not assumes any prior knowladge of Emacs (and Clojure too - in earlier posts there is a nice intro to Clojure).

The Emacs Starter kit has gotten great reviews for getting started with Clojure:
To answer only the swank part of your question:
Leiningen is a really easy way of setting up swank with the correct classpath and get it connected to Emacs.
A great video is here: http://vimeo.com/channels/fulldisclojure#8934942
Here is an example of a project.clj file that
(defproject project "0.1"
:dependencies [[org.clojure/clojure
"1.1.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib
"1.0-SNAPSHOT"]]
:dev-dependencies [[leiningen/lein-swank "1.1.0"]]
:main my.project.main)
then run:
lein swank
and from Emacs:
alt-x slime-connect

Clojure with Emacs on Clojure Documentation can be useful too.

CIDER (Clojure Interactive
Development Environment) must be mentioned here.
It’ll cover most of what you’re looking for. It includes:
interactive REPL
debugging
test running
code navigation
documentation lookup
lots more
In addition to CIDER, there are some other essential and nice-to-have
add-ons for clojure development, which I’ll try to group respectively
(and subjectively):
Essentials
smartparens – parentheses
pairing, manipulation, navigation (or
parinfer if you prefer)
clj-refactor –-
has a couple amazing features, like auto-adding/compiling namepaces
(it may be incorporated into CIDER soon)
clojure-mode –
font-lock, indentation, navigation
company – text completion
framework (or choose another auto-completer)
rainbow delimeters –
highlights/colorizes delimiters such as parentheses, brackets or
braces according to their depth
flycheck – on-the-fly syntax
checking extension
flycheck-clj-kondo –
integration for clj-kondo
Niceties
clojure-snippets –
tab-expandable shortcuts to longer code chunks
dumb-jump – jump to
definitions
which-key – displays
available keybindings in popup
highlight parentheses –
highlight surrounding parentheses
crux – a Collection of
Ridiculously Useful eXtensions for Emacs
comment-dwim-2 –
replacement for Emacs’ built-in comment-dwim
General Essentials (for any language)
magit – git porcelain inside Emacs
projectile – project mgmt
for finding files, searching, etc
helm – incremental completion
and selection narrowing framework (or
swiper)
Other Resources
If you’re looking for a setup that already has done most/all of this
work for you, a couple options are:
prelude
spacemacs

Related

How to use emacs tuareg mode effectively to manage an OCaml project? [duplicate]

Do you know of a good project tree browser for Emacs other than the Emacs Code Browser (ECB)? The features I value are simplicity, lightweightedness, and language agnosticism.
Projectile + NeoTree are my combination of choice.
Projectile just uses your version control system to track files and has an awesome jump to file in project function.
Also, check the notes for integrating the two together.
Speedbar?
If you just want to manage related files, perhaps you would like eproject.
I haven't tried this one myself yet, but emacs-nav is a new Emacs project browser from Google that seems to have the features you value.
You can try sr-speedbar. It's wonderful.
The different parts of cedet will do what you want I think. Speedbar has the tree structure thing, and EDE handles projects etc.
I just now did a word search for "explore" in package-list-packages, and discovered project-explorer. Seems to fit exactly what I want today (I don't code hardly, but I'm getting a grip on the structure of my Jekyll site).
Keys include:
TAB for folding and unfolding directories
Open files with RET or f. With a C-u prefix, it will prompt nicely for which window, and even from there allow you to decide to use window or open up a new one to any side (I didn't find the prompt string in the package code, so it seems to leverage built in Emacs functionality nicely; indeed it looks like dired even).
It's available on Melpa and Marmalade. It is available on Github at sabof/project-explorer.
I include the site's image for convenience:
I don't use projectile or helm, but it has some integration.
Here are my thoughts on several competing file explorer type packages. See the comments above each package below:
;; Dired itself allows one to do 'i' to insert (display in same buffer) the
;; subdirectory under point and C-u k on subdir header line to remove. However,
;; I have found that dired-subtree-toggle and dired-subtree-remove are a better solution for the removal
;; part. Plus dired-subtree let's you customize colors of subdirs to set them apart
;; visually. However, I set all depths of subdirectories custom faces to be the same as I found it distracting.
(use-package dired-subtree
:ensure t
:bind (:map dired-mode-map ("i" . 'dired-subtree-toggle))
:bind (:map dired-mode-map ("I" . 'dired-subtree-remove)))
;; This works nicely. It provides the parent, '..', directory unlike nav.
(use-package project-explorer
:ensure t
:config
(evil-set-initial-state 'project-explorer-mode 'emacs))
;; This can't go above the directory you started it in. It is nice, but I prefer the flexibility
;; of getting to parent directories in most cases.
(use-package dirtree
:ensure t)
;; Google's file explorer
;; Nice, but doesn't maintain visited nodes in view, preferring instead to offer only
;; the current directory or lower in a side window. No better than ivy which is my main file explorer system.
(use-package nav
:ensure t)
;; This is buggy on Emacs 26.1.
(use-package eproject
:disabled t
:ensure t)
;; speedbar is included with Emacs (since 24.x I believe). It has to use a separate frame, which is
;; inconvenient most of the time. There are better options (above).
;; (use-package speedbar)
;; Buggy; doesn't work on Emacs 26.1 (at least with my config).
(use-package sr-speedbar
:disabled t
:load-path "../lisp")
;; Buggy on Emacs 26.1 (at least with my config). I couldn't even get it to activate.
(use-package ecb
:disabled t
:ensure t)
;; Nice, but similar to ivy which I've already committed to, so not necessary.
(use-package lusty-explorer
:disabled t
:ensure t)
For me, ivy plus dired gets me 98% of the way. ivy, dired, and dired-subtree gets me 99% of the way. project-explorer, and to a lesser extent, nav, are just nice alternatives to ivy plus dired or ivy plus dired and dired-subtree. Hopefully this will save you some time.
I've used treemacs and it's works good, esp. with projectile.

What happened to the ido-imenu in ruby-mode function in Emacs24?

Emacs 23.2 in emacs-starter-kit v1 has C-x C-i (or ido-imenu) (similar to Sublime Text's Cmd+R). Emacs24 in emacs-starter-kit v2 lacks this function. I found this github issue and a fix, which try to recreate the functionality. While this ido-imenu works in elisp-mode, it stopped working in ruby-mode. I get:
imenu--make-index-alist: No items suitable for an index found in this buffer
Has anyone figured out how to get this to work?
Why was this taken out of Emacs24?
Is there a new replacement for this function?
Since the function is part of ESK (as opposed to something budled with Emacs) you'd probably do best to report the bug upstream. On a related note ESK main competitor Emacs Prelude offers the same functionality (bound to C-c i by default) and it seems to be working fine with ruby-mode in Emacs 24. Here you can find more on ido-imenu.
So I finally figured it out, after reading the Defining an Imenu Menu for a Mode section on emacs-wiki again.
Short answer: you need to add this bit to your customization. Feel free to add more types to the list (I am happy with just methods).
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable imenu-generic-expression)
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1)
))))
Longer answer: I first tried to define a ruby-imenu-generic-expression function and set that to imenu-generic-expression by using the ruby-mode-hook:
(defvar ruby-imenu-generic-expression
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1))
"The imenu regex to parse an outline of the ruby file")
(defun ruby-set-imenu-generic-expression ()
(make-local-variable 'imenu-generic-expression)
(make-local-variable 'imenu-create-index-function)
(setq imenu-create-index-function 'imenu-default-create-index-function)
(setq imenu-generic-expression ruby-imenu-generic-expression))
(add-hook 'ruby-mode-hook 'ruby-set-imenu-generic-expression)
This however did not work (I would get the same error as before). More reading of the Defining an Imenu Menu for a Mode section showed me the way. Now, I'm not an elisp expert, so here's my hypothesis: basically, the above method works for modes where the
major mode supports a buffer local copy of the “real” variable, ‘imenu-generic-expression’. If your mode doesn’t do it, you will have to rely on a hook.
The example for foo-mode made it clear how to do it for ruby-mode. So it appears that ruby-mode does not have a buffer-local copy of the real imenu-generic-expression variable. I still can't explain why it worked in Emacs 23.2 (with ESK v1) but does not on Emacs24, but hey at least I found a working solution.

Emacs Clojure mode without paredit

I'm using the Clojure mode package from ELPA. Otherwise everything is fine, but I just can't stand paredit mode. I can't seem to turn it off easily, now I just disable it for every buffer I open. I tried setting this variable to nil:
(setq clojure-enable-paredit nil)
But paredit still appears. Any ideas?
Not an answer to your actual question, but give paredit mode a chance. I, too, was really annoyed with it automatically closing my parens, and refusing to delete just a single paren for me.
But doing this enables it to be certain at all times that the buffer is a well-balanced sexp, so it can perform many useful sexp-oriented tasks for you instead of just text-oriented tasks. For example, I use the following all the time:
M-( to wrap a sexp with a new one, eg turn (map f some-list) into (doto (map f some-list) println)
C-) to "slurp" another sexp into the current one, eg turn (let [x 10]) (println x) into (let [x 10] (println x))
M-<UP> and/or M-r to pull the sexp at point a level "higher" in the source tree, destroying the thing that was wrapping it, eg to turn (first (map f some-list)) into (map f some-list) or (first some-list)
There are zillions of useful features like this, that let you start editing code instead of text. And while there are plenty of excellent Lisp hackers who don't like paredit mode, I advise you not to decide against it before you realize the awesome stuff it can do for you.
Found one trick that works. Before the elpa packages are loaded in init.el, add this hook to clojure mode:
(add-hook 'clojure-mode-hook (lambda () (paredit-mode nil)))
For what it's worth, I use clojure-mode through ELPA too, and it doesn't imply paredit. Maybe just uninstall it? I find clojure-mode, slime and slime-repl are the only packages I need to install on a clean EMACS to get clojure/swank/slime working.
I only tested this:
http://www.learningclojure.com/2010/08/clojure-emacs-swank-slime-maven-maven.html
a few weeks ago, and it still works fine.

What are good practices to get GNU emacs and xemacs co-habitate

I would like to make a gradual switch from GNU Emacs to Xemacs. Are there tricks I can use to have the two play well?
Currently, I see the following issues:
xemacs alters .emacs
The two do not like each others .elc files.
Thanks!
Interesting, most appear to be moving in the other direction as I believe XEmacs to be fairly dormant (based on activity of the xemacs-announce list). Simple packages can co-exist, but many folks have given up making their packages work in both XEmacs and Emacs.
But, in answer to your question, to get your .emacs to work in both, I'd start writing a some routines to do function translation between the two. For example, at one point I needed this to get my .emacs to work in XEmacs:
(if (not (fboundp 'tags-table-files))
(defun tags-table-files ()
(tag-table-files tags-file-name)))
Other things were triggered on the Emacs variant, which I stored in a variable GNU:
(setq GNU (not (string-match "XEmacs\\|Lucid" (emacs-version))))
(if GNU
(do-emacs-thing)
(do-xemacs-thing))
I was keeping compiled .emacs files and did this:
(setq compiled-dot-emacs-name (format ".emacs-%d%s" emacs-major-version
(if GNU "" "X")))
Regarding compiled packages, I'd probably store all the .el files in one directory (say emacs-lisp), but have an xemacs variant (xemacs-lisp) with symlinks to the .el files. And then you just byte compile each directory from the appropriate Emacs variant, and make sure to have your load-path point to the right one.
The Emacs wiki has a page on Emacs versus XEmacs which might be a good starting point to figure out other tips to make them cohabitate. Specifically, there's a page for customizing both.
I don't use xemacs, but newer GNU emacs will check for .emacs.d/init.el as well, so maybe moving .emacs stuff to init.el makes sense. Additionally you can link it to .xemacs/init.el if you manage to keep your customization applicable for both.
There is also a discussion on what emacs to prefer on emacswiki.
I started a slow move from Xemacs to Emacs a while ago. I now use both on a daily basis. To make the transition smoother (one set of init files), I stole the following .emacs file from http://xemacs.seanm.ca/_emacs (but the link is now dead).
(setq user-init-file
(expand-file-name "init.el"
(expand-file-name ".xemacs" "~")))
(setq custom-file
(expand-file-name "custom.el"
(expand-file-name ".xemacs" "~")))
(if (file-exists-p user-init-file)
(load-file user-init-file))
(if (file-exists-p custom-file)
(load-file custom-file))
My ~/.xemacs/init.el starts off with:
(unless (boundp 'running-xemacs)
(defvar running-xemacs nil))
(setq load-path (cons "~/.elisp" load-path)) ; packages for both emacsen
(if running-xemacs
(setq load-path (cons "~/.elisp/xemacs" load-path)) ; packages for Xemacs only
(setq load-path (cons "~/.elisp/gnuemacs" load-path))) ; packages for Gnuemacs only
From then on it is pretty obvious what I have (the occasional (if running-xemacs) ...). I also deleted all the .elc files from ~/.elisp, but I presume that Trey Jackson's suggestion will work.
on modern systems i do not see the need for precompiled elisp files anymore. The benefit in looking and on the fly changing the .el-files is much more higher.
.emacs: put your own defines in .emacs_startup (or which name you prefere) and put all your gnu-enmacs stuff there and put a conditional load in your .emacs

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