- Tested with Emacs 24.3.1, 24.4, 24.5, 25.1, 25.2 on Linux/Windows/Cygwin/Mac (I will stop 24.3 support at <2018-01-01>)
- Please read FAQ to disable Vim key bindings
- Please read section “Key bindings” to learn key bindings
- If you use Windows Emacs, you have to install GnuTLS Dlls manually to be able to install packages from remote repositories
- Most packages from MELPA are invisible while packages from MELPA Stable are visible. You can modify variable
melpa-include-packages
in~/.emacs.d/lisp/init-elpa.el
to install unstable packages - Please read section “About Emacs 23” if you uses Emacs 23.4
- Other issues are covered in FAQ
- Stable, Emacs will never crash after a full package upgrade
- Efficient, tested on 10 years old computer
- Native key bindings are preserved
- Usable in emacs-nox, all key bindings and functionality still usable when you ssh to server with PuTTY
- Robust, you can install packages without network access
- Popular programming languages are supported, C/C++/Java/Ruby/Perl/Python/C#/Lua/Javascript …
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
Please remove the file ~/.emacs.d/init.el
and ~/.emacs
. ~
in Home directory.
Please uninstall any package which is not installed at ~/.emacs.d
. For example, run apt-get autoremove emacs-w3m
on Debian/Ubuntu.
If you don’t know what I mean, then do nothing.
All packages should be placed at ~/.emacs.d
from now on.
There are two ways to install this setup (I recommend the first way):
- download latest setup and extract its content into
~/.emacs.d
, OR run commandcd ~; git clone https://github.com/redguardtoo/emacs.d.git .emacs.d
in shell. - use stable setup, OR run command
cd ~; git clone https://github.com/redguardtoo/emacs.d.git .emacs.d; cd .emacs.d; git reset --hard stable
in shell.
Ensure that the init.el contained in this repo ends up at ~/.emacs.d/init.el.
By default, packages are installed automatically during Emacs startup.
You only need two zip files instead of git or network.
Here are the exact steps,
- Remove
~/.emacs
. - Download https://github.com/redguardtoo/emacs.d/archive/stable.zip
- Extract its content into empty directory
~/.emacs.d
- Download https://github.com/redguardtoo/myelpa/archive/stable.zip
- Extract the zip somewhere, say
~/projs/myelpa
- Make sure a file named
archive-contents
exists in~/projs/myelpa
- Add
(setq package-archives '(("myelpa" . "~/projs/myelpa/")))
into~/.emacs.d/lisp/init-elpa.el
- Start Emacs now!
Now you are using local package repository ~/projs/melpa
.
You can switch to online repositories like http://elpa.gnu.org or http://melpa.org by modifying ~/.emacs.d/lisp/init-elpa.el
.
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 …)
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.
- Required by
w3m
(w3m is emacs package name written in elisp) - Install through OS package manager
- Please note only emacs with GUI can display image
- Required by
flymake-lua
- Install through OS package manager
- Required 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
aspell-en
- I force the dictionary to “en_US” in
~/.emacs./lisp/init-spelling.el
. You can modify it. - I recommend aspell for programmers
- Required by lisp
slime
- Install through OS package manager
- Required by
web-mode
for syntax check andtidy.el
html formatting - Install through OS package manager
- Install
node.js
through OS package manager, thennpm install -g csslint
identify from ImageMagick
- Required by
org-mode
to export org file to odt file when image embedded - Install through OS package manager
- Required by
org-mode
to export org file to odt file - Install through OS package manager
- Install
node.js
through OS package manager, thennpm install -g jshint
- required by js-mode
- by default I use js2-mode which does NOT need jshint
- Required by my clipboard command
copy-to-x-clipboard
andpaste-from-x-clipboard
under Linux - Install through OS package manager
- Required by
cpputils-cmake
- Install through OS package manager
- Please use out-of-source build tree when using CMake
- Required by
cpputils-cmake
,company-clang
- Install through OS package manager
- If you use
cpputils-cmake
andcmake
,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
- Required by
flymake
- Install through OS package manager
- Required by MozRepl
- Used by Firefox
- It creates tags file for code navigation and code completion
- Required by many tags related packages
- Install through OS package manager
- See How to use ctags in Emacs effectively
- Required by
ggtags.el
- It creates index files for code navigation and auto-completion
- More advanced than ctags, supports references and has better performance
- Install through OS package manager
- Only the executable
soffice
is used when converting odt file into doc/pdf - conversion happens automatically when exporting org-mode to odt
- The conversion command is in variable
org-export-odt-convert-processes
- Install through OS package manager
- Beautify javascript code
- Install pip through OS package manager, then
pip install jsbeautifier
- syntax check Erlang through flymake
- Install from https://github.com/ten0s/syntaxerl
- Required by elpy which is python IDE
- At least
pip install jedi flake8
. Check elpy website for more tips.
- Required by sdcv.el
- Install through OS package manager
- Run
curl http://abloz.com/huzheng/stardict-dic/dict.org/stardict-dictd_www.dict.org_wn-2.4.2.tar.bz2 | tar jx -C ~/.stardict/dic
to install dictionary
- Used by
M-x my-grep
to search text in files - Run
curl https://sh.rustup.rs -sSf | sh
in shell to install Rust thencargo install ripgrep
- Tweak environment variable PATH to let Emacs find ripgrep
- Used by
M-x my-grep
to search text in files if ripgrep not installed - Install through OS package manager
~/.emacs.d/lisp/init-evil.el
list my frequently used key bindings.
Everyone should finish this tutorial at first.
At minimum you need know,
- What is Environment Variable
- What is Pipeline (Unix), Standard Streams
The purpose it to know how Emacs interacts with other command line programs.
Press C-h t
in Emacs (“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
andC-h f
.
Org-mode is for notes-keeping and planning.
Please watch Carsten Dominik’s talk. It’s really simple. The only hot key to remember is Tab
.
You can visit EmacsWiki for the solution. Newbies can ask for help at http://www.reddit.com/r/emacs/.
Required for vim user,
- Finish vimtutor.
- Read ~/.emacs.d/site-lisp/evil/doc/evil.pdf
Key bindings are defined in ~/.emacs.d/lisp/init-evil.el
.
For example, (nvmap :prefix "," "bu" 'backward-up-list)
means pressing “,bu” executes command backward-up-list
.
The tutorials I recommended provide enough information about commands.
Besides, ”How to be extremely efficient in Emacs” lists my frequently used commands.
You can override default key bindings in ~/.custome.el
.
Check https://emacsthemes.com/.
Write down the name of color theme (for example, molokai).
Insert below code into “~/.emacs.d/lisp/init-color-theme.el”,
;; the color theme name "molokai"" could be replaced with other theme name
(require 'color-theme-molokai)
(color-theme-molokai)
M-x color-theme-select
may not work because of some design flaw in Emacs.
There is NO unified way to enable color theme because two color theme systems exist. You need read color theme’s documentation at first.
My code works for most color themes.
If you insist on configuring the color theme in a different way, please,
- Comment out the line containing
(require 'init-color-theme)
in~/.emacs.d/init.el
at first - Read EmacsWiki
Start Emacs this way,
TERM=xterm-256color emacs -nw
By default color-theme-molokai is used.
But you can run the M-x my-toggle-color-theme
to switch to the fallback theme color-theme-deep-blue
.
You can change the definition of my-toggle-color-theme
in init-color-theme.el
.
I use modified version of git-gutter
for now until my pull request is merged into official repository.
You can set git-gutter:exp-to-create-diff
to make git gutter support other VCS (Perforce, for example),
(setq git-gutter:exp-to-create-diff
(shell-command-to-string (format "p4 diff -du -db %s"
(file-relative-name buffer-file-name))))
Please M-x multi-term
.
If you want to use Zsh instead of Bash, please modify init-term-mode.el
Non-Chinese use unicode-fonts.
Chinese use chinese-fonts-setup.
They are not included in this setup. You need install them manually.
Synchronize from my stable setup which is updated every 6+ months:
git pull https://[email protected]/redguardtoo/emacs.d.git stable
Or latest setup which is unstable:
git pull https://[email protected]/redguardtoo/emacs.d.git
If you don’t like 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
Learn basics. Then use my solution.
Please note paredit-mode is enabled when editing Lisp. Search “paredit cheat sheet” to learn its key bindings.
Use smart-mode-line or powerline?
Comment out (require 'init-modeline)
in init.el at first.
Other desktop applications may intercept the key bindings. For example, someone reported QQ on windows 8 can intercept `M-x’.
If key bindings of multiple plugins conflict, I preserve the key bindings for the more frequently used plugin.
I re-assign the alternative key bindings to less used plugins. Check ~/.emacs.d/lisp/init-evil.el
for details.
Press M-x org-version
, then read corresponding online manual to setup.
For example, org-capture
need your manual setup.
Please replace legacy Emacs 22 and ctags with the new versions.
The easiest way is change Environment variable PATH.
Some packages (Evil, Web-mode …) are so important to my workflow so they are locked.
Those packages are placed at ~/.emacs.d/site-lisp
.
They will not be upgraded through ELPA unless you delete them at ~/.emacs.d/site-lisp
.
Some variables are hard coded so you cannot “M-x customize” to modify them.
Here are the steps to change their values:
- Find the variable description by
M-x customize
- For text “Company Clang Insert Arguments”, search
company-clang-insert-argument
in~/.emacs.d/lisp/
- You will find
~/.emacs.d/lisp/init-company.el
and modifycompany-clang-insert-argument
BTW, please read my comments above the code at first.
If you press C-x C-f
to open a file, Ido will show the suggestions.
Keep pressing C-f
to ignore suggestions.
I strongly suggest Cygwin version of Emacs. But native windows version is OK if it knows how to find the third party command line tools. Cygwin provides most of those tools by default. Add C:\Cygwin64\bin
to environment variable PATH
so Emacs can detect the tools automatically.
By default, environment variable HOME
points to the directory C:\Users\<username>
on Windows 7+. You need copy the folder .emacs.d
into the directory.
Instead of M-x yas-expand
or press TAB key, you may press M-j
instead.
Locale must be UTF-8 compatible. For example, as I type locale
in shell, I got the output “zh_CN.UTF-8”.
Run below command in shell:
http_proxy=http://yourname:[email protected]:8080 emacs -nw
You may need goagent. Run command http_proxy=http://127.0.0.1:8087 emacs -nw
in shell after starting goagent server.
If you use Gnus for email, check init-gnus.el and read my Gnus tutorial.
Some package cannot be downloaded automatically because of network problem.
You could,
M-x list-packages
to manually install it- Or
M-x package-refresh-content
and restart Emacs. the package will be installed automatically.
By default EVIL (Vim emulation in Emacs) is used. Comment out line containing (require 'init-evil)
in init.el to unload it.
It’s defined in ~/.emacs.d/lisp/init-evil.el
. Press C-z
to switch between Emacs and Vim key bindings.
Please read its PDF manual before using evil-mode.
I assume you are using company-mode. Other packages have similar setup.
There are many ways to scan the C++ source files and create the candidates used by company frontend. The Emacs Lisp code and command line tools to scan the C++ files are company backends. company-clang
is a popular backend because Clang is good at processing C++.
If you use clang to parse the C++ code:
- Make sure code is syntax correct
- assign reasonable value into company-clang-arguments
Here is sample code:
(setq company-clang-arguments '("-I/home/myname/projs/test-cmake" "-I/home/myname/projs/test-cmake/inc"))
In “friendly” Visual C++, similar setup is required.
You can use other company backends instead of company-clang
. For example, you can use company-gtags
and GNU Global instead. See Emacs as C++ IDE, easy way for details.
Other backends produce less precise results but are more efficient and easier to setup.
It’s similar to C++ setup. You can use company as frontend. But backend is the key. For example, you can’t use company-clang
for PHP because Clang can’t handle PHP. But GNU Global supports PHP, so you can use company-gtags
instead.
For languages GNU Global doesn’t support, you can always fallback to company-etags
and Ctags by using regular expression. Regular expressions could be placed in ~/.ctags
.
M-x toggle-input-method
to toggle input method chinese-pyim.
If your personal dictionary ~/.eim/personal.pyim
exists, it will be used.
You can M-x my-pyim-export-dictionary
to export your personal words into personal.pyim.
We use minimum setup recommended by chinese-pyim site.
You can override our setup in ~/.custom.el
,
(eval-after-load 'chinese-pyim
'(progn
;; Use great dictionary which can be fetch by:
;; `curl -L https://github.com/tumashu/chinese-pyim-greatdict/raw/master/pyim-greatdict.pyim.gz | zcat > ~/.eim/pyim-greatdict.pyim`
(if (and my-pyim-directory
(file-exists-p (my-pyim-personal-dict "pyim-greatdict.pyim")))
(add-to-list 'pyim-dicts (list :name "pyim-greatdict" :file (my-pyim-personal-dict "pyim-greatdict.pyim"))))))
Run below commands in shell:
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-x --without-dbus --without-sound && make && make install
Feel free to replace 24.3 with other version number.
Insert below code into ~/.emacs
or =~/.custom.el,
;; Use en_US locale to format time.
;; if not set, the OS locale is used.
(setq system-time-locale "C")
~/.emacs.d/init.el
is the main file. It includes all the other *.el files.
~/.emacs.d/lisp/init-elpa.el
defines what packages will be installed from MELPA.
Packages are installed into ~/.emacs.d/elpa/
.
I also manually download and extract some packages into ~/.emacs.d/site-lisp/
. Packages in ~/.emacs.d/site-lisp/
are not visible to the package manager.
My own snippets for Yasnippet is at ~/.emacs.d/snippets
.
Other directories don’t matter.
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:
- Download https://github.com/redguardtoo/emacs.d/archive/1.2.zip
- Download https://github.com/redguardtoo/myelpa/archive/1.2.zip
- Follow the section
Install stable version in easiest way
but skip the download steps
Since most third party plugins don’t support Emacs 23 any more, I strongly recommend upgrading to Emacs 24!
- 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. Please read the chapters “Git Basics”, “Git Branching”, “Git Tools” from Pro Git
- Please check EmacsWiki and my FAQ at first to find a solution
- If your issue is still NOT resolved, restart Emacs with option
---debug-init
, runM-x toggle-debug-on-error
in Emacs, reproduce the issue - Send the error messages to the original developer if it’s third party package issue
- If you are sure it’s my issue, file bug report at https://github.com/redguardtoo/emacs.d. Don’t email me directly!
Bug report should include details (OS, Emacs version …).