Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
purcell's emacs configuration plus C/C++ support
Emacs Lisp Common Lisp Scheme Makefile Ruby HTML
Branch: master
Pull request Compare This branch is 1948 commits ahead, 641 commits behind purcell:master.

README.org

Before start

Please read below checklist at least once:

  • You can make this setup more stable
  • I recommend Emacs 24.3.1 or 24.4
  • Tested with v24.3.1, v24.4, v24.5 on ALL platforms (Linux/Windows/Cygwin/Mac)
  • Check section “About Emacs 23” if you uses Emacs 23.4
  • Please read FAQ to disable default Vim key bindings
  • Packages from melpa-unstable are invisible by default. Modify variable melpa-include-packages in init-elpa.el if you need package from melpa-unstable
  • Other issues are covered in FAQ

Features

  • Stable is the first priority
  • I do NOT re-define key bindings, so original key bindings are still there
  • 100% usable in terminal
  • Popular languages are supported (C/C++/Java/Ruby/Perl/Python/C#/Lua/Javascript …)
  • Minimum dependency (For example, network connection is OPTIONAL to install packages)
  • Optimized for cross-platform C++ development

Installation

Minimum installation

Most users should follow the section “Install in normal way”.

You need the section “Install stable version in easiest way” if and only if:

  • You are absolutely newbie, knowing nothing about Linux/Unix
  • You are living in North Korea without internet access

Install in normal way

Please remove the file “~/.emacs.d/init.el” and “~/.emacs”. “~” means the parent directory of your “.emacs.d”.

Uninstall any package which not located in “~/.emacs.d”. For example, run “apt-get autoremove emacs-w3m” on Debian/Ubuntu.

All packages should be placed at “~/.emacs.d” from now on.

There are three ways to install this setup: Way 1, Download latest setup and extract its content into “~/.emacs.d”.

Way 2, you’ve installed Git, run command `cd ~; git clone https://github.com/redguardtoo/emacs.d.git .emacs.d` in terminal.

Way 3, you can use stable setup which has been regression tested by volunteers every 3 months.

Ensure that the init.el contained in this repo ends up at ~/.emacs.d/init.el.

Install stable version in easiest way (OPTIONAL)

You don’t need git or network any more. All you need are only two zip files.

Here are the exact steps to follow:

  • Remove the file “~/.emacs”.
  • Download https://github.com/redguardtoo/emacs.d/archive/1.2.zip
  • Extract its content into empty directory “~/.emacs.d” (“~” means home directory, the environment variable HOME contains the path of home directory). After extraction, there will be a file named “init.el” in “~/.emacs.d”
  • Download https://github.com/redguardtoo/myelpa/archive/1.2.zip
  • Extract the zip somewhere, say “~/projs/myelpa”.
  • Double check that there is a file named “archive-contents” in the directory “~/projs/myelpa”
  • Uncomment below code in init-elpa.el and start Emacs now!
(setq package-archives '(("myelpa" . "~/projs/myelpa/")))

That’s it. You will never need internet in the future. I tested it on Emacs 24.3.93.1, Emacs 24.3.1 and Emacs 23.4.

Please note that your packages are locked. So you cannot upgrade package online in the future unless you comment out above code line.

Third party tools (OPTIONAL)

Installation

You can install them in any way you like. But “OS package manager” is easier.

“OS package manager” means:

  • apt-cyg at Cygwin
  • homebrew at Mac
  • any package manager at Linux (apt-get at Ubuntu, yum at Redhat, pacman at Arch, emerge at Gentoo …)

Tools List

These tools are OPTIONAL.

Please ignore any related error message. For example, if aspell and hunspell are not installed, you can ignore all the flyspell error messages.

w3m (web browser in console)

  • needed by `w3m` (w3m is emacs package name written in elisp)
  • install through OS package manager
  • please note only emacs with GUI can display image

lua

  • required by `flymake-lua`
  • install through OS package manager

aspell or hunspell

  • needed by `flyspell`
  • hunspell is the alternative of `aspell`. So you need only one of them.
  • install through OS package manager
  • for aspell, you may need its dictionary like aspell-en
  • I force the dictionary to “en_US” in init-spelling.el. You can modify it.
  • I recommend aspell for programmers

sbcl (lisp environment)

  • needed by lisp `slime`
  • install through OS package manager

tidy or html5-tidy

  • needed by `web-mode` for real time HTML syntax check
  • install through OS package manager
  • For html5-tidy, you need download its source code and build it manually
  • I recommend html5-tidy because it supports html5, obviously

csslint

  • install `node.js` through OS package manager, then `sudo npm install -g csslint`

zip and unzip

  • needed by `org-mode` to export org file to odt file
  • install through OS package manager

jshint

  • install `node.js` through OS package manager, then `sudo npm install -g jshint`
  • required by js-mode
  • by default I use js2-mode which does NOT need jshint

xsel

  • needed by my clipboard command `copy-to-x-clipboard` and `paste-from-x-clipboard` under Linux
  • install through OS package manager

CMake

Clang

  • needed by `cpputils-cmake`, `company-clang`
  • install through OS package manager
  • If you use `cpputils-cmake` and `cmake`, `cpputils-cmake` will do all the setup for you. You don’t need read next item! But please spend a few minutes to learn the basics of cmake! There is a one minute step-by-step-guide in README of cpputils-cmake to teach you how to use cmake.
  • If you use `company-clang`, add `(setq company-clang-arguments ‘(“-I/example1/dir” “-I/example2/dir”))` into ~/.emacs.d/init.el

GCC/Make

  • needed by `flymake`
  • install through OS package manager

MozRepl (Firefox addon)

  • needed by MozRepl
  • used by Firefox

CTags

GNU Global

  • needed by `ggtags.el`
  • it creates index files for code navigation
  • more advanced than ctags, supports references and better performance
  • install through OS package manager

pyflakes

  • You need pyflakes for real time python syntax checker like `flymake-python`
  • Install pip through OS package manager, then `pip install pyflakes`
  • On cygwin you need install `setuptool` in order to install `pip`.

libreoffice

  • Only one executable `soffice` needed when converting odt file into doc (Microsoft Word 97)
  • conversion will happen automatically when exporting org-mode to odt
  • The conversion command is in variable `org-export-odt-convert-processes`
  • Install through OS package manager

js-beautify

  • To beautify javascript code (insert extra space, for example)
  • Install pip through OS package manager, then `pip install jsbeautifier`

syntaxerl

jedi & service_factory

  • Python 3rd party packages installed through `pip install jedi service_factory`
  • Required by anaconda-mode which provides Python intellisense
  • If you feel anaconda-mode make Emacs less responsive, disable it by remove line `(anaconda-mode)` in init-python-mode.el

Tutorial (OPTIONAL)

Basic tutorial

Step 1, learn OS basics

Read wikipedia in order to know,

  • What is environment variable
  • What is pipe, stdout, stdin

Step 2, read official tutorial at least once

Press “C-h t” (“C” means Ctrl key, “M” means Alt key) to read bundled tutorial.

At minimum you need know:

  • How to move cursor
  • How to read help by pressing “C-h v” and “C-h f”.

Step 3, know org-mode basics

Org-mode is a for notes-keeping and planning. Please watch the Carsten Dominik’s talk. It’s really simple. The only hot key you need remember is “Tab”.

Step 4, solve your first problem

For that problem, you can visit EmacsWiki for the solution. Newbies can ask for help on http://www.reddit.com/r/emacs/.

Advanced tutorial

See Master Emacs in One Year.

FAQ

How to setup smart-mode-line or powerline?

Comment out `(require ‘init-modeline)` in init.el at first.

Emacs is not responsive?

  • Disable flymake by commenting out line `(flymake-mode 1)` in “~/.emacs.d/lisp/init-*.el”
  • Disable flyspell by commenting out line `(flyspell-mode 1)` in “~/.emacs.d/lisp/init-*.el”

Why certain key binding doesn’t work?

Other softwares may intercept the key bindings. For example, someone reported QQ on windows 8 can intercept `M-x`.

My frequently used commands

They are listed at “lisp/init-evil”. I use evil-leader to assign hot keys for them.

OS X user?

Please remove bundled emacs 22 at first!

You may need remove the obsolete ctags/etags too.

To find out the version of your Emacs/Ctags, please run below command in shell:

emacs --version
ctags --version

Important packages are locked

Some packages (Evil, Helm, Web-mode …) are so important to my workflow that I locked their versions.

Those packages are placed at “~/.emacs.d/site-lisp”.

They will not be upgraded through ELPA automatically unless you delete corresponding folders at “~/.emacs.d/site-lisp”.

Customize global variables

Some variables are hard coded in this setup so you cannot “M-x customize” to modify them.

So you have to modify it by tweaking Emacs Lisp code.

Here are the steps:

  • Find the variable description by “M-x customize”. The description is “Company Clang Insert Arguments”, for example
  • Search text “company-clang-insert-argument” in files in ~/.emacs.d/lisp/
  • Find “init-company.el” and modify company-clang-insert-argument’s value

BTW, please read my comments above the code at first.

Open file with Ido

If you press `C-x C-f` to open a file, Ido will show the completions.

You can keep pressing `C-f` to ignore the completions and input path manually.

C++ developers?

You need set up the directories to seach C++ header files. Please see the section `clang`.

If you don’t use cmake, you could disable flymake-mode in init-cc-mode.el.

Use Emacs on Windows?

I strongly suggest Cygwin. But the setup is still usable in native windows version if you set up environment variable HOME.

Yasnippet key bindings

Instead of “M-x yas-expand”, you can use hotkey “C-c k” globally and “M-j” in evil-insert-mode.

I don’t suggest use default TAB key to expand snippet because TAB keys is used by other plugins

MELPA does not include the package?

If a package is not installable through MELPA, you can place its source code at “~/.emacs.d/site-lisp” instead. There are already some samples there.

Non-English users?

Please make sure your locale is UTF-8 compatible. For example, if I type `locale` in shell, I will get the output “zh_CN.UTF-8”.

Behind Corporate firewall?

In shell, input below commmand:

http_proxy=http://yourname:passwd@proxy.company.com:8080 emacs -nw

Your government blocks the internet?

People in China, North Korea, Cuba, Iran need goagent to download packages. Run command “http_proxy=http://127.0.0.1:8087 emacs -nw” in shell after starting goagent server.

Email setup?

If you use Gnus for email (Gmail, for example), check init-gnus.el. Then read my Gnus tutorial.

How to toggle Chinese input method?

Run command `M-x toggle-input-method`.

Cannot download packages through ELPA?

Some package cannot be downloaded automatically because of network problem.

You could

  • `M-x list-packages` to manually install it
  • Rr `M-x package-refresh-content` and restart Emacs. the package will be installed automatically

Use Emacs original key bindings

By default EVIL (Vim emulation in Emacs) is used. You can comment out line containing “(require ‘init-evil)” in init.el to unload it.

Evil setup

It’s defined in “init-evil.el”. You can press “C-z” to switch between Emacs and Vim key bindings in evil-mode.

Please reading its PDF manual before using evil-mode.

Why C++ auto-completion doesn’t work?

I assume you are using company-mode. Other packages have similar setup.

At minimum:

  • You need install clang
  • Make sure your code is syntax correct at the beginning
  • assign reasonable value into company-clang-arguments

Here is sample setup in “~/.emacs.d/init.el”:

(setq company-clang-arguments '("-I/home/myname/projs/test-cmake" "-I/home/myname/projs/test-cmake/inc"))

In “friendly” Visual C++, you need do similar setup.

Enable color theme in terminal

TERM=xterm-256color emacs -nw

Preview&Apply a color theme

Check http://emacsthemes.caisah.info/.

Write down the name of color theme (for example, molokai).

Insert below code into ~/.emacs.d/init.el,

(require 'color-theme-molokai)
(color-theme-molokai)

“M-x color-theme-select” may not work because of some design flaw in Emacs.

Please note similar color themes may have different ways to enable. Please read theirs documentation.

My above sample code works for most color themes, but there is always exceptions.

Update from my latest setup

I suggest pulling from the version tagged as “stable”:

git pull https://github.com/redguardtoo/emacs.d.git stable

If you don’t like some of my commits, you can revert them:

# always start from the latest related commit
git revert commit-2014-12-01
git revert commit-2014-11-01

Chinese Input Method Editor

By default, the word files path is at “~/.eim/py.txt”. I place it out of the emacs root folder in order to protect my privacy.

The path can be changed in init-eim.el.

A sample file can be downloaded HERE. After downloading, rename it to py.txt.

Install Emacs at home directory

Run below commands:

mkdir -p ~/tmp;
curl http://ftp.gnu.org/gnu/emacs/emacs-24.3.tar.gz | tar xvz -C ~/tmp/emacs-24.3
cd ~/tmp/emacs-24.3;
mkdir -p ~/myemacs/24.3;
rm -rf ~/myemacs/24.3/*;
./configure --prefix=~/myemacs/24.3 --without-gtk --without-gtk3 --without-aqua --without-x --without-xpm --without-png --without-gif --without-alsa --without-tiff --without-jpeg --without-aqua --without-rsvg --without-xft --without-xaw3d --without-xim --without-xpm --without-dbus --without-makeinfo --with-x-toolkit=no --without-sound --without-sync-input --without-pop;make;make install

Feel free to replace 24.3 with other version number.

Tips

  • Never turn off any bundled mode if it’s on by default. Future version of Emacs may assume it’s on. Tweak its flag in mode hook instead!
  • Git skills are extremely useful for maintainting your emacs.d in the long term

Report bug

Check EmacsWiki and my FAQ at first.

File bug report at https://github.com/redguardtoo/emacs.d. Don’t email me directly!

Please contact the original developer if you find any bug from third party packages.

Bug report should include details (OS, Emacs version …) plus the output of `emacs –debug-init` at minimum.

Misc

Directory structure

init.el is the main file. It includes all the other *.el files.

“init-elpa.el” defines how and what packages will be installed from MELPA.

The package manager will extract packages into ~/.emacs.d/elpa/.

I also manually download and extract some packages into ~/.emacs.d/site-lisp/. Packages in ~/.emacs.d/site-lisp/ is not visible to the package manager.

My own snippets for Yasnippet is at ~/.emacs.d/snippets.

Other directories don’t matter.

About Emacs 23

Emacs 23 support was dropped on <2015-04-21>.

The latest Emacs23 compatible version of setup is 1.2!

Here are the steps to use that setup:

Since most third party plugins don’t support Emacs 23 any more. I strongly recommend you upgrading to Emacs 24 instead!

Emacs is portalbe on any platform. So you can install Emacs even when you are not root of the Linux server. Please read previous “Install Emacs at home directory” for HOW.

Something went wrong with that request. Please try again.