Emacs is a great editor. But it is really hard to set it up. So I decided to write a document for my current emacs setup. In this post, I will explain how to install emacs with a basic setup.
I will cover how to:
I will cover setups for specific programming languages in other posts
There is two way to install emacs. Easy way is to use your package manager. If you are using debian derived system, just type
sudo apt-get install emacs23
I recommend to compile it yourself from source. It is really easy to do. Here is instructions to do it.
Go to emacs page and download latest version. By the time I wrote this it was emacs 23.3. Google for emacs and find project page. In there, you can find a link to download emacs. In my case I found the file emacs-23.3.tar.gz and untared it. The way I installed it, was the following.
First, I installed the dependencies for emacs. Easy way to do this is to use
apt-get build-dep command:
$sudo apt-get build-dep emacs23
Please note that this command will not install emacs23 instead it will only install dependencies to build it.
After that, you can Install emacs. Installation instructions was in emacs directory that I just untarred. (In the file named INSTALL). Here is the commands I followed:
(run in emacs directory you just untared) $./configure $make $sudo make install
configure: error: crt*.o not found. Use --with-crt-dir to specify the location.
So as error suggested I search for a crt*o file with command
sudo find / -name "crt*.o"
That way I found my crt directory in my case it was
So I run configure command as
After that every thing work as expected.
Since we finish installing emacs, we can start the hard part: setting it up. Create .emacs file and .emacs.d directory in ~/ . Also create plugins directory under .emacs.d
Now you should have:
~/.emacs (File) ~/.emacs.d/ (Directory) ~/.emacs.d/plugins/ (Directory)
After that, add .emacs.d and plugins directory to emacs load path:
To do this add following elisp script to your .emacs file (initialization file which will be run in initialization of emacs)
(add-to-list 'load-path “~/.emacs.d/”) (add-to-list 'load-path “~/.emacs.d/plugins/”)
Now you have .emacs.d and plugins directories on your load path. That means, any script you put in those directories will be executed in initialization of your editor.
IDO is a great emacs plugin that makes finding files and buffers very easy.
To enable it, Add the following script to your .emacs file
(require 'ido) (ido-mode t) (setq ido-enable-flex-matching t) ;; enable fuzzy matching
You didn't need to install it because it is already included in emacs 2.3.
For autocomplete mode, I went to this page and downloaded autocomplete 1.3.1. Page also has a link to
Autocomplete mode user manual. You can get installation information from there.
I installed it in following way:
The script I got was the following:
(add-to-list 'load-path "~/.emacs.d/plugins/autocomplete/") (require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d/plugins/autocomplete/ac-dict") (ac-config-default)
Add following script to your .emacs file
More info about installing yasnippet can be found here
File name is actually written in notification area but you cannot see where the file is located. So I prefer to add it to window title. To do this add the following script to your .emacs file. Try to change the format to fit your taste. After all that is all emacs is all about.
(setq frame-title-format '("Emacs @ " system-name ": %b %+%+ %f"))
If you want to change the colors in emacs, you can use preset themes for that. To install color themes go to color themes home page and download color-theme download it. Uncompress downloaded file (In my case, I downloaded color-theme.el.gz) and copy color-theme.el to somwhere in your load path(~/emacs.d/plugins/color-theme.el). After that, open el file and read the instructions which explains that in order to enable color themes you should copy following code to your .emacs file:
(require 'color-theme) (color-theme-gnome2)
(require 'color-theme) (color-theme-initialize) (color-theme-gnome2)
you can change color-theme-gnome2 method with another theme to change the default theme. available themes can be seen from Tools->Color Themes menu item. You can also color theme test project to choose a theme.
If you are also using emacs in terminal, you might want to use different theme for terminal. In order to achive that use following code instead of the one above:
(require 'color-theme) (if window-system (color-theme-subtle-hacker) (color-theme-hober))
In this code first theme is used if you open emacs in regular way. Second one is used if you open it in terminal (emacs -nw) (source: emacs-wiki)