Skip to content

ickma/.emacs.d-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warning

  • I’m using Vim key binding. Please see section Tips if you prefer the Emacs key binding.
  • People in Mainland China may need goagent to download packages from ELPA. Run command “http_proxy=http://127.0.0.1:8087 emacs -nw” after starting goagent server (or any proxy server).
  • C++/C developers, you need tell Emacs location of header files. You MUST see section `clang` now!
  • I suggest Windows users using Cygwin version Emacs to avoid overhead of setting up third party tools. But this configuration is still usable even in native windows Emacs if you set up environment variable HOME.
  • I whitelist packages from melpa because it is too cutting edge. Modify variable “melpa-include-packages” in init-elpa.el if prefer some package from it.
  • If you not are willing to or cannot fetch packages from remote repositories, see the section Install packages without elpa/marmalade/melpa.
  • In your bug report, please include details of environment (OS, Emacs version …) and the full output of `emacs –debug-init`.
  • Remove bundled emacs 22 at first if you are using OS X!
  • If you don’t want to use Emacs’ own package manager, please extract the your package’s source code at ~/.emacs.d/site-lisp. There are many samples there.

General

My first priority is stable. So I use fewer cutting-edge packages from melpa. If you want to get all the latest package from melpa, search the line containing “(setq package-filter-function nil)” in “init-elpa.el” and un-comment it.

Most modern popular programming languages are supported (C/C++/Java/Ruby/Perl/Python/C#/Lua/Javascript …).

Features

  • All key binding and plugins are usable in terminal
  • Real time HTML syntax checker enabled (you need install tidy or tidy-html5). I recommend tidy-html5.
  • git or subversion is NOT needed. You DONOT need run ‘git submodule update’.
  • optimized for cross-platform C++ development with CMake and wxWidgets
  • emacs-w3m (console browser)
  • eim (Chinese pinyin input method)
  • org2blog (post wordpress blog with org-mode)
  • make the configuration work on ALL platforms (Linux/Cygwin/Mac).
  • The configuration work with Emacs version >=24 but still usable with Emacs version 23 (tested with Emacs 23.4.1).
  • evil-mode and its plugins (Vim key binding)
  • yasnippet and my customized snippets (insert code snippet by typing less keys)

Install

Download this zip file and extract its content into ~/.emacs.d. Ensure that the ‘init.el’ contained in this repo ends up at ~/.emacs.d/init.el and old ~/.emacs IS REMOVED.

You possibly need run the below command in the terminal at least once to update the content from package repositories:

emacs -nw --batch -l ~/.emacs.d/init.el -f package-refresh-contents

If you cannot download packages from remote repository (for example, you are behind company firewall), don’t panic!

You do have USB stick, right?

Check the section Install packages without elpa/marmalade/melpa for solutions.

Quick guide

Step 1, Learn basic knowledge about OS

  • Know what’s environment variable
  • Know what’s pipe, stdout, stdin

Step 2, Read Emacs official tutorial at least once

Press “C-h t” (C means Ctrl) and start read tutorial.

  • Know how to move cursor
  • Know how to open help. Press “C-h v” and “C-h f”.

Step 3, Learn 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, use Emacs to solve your first specific problem

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

Directory structure

init.el is main file which include all the other *.el files.

init-elpa define how and what packages will be installed from elpa/marmalade/melpa by package manager.

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 Emacs package manager.

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

Other directoris do not matter.

Third party command line tools

These tools are OPTIONAL. Your Emacs will NOT crash if they are not installed.

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 (RECOMMENDED) or hunspell, and corresponding dictionary (aspell-en, for example)

  • needed by `flyspell`
  • hunspell is the alternative of `aspell`. So you need only install either aspell or hunspell.
  • install through OS package manager
  • I force the dictionary to “en_US” in init-spelling.el. You can modify it in init-spelling.el.

sbcl (lisp environment)

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

tidy (html tidy program) or html5-tidy (RECOMMENDED)

  • 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

csslint

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

zip and unzip

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

jshint (if you use js-mode instead js2-mode)

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

xsel

  • needed by my clipboard command `copy-to-x-clipboard` and `paste-from-x-clipboard` under Linux
  • install through OS package manager
  • needed by `cpputils-cmake`, `flymake`, `company-clang`
  • install through OS package manager
  • If you use `cpputils-cmake` and `cmake`, `cpputils-cmake` will do all the set up for you. You don’t need read next item!
  • If you use `company-clang`, add `(setq company-clang-arguments ‘(“-I/example1/dir” “-I/example2/dir”))` into ~/.emacs.d/init.el
  • P.S. Abandon ‘company-mode’, Use ‘auto-complete-mode’ now, see the commments in ‘init-auto.complete.el’
  • 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`

OS package manager recommended

Install packages without elpa/marmalade/melpa

Solution 1

Here are the exact steps you need follow:

  • Go to https://github.com/redguardtoo/myelpa.
  • Click “Download ZIP”
  • Extract zip somewhere say “~/myelpa”.
  • Double check that there is a file name “archive-contents” in the directory “~/myelpa”.
  • uncomment below code in ~/.emacs.d/init-elpa.el.
(setq package-archives '(("myelpa" . "~/myelpa/")))

That’s it. You will never need internet connection in the future.

Please note that all your packages are locked to the versions I’m using. So you can’t upgrade package online in the future.

I don’t recommend advanced users locking their package version.

Solution 2

If you are too lazy to download ZIP file, you can uncomment below code in ~/.emacs.d/init-elpa.el,

(setq package-archives '(("myelpa" . "https://raw.github.com/redguardtoo/myelpa/master/")))

Then you are good to go. Obviously you need internet connection to access github.com.

Report bug

Please file bug report at https://github.com/redguardtoo/emacs.d. Don’t send me email!

Tips

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

Some package cannot be downloaded automatically because of network problem.

You need manually `M-x list-packages` and install it or just `M-x package-refresh-content` and restart Emacs.

If you use `gnus` for email (Gmail, for example). Check ~/.emacs.d/init-gnus.el which includes my most settings except my private stuff. Here is my Gnus tutorial.

To toggle Chinese input method (eim, for example), press `C-` or run command `M-x toggle-input-method`(I bind it to `C-<SPC>` in evil-insert-state)

XML

  • completion: `C-M-i`
  • keep tags balanced and input the end-tag at the same time as the start-tag: `C-c C-i`
  • for block-level elements: `C-c C-b`
  • `/` automatically inserts the rest of the end-tag when it occurs after `<`

Mutlti-Window WorkingFlow

  • M-o to show the window-number
  • M-(num) to switch to the (num)th window
  • (C-x 1) to minimize the current window
  • (C-x 4 u) or “,wu” to undo the window-operation
  • (C-x 4 r) or “,wr” to redo the window-operation

Version Controll

  • Magit Install magit , then M-x magit-blahblah….

evil-leader

Configure your shotcuts in init-evil-leader.el.

Projectile

Providing a nice set of features operating on a project level.See https://github.com/bbatsov/projectile

Requiring find, xargs, git installed.

If your project directory isn’t gitted, you can touch .projectile in you project’s root directory.

The common commands:

  • “,pf” ‘projectile-find-file
  • “,pg” ‘projectile-grep
  • “,sp” ‘projectile-switch-project
  • “,pd” ‘projectile-find-dir-other-window
  • “,pD” ‘projectile-dired
  • “,p!” ‘projectile-run-shell-command-in-root

If you’d like to instruct Projectile to ignore certain files in a project, when indexing it you can do so in the .projectile file by adding each path to ignore, where the paths all are relative to the root directory and start with a slash. Everything ignored should be preceded with a - sign. Alternatively, not having any prefix at all also means to ignore the directory or file pattern that follows. Here’s an example for a typical Rails application:

-/log
-/tmp
-/vendor
-/public/uploads

ECB

Make your emacs closer to IDE. The shortcuts for ecb have been set in init-ecb.el

The layout of ECB can be modified in site-lisp/ecb/ecb-layout-defs.el And after you change the layout, you may `M-x ecb-byte-compile` to recompile the [yas] elisp error! Symbol’s function definition is void: ca-with-commentle

If you want to activate ECB, `M-x ecb-activate` or `,ea’ , then , when emacs shuts down , REMEMBER TO `m-X ECB-DEACTIVATE’ OR `,ED` TO SHUTDOWN ECB

Word Completion

  • type some prefix characters, then M-/

Path Completion

  • C-c C-i to input the path && C-j to insert it.
  • type some prefix characters, then M-/

Transparency

You can configure your own window transparency in .custom.el

Clang-Completion

You can use company-mode or auto-complete-mode. Comment out the “init-company” or “init-auto-complete” in init.el to choose either. The default is “company-[yas] elisp error! Symbol’s function definition is void: ca-with-comment”

Python

  • Grammar flycheck

`M-x python-check

  • Jedi

Jedi.el is a Python auto-completion package for Emacs. See http://tkf.github.io/emacs-jedi/latest/

Virtualenv is needed. Then, `M-x jedi:install-server RET

<C-tab> jedi:complete Complete code at point.

C-c ? jedi:show-doc Show the documentation of the object at point.

C-c . jedi:goto-definition Goto the definition of the object at point.

C-c , jedi:goto-definition-pop-marker Goto the last point where jedi:goto-definition was called.

  • Pyvenv

Jedi uses the variable VIRTUAL_ENV to determine which the virtualenv to use(the default is .emacs.d/.python-enviroments), So I use pyvenv to change the workon virtualenv.

Firstly, install virtualenvwrapper

Pust the following code in your .bashrc/.zshrc:

if [ `id -u` != '0' ]; then
export VIRTUALENV_USE_DISTRIBUTE=1        # <-- Always use pip/distribute
export WORKON_HOME=$HOME/.virtualenvs       # <-- Where all virtualenvs will be stored
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
fi

mkdir .virtualenvs in you home directory, and put your virtualenv in it. if you virtualenvs is system-wide spreaded, you may make a symbolic link in .virtualenvs.

When you’re in python-mode, Jedi uses .emacs/.python-enviroments as the default virtualenv, you can change it by M-x pyvenv-workon and choose the one you want, then `M-x jedi:stop-sever` to restart jedi (the words underscored is not necessarily if you use my pyvenv.el, because I’ve refined it and it will restart jedi automatically)

Auto-completion Popup Face

  • In the elpa/popup/popup.el,modify the color of the “popup-face” & “popup-menu-selection-face” “popup-tip-face”
 (defface popup-face
'((t (:background "yellow" :foreground "black"))))

 (defface popup-menu-selection-face
'((t (:background "orange" :foreground "black"))))

 (defface popup-tip-face
'((t (:background "orange" :foreground "black"))))
  • In the auto-complete-clang.el, modify the color of the “ac-clang-candidate-face” & “ac-clang-selection-face”
  • In the auto-complete-config.el, modify the color of yasnippet & gtags face.
  • After modification, you must `M-x byte-recompile-file`

Code Map

  • M-x minimap-mode

Source Reading

xcscope.el

  • n/p navigates over individual results
  • k kills individual results
  • N/P or M-n/M-p navigates over file results
  • M-k kills file results
  • M-N/M-P navigates over result sets
  • M-K kills result sets
  • Navigation from outside the cscope buffer (C-c s n/p/N/P) is restricted to the result set at (point)
  • Keybindings:

All keybindings use the “C-c s” prefix:

C-c s sFind symbol.
C-c s =Find assignments to this symbol
C-c s dFind global definition.
C-c s gFind global definition (alternate binding).
C-c s GFind global definition without prompting.
C-c s cFind functions calling a function.
C-c s CFind called functions (list functions called from a function).
C-c s tFind text string.
C-c s eFind egrep pattern.
C-c s fFind a file.
C-c s iFind files #including a file.

These pertain to navigation through the search results:

C-c s bDisplay cscope buffer.
C-c s BAuto display cscope buffer toggle.
C-c s nNext symbol.
C-c s NNext file.
C-c s pPrevious symbol.
C-c s PPrevious file.
C-c s uPop mark.

These pertain to setting and unsetting the variable, `cscope-initial-directory’, (location searched for the cscope database directory):

C-c s aSet initial directory.
C-c s AUnset initial directory.

These pertain to cscope database maintenance:

C-c s LCreate list of files to index.
C-c s ICreate list and index.
C-c s EEdit list of files to index.
C-c s WLocate this buffer’s cscope directory (“W” –> “where”).
C-c s SLocate this buffer’s cscope directory. (alternate binding: “S” –> “show”).
C-c s TLocate this buffer’s cscope directory. (alternate binding: “T” –> “tell”).
C-c s DDired this buffer’s directory.

CTAGs

  • ctags -R -e *.h *.cpp
  • C-] to find-definition , C-t to pop

GGtags

To replace cscope, global is required.

Before using the ggtags or helm-gtags, remember to create a GTAGS database by running gtags at your project root in terminal:

cd /path/to/project/root
gtags

If you use ggtags, you have a command for creating GTAGS database, that is ggtags-create-tags; this is recommended way when using ggtags, to let it know where the project root is.

Basic movements

  • %: move around over a balanced expression that can be a pair or a symbol
  • v%: rusn mark-sexp, put mark after following expression that can be a pair or a symbol
  • C-M-a: runs beginning-of-defun, which moves point to beginning of a function
  • C-M-e: runs end-of-defun, which moves point to end of a function
  • C-M-h: runs mark-defun, which put a region around whole current or following function

Find definitions in current buffer

semantic-mode should be enabled. You can add it to the specific mode you want in init-ggtags.el, like this:

(add-hook 'c-mode-hook 'semantic-mode)
(add-hook 'c++-mode-hook 'semantic-mode)
(add-hook 'python-mode-hook 'semantic-mode)
(add-hook 'asm-mode-hook 'semantic-mode)

M-x helm-semantic-or-imenu or <evil-leader>gcd , please notice the “pattern: ” prompt in the minibuffer, you can type func to narrow the candidates that are functions, class for that are classes and var that are variables.

Find definitions in project

  • <evil-leader>gt, which runs ggtags-find-tag-dwim, this command jump to tag base on context:
    • If the tag at point is a definition, ggtags jumps to a reference. If there is more than one reference, it displays a list of references.
    • If the tag at point is a reference, ggtags jumps to tag definition.
    • If the tag at point is an include header, it jumps to that header.

    M-n and M-p to go to the next and previous file.

    M-< and M-> for the first and the last.

    M-* to abort and go back to the location where the search was started

    You can also find arbitrary tag definition when invoking ggtags-find-tag-dwim on blank space. A prompt asks you for tag pattern, which is a regexp.

  • M-, , which runs pop-tag-mark to jump back to original location

Find files in project

If point is on an included header file, <evil-leader>gt or ggtags-find-tag-dwim automatically jumps to the file.

View visited tags with tag stack

<evil-leader>gp, which runs ggtags-prev-mark <evil-leader>gn, which runs ggtags-next-mark <evil-leader>gsh, which runs ggtags-view-tag-history that shows visited tags from newest to oldest, from top to bottom.

Update Tags

When file is saved, tags will be automatically updated. If failed, “<evil-leader>gu” to update it manually.

Source Editing

Narrowing

Narrowing means making only a text portion in current buffer visible. Narrowing is useful when you want to perform text editing on a small part of the buffer without affecting the others. For example, you want to delete all printf statements in current functions, using flush-lines command. But if you do so, you will also delete printf outside the current function, which is undesirable. By narrowing, you can safely remove all those printf and be certain that nothing else is changed accidentally.

Default key bindings:

  • narrow-to-defun, Narrow buffer to current function at point
  • narrow-to-region
  • widen, Widen buffer

Source Compilation

When you want to compile the source code, you can type `M-x compile` or type `,cp`, then type the compiling command, such as `gcc blabla` for c/c++ source code, or `python blabla` for python code.

About Emacs23

Emacs23 support will be dropped in one year <2015-04-24 Thu>. Currently Emacs 23 will not support below packages:

  • helm
  • org-mode and its third party packages
  • company-mode

About

purcell's emacs configuration plus C/C++ support

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 89.4%
  • Common Lisp 5.0%
  • Python 2.8%
  • Roff 0.6%
  • Scheme 0.6%
  • TeX 0.5%
  • Other 1.1%