Back to Table of Contents

Emacs Mini Manual (PART 3) - CUSTOMIZING AND EXTENDING EMACS

Table of Contents

Why customize and extend Emacs?

Emacs comes with default settings. Some interesting features are disabled and hidden, i.e. ibuffer, Semantic, electric modes… Probably, to make it more user friendly to new users and make it behave more like "normal" editors, i.e. Normal users do not expect automatic pairing of punctuation marks like parentheses, brackets, curly brackets…

Because the nature of Emacs is an extensible system, people write extensions to improve Emacs and share with others. The extensions improve various aspects of Emacs: Improve existing and add new editing features, integrate 3rd party tools, add programming languages supports, change Emacs appearance… Without the ability to extend, Emacs will just be another obscure editor with some useful features but cannot meet the demands of people, because different people have different needs, and Emacs maintainers cannot provide them all and integrate all into Emacs. With the ability to extend, people can bend Emacs the way they want, much like Lisp.

Unlike other editors which encourage users to stay with the default as much as they can, Emacs encourages users to customize and extend Emacs as much as they can.

In the old days, when Emacs did not have a package manager and did not have many learning resources, it's really uneasy to customize Emacs, because to customize Emacs properly you have to read a decent chunk of the Emacs Lisp manual. Many of us, including me, do not have that luxury of time. The way I learned to customize Emacs was copying little code snippets that solve specific problems - when I encountered them - and paste everything in my ~/.emacs file. I also had to download Emacs packages manually and load it manually in ~/.emacs. I hope that this guide helps you to be at least as good as me in customizing Emacs without having to spend a long time in collecting configurations, or reading the whole Emacs Lisp manual. After you finish this chapter, you can dive in the Emacs Lisp manually if you want, and easier.

Just enough Emacs Lisp

In this section, you only need to read and understand. I will list the commonly used function used for customizing Emacs that we will use in later sections. It's important that you understand the core ideas. After you finish the sub-sections of this section, we will play with Emacs Lisp code for customizing Emacs, and it's really fun to see your Emacs "evolves" gradually.

It's worth to review again. To read most of Lisp code, it is easy. You only need to these rules:

  • Code that get executed is a pair of parentheses, with things in it: (...). The first element always gets evaluated; your Lisp environment (in our case, Emacs) determines which of the following 3 forms the symbol in the first slot is, then acts accordingly:
  • Function form: if the first element points to a function definition, then the following elements get evaluated from left to right and finally passed into the function as arguments.

    For example:

    (message "Hello word %d" (+ 10 10))
    

    message is a function that prints to echo area and *Message* buffer (can be opened with C-h e). Emacs detects that message is a function, then it evaluates the string "Hello world %d" and another nested form (+ 10 10) sequentially. When Emacs gets to (+ 10 10), it evaluates the form and return 20. Then the string "Hello world %d" and the number 20 are passed into message, and finally output "Hello world 20" in the echo area and *Message* buffer.

  • Special form: if the first element is one of predefined functions in Emacs Lisp that need special rules and/or syntax, then the remaining elements are evaluated depend on the rule of the predefined functions. Special form is just function form, but handle the remaining in its own way rather than using the default in function form. That's why we call it special.

    For example, if is a special form as we learned in previous part:

    (if condition
        true-case
      false-case)
    

    condition is a valid Lisp form; if it is evaluated to true (which is anything not NIL, or the empty list ()), then the true case - also a valid Lisp form - gets evaluated; otherwise the false case - also a valid Lisp form - gets evaluated.

    Another special form is and. After Emacs determines the first element is and special form, then it keeps evaluating the remaining elements from left to right until one of the element return false. If all elements get evaluated, and returns true.

  • Macro form: if the first element is created by the function defmacro (which you do not need to know at this stage), then Emacs do not evaluate any remaining elements, but passes them in as data. Macro is a way for programmers to create their own mini-language that do not follow the evaluation rules predefined in Emacs (function form and special form). If you read a form that is not a function form or any predefined special form, don't panic! It's a macro form. Programmers always provide documentations on how to use their mini-languages.

After all, those different forms are just under one category: function. Function form is a regular function; special form is a function with its own rule; macro form is a function that generate code.

  • Data: has two types:
  • Atom: primitives such as number, string, symbol and NIL.
  • Non-atom: if you put a just before a form, it becomes a list. Emacs treats these quoted forms as data.

    Emacs also has other data types like array, hash-table… but list is the most popular, used when performance is not needed.

In this section, I only explained the frequently used functions. In the later sections, there are more functions used. I can't explain them all. You should really work it out on your own gradually with C-h f and C-h v.

Function: (setq [ SYM VAL ]…)

Comment: A really fundamental function for customizing Emacs settings. An Emacs setting is really just a variable. Emacs has GUI for changing setting, but setq a variable is also equivalent.

Example:

(setq global-mark-ring-max 50000)

Built-in Documentation:

Set each SYM to the value of its VAL. The symbols SYM are variables; they are literal (not evaluated). The values VAL are expressions; they are evaluated. Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'. The second VAL is not computed until after the first SYM is set, and so on; each VAL can use the new value of variables set earlier in the `setq_'. The return value of the `setq_' form is the value of the last VAL.

Function: (load FILE &optional NOERROR NOMESSAGE NOSUFFIX MUST-SUFFIX)

Comment: This function allows you to load a file. FILE is the a filename that is looked up in the variable load-path. Do you notice &optional keyword? When you see this keyword, it means everything after &optional is, optional. The parameters NOERROR, NOMESSAGE, NOSUFFIX, MUST-SUFFIX are not required to be passed into the function if you don't need. However, if you want to pass an argument into the place of one a parameter, you must also pass arguments to all the parameters to the left of your chosen parameter. For example, if you want to pass an argument into NOSUFFIX, you are required to pass arguments into NOERROR, NOMESSAGE first. You are safe to ignore everything after your chosen parameter, and in our example, it's MUST-SUFFIX.

Example:

(load (substitute-in-file-name "$HOME/.emacs.d/module")) ;; first try to load module.elc; if not found, try to load module.el
(load (substitute-in-file-name "$HOME/.emacs.d/module.el")) ;; only load module.el
(load (substitute-in-file-name "$HOME/.emacs.d/module.elc")) ;; only load module.elc
(load "module") ; search for the file module.el or module.elc in variable load-path

Built-in Documentation:

Execute a file of Lisp code named FILE. First try FILE with `.elc' appended, then try with `.el', then try FILE unmodified (the exact suffixes in the exact order are determined by `load-suffixes'). Environment variable references in FILE are replaced with their values by calling `substitute-in-file-name'. This function searches the directories in `load-path'.

….(C-h f for more information)…

Function: (require FEATURE &optional FILENAME NOERROR)

Comment: If you install a package from M-x list-packages, to load that package, use (require 'installed-package).

Example: For example, you installed package volatile-highlights, to load it:

(require 'volatile-highlights)

Later in the guide, you will create your own custom modules that uses provide function to provide new feature to Emacs. To use a feature, the module must be activated with require.

Built-in Documentation:

If feature FEATURE is not loaded, load it from FILENAME. If FEATURE is not a member of the list `features', then the feature is not loaded; so load the file FILENAME. If FILENAME is omitted, the printname of FEATURE is used as the file name, and `load' will try to load this name appended with the suffix `.elc' or `.el', in that order. The name without appended suffix will not be used. See `get-load-suffixes' for the complete list of suffixes. If the optional third argument NOERROR is non-nil, then return nil if the file is not found instead of signaling an error. Normally the return value is FEATURE. The normal messages at start and end of loading FILENAME are suppressed.

Function: (provide FEATURE &optional SUBFEATURES)

Comment: You can use this function at the end of a file to turn the file into a loadable module that is only loaded when called with require.

Example:

Suppose that in a file setup-editing.el, you put this line at the bottom:

(provide 'setup-editing)

Then, even if you load it with load function, it won't be activated. To activate, you have to execute (require 'setup-editing).

Built-in Documentation:

Announce that FEATURE is a feature of the current Emacs. The optional argument SUBFEATURES should be a list of symbols listing particular subfeatures supported in this version of FEATURE.

Function: (add-to-list LIST-VAR ELEMENT &optional APPEND COMPARE-FN)

Comment: Add an element ELEMENT to a list named LIST-VAR.

Example:

(add-to-list 'load-path "~/.emacs.d/personal") ; add personal to load-path,
                                               ; so "load" function can search for files in it

Built-in Documentation:

Add ELEMENT to the value of LIST-VAR if it isn't there yet. The test for presence of ELEMENT is done with `equal', or with COMPARE-FN if that's non-nil. If ELEMENT is added, it is added at the beginning of the list, unless the optional argument APPEND is non-nil, in which case ELEMENT is added at the end.

The return value is the new value of LIST-VAR.

This is handy to add some elements to configuration variables, but please do not abuse it in Elisp code, where you are usually better off using `push' or `cl-pushnew'.

If you want to use `add-to-list' on a variable that is not defined until a certain package is loaded, you should put the call to `add-to-list' into a hook function that will be run only after loading the package. `eval-after-load' provides one way to do this. In some cases other hooks, such as major mode hooks, can do the job.

Function: (add-hook HOOK FUNCTION &optional APPEND LOCAL)

Comment: A hook is a Lisp variable which holds a list of functions, to be called on some well-defined occasion. (This is called running the hook. You can search for hook using C-h v and enter -hook suffix then TAB. Or you can find hooks in Customization Groups.

Example:

(add-hook 'prog-mode-hook 'linum-mode)

After you add the function linum-mode - which activates line number on the left margin of your Emacs - then every time you enter a prog-mode, which is the root all programming major modes derive from. A programming mode can be c-mode, asm-mode, emacs-lisp-mode, java-mode

Built-in Documentation:

Add to the value of HOOK the function FUNCTION. FUNCTION is not added if already present. FUNCTION is added (if necessary) at the beginning of the hook list unless the optional argument APPEND is non-nil, in which case FUNCTION is added at the end.

The optional fourth argument, LOCAL, if non-nil, says to modify the hook's buffer-local value rather than its global value. This makes the hook buffer-local, and it makes t a member of the buffer-local value. That acts as a flag to run the hook functions of the global value as well as in the local value.

HOOK should be a symbol, and FUNCTION may be any valid function. If HOOK is void, it is first set to nil. If HOOK's value is a single function, it is changed to a list of functions.

Function: (global-set-key KEY COMMAND)

Comment: This function binds a command to a key, as you can see in the function interface.

Example:

You can bind in one of the following ways:

(global-set-key (kbd "C-x C-b") 'ibuffer) ;; bind "C-x C-b" to ibuffer command
(global-set-key "\C-x\C-b" 'ibuffer)  ;; bind "C-x C-b to ibuffer command, but modifier 
                                      ;; keys must be escaped with the backslash
(global-set-key [?\C-x?\C-b] 'ibuffer) ;; use vector instead of a string

I recommend you to use (kbd ...) function because we can write key bindings using our familiar key notations without adding unnecessary characters. Vector is array in other languages. Vector was used for mapping function keys, such as [left], [right], [up], [down], [f1]...[f12]. But now, you can also map function keys in (kbd ...) function using angle brackets:

(global-set-key (kbd "<f3>") 'kmacro-start-macro-or-insert-counter)

Here are common function keys (remember to wrap them in a pair of angle bracket):

Key Description
left, up, right, down Cursor arrow keys
begin, end, home, next, prior Other cursor re-positioning keys
  prior means PageUp
  next means PageDOwn
select, print, execute, backtab Miscellaneous keys
insert, undo, redo, clearline backtab means S-TAB or C-iso-tab
insertline, deleteline, insertchar, deletechar  
f1, f2, ... F35 Numbered function keys on top of your keyboard
kp-add, kp-subtract, kp-multiply, kp-divide Keypad keys (to the right of the regular keyboard)
kp-backtab, kp-space, kp-tab, kp-enter , with names or punctuation.
kp-separator, kp-decimal, kp-equal  
   
kp-0, kp-1, ... kp-9 Keypad keys with digits.
   
kp-f1, kp-f2, kp-f3, kp-f4 Keypad PF keys.

Built-in Documentation:

Give KEY a global binding as COMMAND. COMMAND is the command definition to use; usually it is a symbol naming an interactively-callable function. KEY is a key sequence; noninteractively, it is a string or vector of characters or event types, and non-ASCII characters with codes above 127 (such as ISO Latin-1) can be included if you use a vector.

Note that if KEY has a local binding in the current buffer, that local binding will continue to shadow any global binding that you make with this function.

Function: (define-key KEYMAP KEY DEF)

Comment:

This function binds a definition DEF, usually a command, to a key sequence KEY. A definition can be other things that you can find in the built-in documentation.

A key sequence (key, for short) is a sequence of input events that have a meaning as a unit. Input events include characters, function keys and mouse buttons—all the inputs that you can send to the computer. A key sequence gets its meaning from its binding, which says what command it runs.

When a key sequence KEY is pressed, Emacs runs the associated function. A keymap KEYMAP stores a list of bindings between KEY and definition DEF. Major mode or minor mode uses keymap to provide its own key bindings. A keymap usually has -mode-map suffix, i.e. dired-mode-map; if you want to change or add a key binding in a major mode or minor mode, you use define-key function like this:

Example:

;; Dired uses "e", "f" or RET to open a file
;; you can reuse one of these keys for different purpose
;; for example, you can bind it to wdired-change-to-wdired-mode
;; wdired-change-to-wdired-mode allows you to edit your Dired buffer
;; like a normal text buffer, such as edit file/directory names,
;; permission bits.. and then commit the changes to disk.
;;
;; "e" is short for "edit"
;; After finish your editing, "C-c C-c" to commit, "C-c C-k" to abort
(define-key dired-mode-map (kbd "e") 'wdired-change-to-wdired-mode)

Built-in Documentation:

In KEYMAP, define key sequence KEY as DEF. KEYMAP is a keymap.

KEY is a string or a vector of symbols and characters, representing a sequence of keystrokes and events. Non-ASCII characters with codes above 127 (such as ISO Latin-1) can be represented by vectors. Two types of vector have special meanings: [remap COMMAND] remaps any key binding for COMMAND. [t] creates a default definition, which applies to any event with no other definition in KEYMAP.

DEF is anything that can be a key's definition: nil (means key is undefined in this keymap), a command (a Lisp function suitable for interactive calling), a string (treated as a keyboard macro), a keymap (to define a prefix key), a symbol (when the key is looked up, the symbol will stand for its function definition, which should at that time be one of the above, or another symbol whose function definition is used, etc.), a cons (STRING . DEFN), meaning that DEFN is the definition (DEFN should be a valid definition in its own right), or a cons (MAP . CHAR), meaning use definition of CHAR in keymap MAP, or an extended menu item definition. (See info node `(elisp)Extended Menu Items'.)

If KEYMAP is a sparse keymap with a binding for KEY, the existing binding is altered. If there is no binding for KEY, the new pair binding KEY to DEF is added at the front of KEYMAP.

Function: (defalias SYMBOL DEFINITION &optional DOCSTRING)

Comment: defalias allows you to rename a command. It is usually used to abbreviate command name.

Example: Put the following aliases in your init.el:

(defalias 'yes-or-no-p 'y-or-n-p) ; y or n is enough
(defalias 'list-buffers 'ibuffer) ; always use ibuffer

                                        ; elisp
(defalias 'eb 'eval-buffer)
(defalias 'er 'eval-region)
(defalias 'ed 'eval-defun)

                                        ; minor modes
(defalias 'wsm 'whitespace-mode)

Built-in Documentation:

Set SYMBOL's function definition to DEFINITION. Associates the function with the current load file, if any. The optional third argument DOCSTRING specifies the documentation string for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string determined by DEFINITION.

Internally, this normally uses `fset', but if SYMBOL has a `defalias-fset-function' property, the associated value is used instead.

The return value is undefined.

Function: (mapc FUNCTION SEQUENCE)

Comment: mapc calls the function FUNCTION on each element of the sequence SEQUENCE.

Example:

;; load every .el file inside ~/.emacs.d/custom/
(mapc 'load (directory-files "~/.emacs.d/custom" t ".*\.el"))

Built-in Documentation:

Apply FUNCTION to each element of SEQUENCE for side effects only. Unlike `mapcar', don't accumulate the results. Return SEQUENCE. SEQUENCE may be a list, a vector, a bool-vector, or a string.

Macro: (defun NAME ARGLIST &optional DOCSTRING DECL &rest BODY)

Comment: defun is a Lisp macro that allows you to define a function, like any other language. A function is a collection of Lisp forms to be executed. The return value is the last form.

Example:

  • Create a normal function (Not available in M-x):
(defun demo ()
  (message "Hello World" number string))
  • Create a command (Available in M-x):
(defun demo ()
  (interactive)
  (message "Hello World"))

interactive is a special form that turns a function into a command and allow a command to accept various types of prefix arguments, such as a number, a string, symbol, buffer names… You can C-h f and type interactive to find out more.

Built-in Documentation:

Define NAME as a function. The definition is (lambda ARGLIST [/DOCSTRING/] BODY…). See also the function `interactive'. DECL is a declaration, optional, of the form (declare DECLS…) where /DECLS is a list of elements of the form (PROP . VALUES). These are interpreted according to `defun-declarations-alist'. The return value is undefined.

Useful built-in key bindings for navigating pairs

  • C-M-f binds to forward-sexp, move forward over a balanced expression. Demo:

    forward-sexp.gif

  • C-M-b binds to backward-sexp, move backward over a balanced expression. Demo:

    backward-sexp.gif

  • C-M-k binds to kill-sexp, kill balanced expression forward. Demo:

    kill-sexp.gif

  • C-M-t binds to transpose-sexps, transpose expressions. Demo:

    transpose-sexp.gif

  • C-M-<SPC> or C-M-@ binds to mark-sexp, put mark after following expression. Demo:

    mark-sexp.gif

Let's supercharge Emacs

Throughout this section I will help you to extend Emacs with packages that improves general Emacs features, such as Info, Dired, buffer management… I will introduce you popular packages out there, but I cannot present you all. The purpose of this guide is to help you get really comfortable to Emacs package system, so you can extend Emacs with packages from other people easily to fit your need. Writing your own Emacs extension is a differnt story, and is beyond the scope of this guide.

I will introduce packages specialized for programming in later part: how to setup programming environment for popular languages (C/C++, Lisp, Python, Ruby…); each programming environment will have its own chapter. In this part of the mini manual series, I only introduce general packages for extending Emacs in various aspects. And you are going to need some of these packages to setup your specialized programming envrionment, so don't skip it.

Don't be intimidated if you see many packages down there. Adding packages and see it extends your Emacs is fun and addictive, like playing video games.

To remind you, Emacs always loads one of the three of the following files when it starts:

  • ~/.emacs
  • ~/.emacs.d/init
  • ~/.emacs.d/init.el

To apply a setting, move point to the end of a Lisp expression and C-x C-e, which runs eval-last-sexp. Or, you can evaluate the whole buffer with eval-buffer.

When you want to complete function names in Emacs Lisp: C-M-i, which runs completion-at-point. It will display a list of possible candidates available in Emacs. As a reminder, if you want to quickly complete some text, you can M-/, which runs dabbrev-expand.

If a package uses new functions, I will introduce the functions in its own sections just before we get to that package. I will only introduce the basic usage of the functions. If you want to understand more, C-h f and enter name of the function. All of the quoted function descriptions are taken from C-h f. If you forget what a function does and how to use it, C-h f to find out. Really, you should get used to getting help from Emacs itself.

How to use Emacs package manager

Emacs has a package manager to make the task of installing, update and removing easier, as well as inform users new packages created by the community. Emacs gets a list of packages from sources, called package archive. Package archive is the same as repository in Linux. Currently, there are 3 package archives in Emacs:

  • built-in: limited number of packages, and not always up to date.
  • Marmalade: more packages, but mostly outdated since people moved to MELPA.
  • MELPA: the most popular and most up to date package archive, with most number of packages.

Marmalade and MELPA are not activated by default; you have to add them manually. You only need to setup MELPA and that's enough to get all the packages described in later sections. Add this code snippet to your ~/.emacs.d/init.el:

(require 'package)
(add-to-list 'package-archives
  '("melpa" . "http://melpa.milkbox.net/packages/") t)

Then, evaluate those two expressions with C-x C-e or eval-buffer.

To open the package manager, M-x list-package. You will see a list of packages.

  • To navigate the package list down and up using n and p.
  • To view information of a package, press RET.
  • To mark a package for install, press i.
  • To mark a package for delete, press d.
  • To unmark a package, press u.
  • To execute the marked packages (either for install or delete), press x.
  • To refresh and update the latest package list, press r.
  • To update all packages, press U.
  • To filter to a group of packages, press f. Press TAB to display possible groups.
  • To display these key bindings, press h.

Exercise: Let's install a few packages in advance, so you won't have to install the packages later. Install these packages:

  • volatile-highlights
  • undo-tree
  • yasnippet

Customize Emacs

Using GUI

If you want to change a specific setting, you need to change a variable value. You wonder, there are so many variables to set. How do you know which to which? Luckily, you don't have to manually guess which variable to set. Emacs has a command for setting Emacs internally, with a nice organization of settings, rather than randomly set a variable that you randomly found. M-x customize to open a window for customizing Emacs:

customize.jpg

You will see various categories for customizing Emacs. These categories are called Customization Groups in Emacs. Let's try setting something in Emacs:

  • Go to Editing -> Editing Basics -> move point to "Global

Mark ring Max: ".

  • Change the value to 5000.
  • Move point on State button. Press RET.
  • A menu appears with the following choice:

0 = Set for current Sesssion This option is for trying out a new setting. If you close Emacs, the old setting is restored.

1 = Save for Future Sesssions This option saves the new value permanently, so the next time you start Emacs, it uses your saved setting. The new value is saved at ~/.emacs.d/init.el like this:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(global-mark-ring-max 5000))

2 = Undo Edits: Undo to the previous value of a particular setting, if you haven't set.

3 = Revert This Sesssion's Customization: This restores the value of the variable to the last saved value, and updates the text accordingly.

4 = Erase Customization: Reset to standard value and delete set value in ~/emacs.d/init.el.

7 = Add Comment: Sometimes you have something to say about your customization. Write it using this option.

: = Show Saved Lisp Expression: Show the actual variable representation. If you open the menu again, the option : = Show Saved Lisp Expression is changed to Show current value that switches back to the nicer representation.

Another way to change a setting is using C-h v, which runs describe-variable that list all the available variables in your Emacs and allow you to select one. You can also access the parent group of a group or a variable.

Aside from the general customize command, Emacs has many more customization command: customize-group, customize-face… That organize customization groups in different ways. However, in the scope of this guide, we only use customize for customize Emacs generally and customize-group to select a specific package for customizing, and also find out which parent group the package belongs to, after you finished installing from the package manager.

Using Emacs Lisp

The above approach uses GUI, which makes Emacs look familiar to normal users from other editors: using GUI to change the editors. However, it has disadvantages: Monolithic. Although the settings are nicely organized into groups, its underlying representation is not. After you set and save something in whatever group, Emacs always add your setting to the function custom-set-variables like this:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(global-mark-ring-max 5000 nil nil "test"))

As you can read it the comment, custom-set-variables is expected to be unique in your init file. If you have more, things go wrong. So, by design, you cannot split the settings into logical groups of your choice.

For that reason, setq is the preferred method. But, you can use the GUI with nice and logical grouping to guide you to the settings you want to change. The grouping is nice, and for consistency, we should organize our module structure based on the grouping in M-x customize:

  • setup-editing.el for Editing group.
  • setup-convenience.el for Convenience group.
  • setup-files.el for Files group.
  • setup-text.el for Text group.
  • setup-data.el for Data group.
  • setup-external.el for External group.
  • setup-communication.el for Communication group.
  • setup-programming.el for Programming group.
  • setup-applications.el for Application group.
  • setup-development.el for Development group.
  • setup-environment.el for Environment group.
  • setup-faces.el for Faces group.
  • setup-help.el for Help group.
  • setup-multimedia.el for Multimedia group.
  • setup-local.el for Local group.

Please note that even though you may see some packages are inside a group in customize GUI, I still put in another group since I feel such packages are more appropriate. So, if you see packages in my setup are in different groups, don't be surprise. But it's just my personal opinion. You can move it where you want.

Exercise:

  • Create a directory: ~/.emacs.d/custom/
  • Create the above setup-*.el files under it.
  • Load the files above using mapc:
(mapc 'load (directory-files "~/.emacs.d/custom" t ".*\.el"))

You already installed the package rebox2 in How to use Emacs package manager section. When you mark a region and M-q, you can create the above comment box. There are many styles, you can cycle by pressing M-q repeatedly.

Now, everything is prepared. We can really dive into customizing and extending Emacs with 3rd party packages and various code snippets that solve many little problems. In later sections, each is dedicated to a category. But, please note that I only provide the customizations that I found useful, not templates that you have to follow rigidly. You can consider my customizations as an example for your own customizations. You can use it either way:

  • Copy the sample configurations into your files and look back later or just don't care.
  • Really control the customization process and make the customizations actually yours, by reading the customization code and understand what it does.

init.el

Sample init.el:

;; Add and enable MELPA
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)

;; add your modules path
(add-to-list 'load-path "~/.emacs.d/custom/")

;; load your modules
(require 'setup-applications)
(require 'setup-communication)
(require 'setup-convenience)
(require 'setup-data)
(require 'setup-development)
(require 'setup-editing)
(require 'setup-environment)
(require 'setup-external)
(require 'setup-faces-and-ui)
(require 'setup-files)
(require 'setup-help)
(require 'setup-programming)
(require 'setup-text)
(require 'setup-local)

Package: workgroups2

Author:

Sergey Pashinin, sergey@pashinin.com

Based on the original workgroups, created by tlh, thunkout@gmail.com.

Homepage: Github

Features:

Workgroups is a session manager for Emacs.

  • It saves all your opened buffers, their location and sizes on disk to restore later.
  • You can create several workspaces.

You can also restore such buffers as: org-agenda, shell, magit-status, help.

Installation:

M-x list-packages and select workgroups2 package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: workgroups2               ;;
;;                                    ;;
;; GROUP: Convenience -> Workgroups   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'workgroups2)
;; Change some settings
(workgroups-mode 1)

Remember to put the code at the bottom of init.el, after everything is properly initialized.

Usage:

Most commands are bound to both <prefix> <key> and <prefix> C-<key>.

By default prefix is: "C-c z" (To change it - see settings below)

<prefix> <key> <prefix> c - create workgroup <prefix> A - rename workgroup <prefix> k - kill workgroup <prefix> v - switch to workgroup <prefix> C-s - save session <prefix> C-f - load session <prefix> 0..9 - switch to workgroup at index 0..9

Do you remember how to use registers to store window configurations? Registers are good, but it does not allow you to name window configurations. It would be trouble when the number of window configurations getting large. You will have to tediously remember which register stores which configuration.

With workgroups2, each window configuration is a workgroup, and you can create as many workgroups and named it with <prefix> c; later, you can switch back by <prefix> v. Because you can name your window configurations, you don't have the burden to remember which to which in registers. You can also save your window configurations to continue using them in later Emacs sessions.

setup-editing.el

Let's use setq to change Emacs the way we want. You should type in the snippet below and use the completion key bindings until you get used to it. Remember to include the line (provide 'setup-editing), otherwise Emacs won't be able to load your module.

(provide 'setup-editing)

;; GROUP: Editing -> Editing Basics
(setq global-mark-ring-max 5000         ; increase mark ring to contains 5000 entries
      mark-ring-max 5000                ; increase kill ring to contains 5000 entries
      mode-require-final-newline t      ; add a newline to end of file
      )

;; default to 4 visible spaces to display a tab
(setq-default tab-width 4)

(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)

(setq-default indent-tabs-mode nil)
(delete-selection-mode)
(global-set-key (kbd "RET") 'newline-and-indent)

;; GROUP: Editing -> Killing
(setq
 kill-ring-max 5000 ; increase kill-ring capacity
 kill-whole-line t  ; if NIL, kill whole line and move the next line up
 )

;; show important whitespace in diff-mode
(add-hook 'diff-mode-hook (lambda ()
                            (setq-local whitespace-style
                                        '(face
                                          tabs
                                          tab-mark
                                          spaces
                                          space-mark
                                          trailing
                                          indentation::space
                                          indentation::tab
                                          newline
                                          newline-mark))
                            (whitespace-mode 1)))

Customize built-in functions

Sometimes, we want to adjust or improve the behaviours of some commands in certain contexts. Consider this situation: C-a, which runs move-beginning-of-line, always move to the beginning of line. However, sometimes we don't always to move to the beginning of line, but move to the first non-whitespace character of that line.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customized functions                ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun prelude-move-beginning-of-line (arg)
  "Move point back to indentation of beginning of line.

Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.

If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there."
  (interactive "^p")
  (setq arg (or arg 1))

  ;; Move lines first
  (when (/= arg 1)
    (let ((line-move-visual nil))
      (forward-line (1- arg))))

  (let ((orig-point (point)))
    (back-to-indentation)
    (when (= orig-point (point))
      (move-beginning-of-line 1))))

(global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)

(defadvice kill-ring-save (before slick-copy activate compile)
  "When called interactively with no active region, copy a single
line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (message "Copied line")
     (list (line-beginning-position)
           (line-beginning-position 2)))))

(defadvice kill-region (before slick-cut activate compile)
  "When called interactively with no active region, kill a single
  line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (list (line-beginning-position)
           (line-beginning-position 2)))))

;; kill a line, including whitespace characters until next non-whiepsace character
;; of next line
(defadvice kill-line (before check-position activate)
  (if (member major-mode
              '(emacs-lisp-mode scheme-mode lisp-mode
                                c-mode c++-mode objc-mode
                                latex-mode plain-tex-mode))
      (if (and (eolp) (not (bolp)))
          (progn (forward-char 1)
                 (just-one-space 0)
                 (backward-char 1)))))

;; taken from prelude-editor.el
;; automatically indenting yanked text if in programming-modes
(defvar yank-indent-modes
  '(LaTeX-mode TeX-mode)
  "Modes in which to indent regions that are yanked (or yank-popped).
Only modes that don't derive from `prog-mode' should be listed here.")

(defvar yank-indent-blacklisted-modes
  '(python-mode slim-mode haml-mode)
  "Modes for which auto-indenting is suppressed.")

(defvar yank-advised-indent-threshold 1000
  "Threshold (# chars) over which indentation does not automatically occur.")

(defun yank-advised-indent-function (beg end)
  "Do indentation, as long as the region isn't too large."
  (if (<= (- end beg) yank-advised-indent-threshold)
      (indent-region beg end nil)))

(defadvice yank (after yank-indent activate)
  "If current mode is one of 'yank-indent-modes,
indent yanked text (with prefix arg don't indent)."
  (if (and (not (ad-get-arg 0))
           (not (member major-mode yank-indent-blacklisted-modes))
           (or (derived-mode-p 'prog-mode)
               (member major-mode yank-indent-modes)))
      (let ((transient-mark-mode nil))
        (yank-advised-indent-function (region-beginning) (region-end)))))

(defadvice yank-pop (after yank-pop-indent activate)
  "If current mode is one of `yank-indent-modes',
indent yanked text (with prefix arg don't indent)."
  (when (and (not (ad-get-arg 0))
             (not (member major-mode yank-indent-blacklisted-modes))
             (or (derived-mode-p 'prog-mode)
                 (member major-mode yank-indent-modes)))
    (let ((transient-mark-mode nil))
      (yank-advised-indent-function (region-beginning) (region-end)))))

;; prelude-core.el
(defun prelude-duplicate-current-line-or-region (arg)
  "Duplicates the current line or region ARG times.
If there's no region, the current line will be duplicated. However, if
there's a region, all lines that region covers will be duplicated."
  (interactive "p")
  (pcase-let* ((origin (point))
               (`(,beg . ,end) (prelude-get-positions-of-line-or-region))
               (region (buffer-substring-no-properties beg end)))
    (-dotimes arg
      (lambda (n)
        (goto-char end)
        (newline)
        (insert region)
        (setq end (point))))
    (goto-char (+ origin (* (length region) arg) arg))))

;; prelude-core.el
(defun indent-buffer ()
  "Indent the currently visited buffer."
  (interactive)
  (indent-region (point-min) (point-max)))

;; prelude-editing.el
(defcustom prelude-indent-sensitive-modes
  '(coffee-mode python-mode slim-mode haml-mode yaml-mode)
  "Modes for which auto-indenting is suppressed."
  :type 'list)

(defun indent-region-or-buffer ()
  "Indent a region if selected, otherwise the whole buffer."
  (interactive)
  (unless (member major-mode prelude-indent-sensitive-modes)
    (save-excursion
      (if (region-active-p)
          (progn
            (indent-region (region-beginning) (region-end))
            (message "Indented selected region."))
        (progn
          (indent-buffer)
          (message "Indented buffer.")))
      (whitespace-cleanup))))

(global-set-key (kbd "C-c i") 'indent-region-or-buffer)

;; add duplicate line function from Prelude
;; taken from prelude-core.el
(defun prelude-get-positions-of-line-or-region ()
  "Return positions (beg . end) of the current line
or region."
  (let (beg end)
    (if (and mark-active (> (point) (mark)))
        (exchange-point-and-mark))
    (setq beg (line-beginning-position))
    (if mark-active
        (exchange-point-and-mark))
    (setq end (line-end-position))
    (cons beg end)))

(defun kill-default-buffer ()
  "Kill the currently active buffer -- set to C-x k so that users are not asked which buffer they want to kill."
  (interactive)
  (let (kill-buffer-query-functions) (kill-buffer)))

(global-set-key (kbd "C-x k") 'kill-default-buffer)

;; smart openline
(defun prelude-smart-open-line (arg)
  "Insert an empty line after the current line.
Position the cursor at its beginning, according to the current mode.
With a prefix ARG open line above the current line."
  (interactive "P")
  (if arg
      (prelude-smart-open-line-above)
    (progn
      (move-end-of-line nil)
      (newline-and-indent))))

(defun prelude-smart-open-line-above ()
  "Insert an empty line above the current line.
Position the cursor at it's beginning, according to the current mode."
  (interactive)
  (move-beginning-of-line nil)
  (newline-and-indent)
  (forward-line -1)
  (indent-according-to-mode))

(global-set-key (kbd "C-o") 'prelude-smart-open-line)
(global-set-key (kbd "M-o") 'open-line)

The code above is taken from this article: Smarter Navigation to the Beginning of a Line.

(defadvice kill-ring-save (before slick-copy activate compile)
  "When called interactively with no active region, copy a single
line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (message "Copied line")
     (list (line-beginning-position)
           (line-beginning-position 2)))))

(defadvice kill-region (before slick-cut activate compile)
  "When called interactively with no active region, kill a single
  line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (list (line-beginning-position)
           (line-beginning-position 2)))))

;; kill a line, including whitespace characters until next non-whiepsace character
;; of next line
(defadvice kill-line (before check-position activate)
  (if (member major-mode
              '(emacs-lisp-mode scheme-mode lisp-mode
                                c-mode c++-mode objc-mode
                                latex-mode plain-tex-mode))
      (if (and (eolp) (not (bolp)))
          (progn (forward-char 1)
                 (just-one-space 0)
                 (backward-char 1)))))

Package: duplicate-thing

Author: ongaeshi, ongaeshi0621@gmail.com

Homepage: Github

Features:

Easy duplicate line or region, with comment out.

  • Duplicate current line.
  • Duplicate a selection when selection is active.
  • Only C-u, replicate, comment out the range.
  • Numerical prefix is specified as 'C-u 5': do multiple times repeatedly.

Installation:

(require 'duplicate-thing)
(global-set-key (kbd "M-c") 'duplicate-thing)

Usage: If point is on a line, the command duplicates the current line. If region is active, duplicates region instead.

Package: volatile-highlights

Author: Keitalo Miyazaki, Keitaro.Miyazaki@gmail.com

Homepage: Emacswiki

Features:

VolatileHighlights highlights changes to the buffer caused by commands such as ‘undo’, ‘yank’/’yank-pop’, etc. The highlight disappears at the next command. The highlighting gives useful visual feedback for what your operation actually changed in the buffer.

Installation:

M-x list-packages and select volatile-highlights package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: volatile-highlights          ;;
;;                                       ;;
;; GROUP: Editing -> Volatile Highlights ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'volatile-highlights)
(volatile-highlights-mode t)

Usage:

When you yank (paste) something, the yanked (pasted) region will be highlighted.

Package: smartparens

Author: Matus Goljer, matus.goljer@gmail.com

Homepage: Github

Features:

Smartparens is minor mode for Emacs that deals with parens pairs and tries to be smart about it. It started as a unification effort to combine functionality of several existing packages in a single, compatible and extensible way to deal with parentheses, delimiters, tags and the like. Some of these packages include autopair, textmate, wrap-region, electric-pair-mode, paredit and others. With the basic features found in other packages it also brings many improvements as well as completely new features. Here's a highlight of some features, for a complete list and detailed documentation look in the manual.

For the complete documentation visit the documentation wiki.

Installation:

M-x list-packages and select smartparens package, then install it. After finish installing, add this code snippet to activate the package:

;; Package: smartparens
(require 'smartparens-config)
(setq sp-base-key-bindings 'paredit)
(setq sp-autoskip-closing-pair 'always)
(setq sp-hybrid-kill-entire-symbol nil)
(sp-use-paredit-bindings)

Usage:

If smartparens sees a opening/closing of pair, either the default supported ones or customized by users, it will complete the pair. You can even highlight a block of text (region) and enter a pair character, smartparens will wraps the region around the pair. smartparens can also highlight pairs, even pairs with escape characters.

Package: clean-aindent-mode

Author: Peter Marinov

Homepage: Github

Features:

When you press RET to create a newline and got indented by eletric-indent-mode, you have appropriate whitespace for indenting. But, if you leave the line blank and move to the next line, the whitespace becomes useless. This package helps clean up unused whitespace.

View this Emacswiki page for more details.

Installation:

M-x list-packages and select clean-aindent-mode package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: clean-aindent-mode               ;;
;;                                           ;;
;; GROUP: Editing -> Indent -> Clean Aindent ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'clean-aindent-mode)
(add-hook 'prog-mode-hook 'clean-aindent-mode)

Usage:

Automatically cleanup useless whitespaced on moving up/down.

Package: undo-tree

Author: Toby Cubitt, toby-undo-tree@dr-qubit.org

Homepage: www.dr-qubit.org

Features:

undo-tree allows you to visual the whole history of your editing in a tree. It also provides regular undo/redo behaviours in other editors. undo-tree can even provide a diff between two different states. Highly recommended.

undo-tree.jpg

Installation:

M-x list-packages and select undo-tree package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: undo-tree                  ;;
;;                                     ;;
;; GROUP: Editing -> Undo -> Undo Tree ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'undo-tree)
(global-undo-tree-mode)

Usage:

From now on, your undo (C-/) behaves just like normal editor. To redo, C-_. To open the undo tree, C-x u.

Package: yasnippet

Author: João Távora

Homepage: Github

Features:

YASnippet is a template system for Emacs. It allows you to type an abbreviation and automatically expand it into function templates. Bundled language templates include: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more. The snippet syntax is inspired from TextMate's syntax, you can even import most TextMate templates to YASnippet.

Installation:

M-x list-packages and select yasnippet package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: yasnippet                 ;;
;;                                    ;;
;; GROUP: Editing -> Yasnippet        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'yasnippet)
(yas-global-mode 1)

Usage:

In major modes where yasnippet has snippets available, typing a certain keyword and TAB insert a predefined snippet. For example, in a C buffer, if you type for and TAB, it expands to:

for (i = 0; i < N; i++) {
    ...point will be here....
}

You can view supported snippets here.

setup-convenience.el

Remember to include the line (provide 'setup-convenience), otherwise Emacs won't be able to load your module. Here is my sample customization:

(provide 'setup-convenience)

;; GROUP: Convenience -> Revert

;; update any change made on file to the current buffer
(global-auto-revert-mode)

;; GROUP: Convenience -> Hippe Expand
;; hippie-expand is a better version of dabbrev-expand.
;; While dabbrev-expand searches for words you already types, in current;; buffers and other buffers, hippie-expand includes more sources,
;; such as filenames, klll ring...
(global-set-key (kbd "M-/") 'hippie-expand) ;; replace dabbrev-expand
(setq
 hippie-expand-try-functions-list
 '(try-expand-dabbrev ;; Try to expand word "dynamically", searching the current buffer.
   try-expand-dabbrev-all-buffers ;; Try to expand word "dynamically", searching all other buffers.
   try-expand-dabbrev-from-kill ;; Try to expand word "dynamically", searching the kill ring.
   try-complete-file-name-partially ;; Try to complete text as a file name, as many characters as unique.
   try-complete-file-name ;; Try to complete text as a file name.
   try-expand-all-abbrevs ;; Try to expand word before point according to all abbrev tables.
   try-expand-list ;; Try to complete the current line to an entire line in the buffer.
   try-expand-line ;; Try to complete the current line to an entire line in the buffer.
   try-complete-lisp-symbol-partially ;; Try to complete as an Emacs Lisp symbol, as many characters as unique.
   try-complete-lisp-symbol) ;; Try to complete word as an Emacs Lisp symbol.
 )

;; GROUP: Convenience -> HL Line
(global-hl-line-mode)

;; GROUP: Convenience -> Ibuffer
(setq ibuffer-use-other-window t) ;; always display ibuffer in another window

;; GROUP: Convenience -> Linum
(add-hook 'prog-mode-hook 'linum-mode) ;; enable linum only in programming modes

;; GROUP: Convenience -> Whitespace

;; whenever you create useless whitespace, the whitespace is highlighted
(add-hook 'prog-mode-hook (lambda () (interactive) (setq show-trailing-whitespace 1)))

;; activate whitespace-mode to view all whitespace characters
(global-set-key (kbd "C-c w") 'whitespace-mode)

;; GROUP: Convenience -> Windmove

;; easier window navigation
(windmove-default-keybindings)

Package: company

Author:

  • Nikolaj Schumacher (original author)
  • Dmitry Gutov (current maintainer), dgutov@yandex.ru

Homepage: http://company-mode.github.io/

Features:

Company is a text completion framework for Emacs. The name stands for "complete anything". It uses pluggable back-ends and front-ends to retrieve and display completion candidates.

It comes with several back-ends such as Elisp, Clang, Semantic, Eclim, Ropemacs, Ispell, CMake, BBDB, Yasnippet, dabbrev, etags, gtags, files, keywords and a few others.

The CAPF back-end provides a bridge to the standard completion-at-point-functions facility, and thus works with any major mode that defines a proper completion function.

Installation:

M-x list-packages and select company package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: company              ;;
;;                               ;;
;; GROUP: Convenience -> Company ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'after-init-hook 'global-company-mode)

Usage:

Completion will start automatically after you type a few letters. Use M-n and M-p to select, <return> to complete or <tab> to complete the common part. Search through the completions with C-s, C-r and C-o. Press M-(digit) to quickly complete with one of the first 10 candidates.

Package: expand-region

Author: Magnar Sveen

Homepage: Github

Features: expand-region allows you to select text objects incrementally.

Installation:

M-x list-packages and select expand-region package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: expand-region                       ;;
;;                                              ;;
;; GROUP: Convenience -> Abbreviation -> Expand ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'expand-region)
(global-set-key (kbd "M-m") 'er/expand-region)

I bind er/expand-regin to M-m, because the functionality is included from the amended beginning-of-line we did above.

Usage:

M-m to continue expand outward.

Package: ibuffer-vc

Author: Steve Purcell

Homepage: Github

Features:

  • Group your buffers by their parent vc root directory
  • See the VC status of the associated files
  • Sort buffers by their VC status

ibuffer-vc.png

Installation:

M-x list-packages and select ibuffer-vc package, then install it. After finish installing, add this code snippet to activate the package:

(add-hook 'ibuffer-hook
          (lambda ()
            (ibuffer-vc-set-filter-groups-by-vc-root)
            (unless (eq ibuffer-sorting-mode 'alphabetic)
              (ibuffer-do-sort-by-alphabetic))))

(setq ibuffer-formats
      '((mark modified read-only vc-status-mini " "
              (name 18 18 :left :elide)
              " "
              (size 9 -1 :right)
              " "
              (mode 16 16 :left :elide)
              " "
              (vc-status 16 16 :left)
              " "
              filename-and-process)))

Usage:

When you use ibuffer, it will automatically group buffers by version control system.

Package: projectile

Author: Bozhidar Batsov, bozhidar@batsov.com

Homepage: Github

Features:

Projectile is a project interaction library for Emacs. Its goal is to provide a nice set of features operating on a project level without introducing external dependencies(when feasible). For instance - finding project files has a portable implementation written in pure Emacs Lisp without the use of GNU find (but for performance sake an indexing mechanism backed by external commands exists as well).

Projectile tries to be practical - portability is great, but if some external tools could speed up some task substantially and the tools are available, Projectile will leverage them.

This library provides easy project management and navigation. The concept of a project is pretty basic - just a folder containing special file. Currently git, mercurial, darcs and bazaar repos are considered projects by default. So are lein, maven, sbt, rebar and bundler projects. If you want to mark a folder manually as a project just create an empty .projectile file in it. Some of Projectile's features:

  • jump to a file in project
  • jump to a directory in project
  • jump to a file in a directory
  • jump to a project buffer
  • jump to a test in project
  • toggle between code and its test
  • jump to recently visited files in the project
  • switch between projects you have worked on
  • kill all project buffers
  • replace in project
  • multi-occur in project buffers
  • grep in project
  • regenerate project etags or gtags (requires gtags).
  • visit project in dired
  • run make in a project with a single key chord

Here's a glimpse of Projectile in action:

projectile.png

Installation:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGES: projectile             ;;
;;                                  ;;
;; GROUP: Convenience -> Projectile ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(projectile-global-mode)

Usage:

Please refer to the usage on the homepage.

Package in a league of its own: helm

Helm is an awesome package. Please refer to the whole guide. You should give Helm its own file: setup-helm.el.

Alternative to Helm: ido + ido-ubiquitous + flx-ido + smex

If you want to use Ido, at replace Helm configuration with this sample configuration that you can place in setup-environment.el:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Development -> Extensions -> Ido ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'ido)

(setq ido-enable-prefix nil
      ido-enable-flex-matching t
      ido-create-new-buffer 'always
      ido-use-filename-at-point 'guess
      ido-max-prospects 10
      ido-default-file-method 'selected-window
      ido-auto-merge-work-directories-length -1)

(ido-mode +1)

Package: ido-ubiquitous

Author: Ryan C. Thompson, rct+github@thompsonclan.org

Homepage: Github

Features:

Gimme some ido… everywhere!

Does what you were really hoping for when you did (setq ido-everywhere t). Replaces stock emacs completion with ido completion wherever it is possible to do so without breaking things.

Note that ido-ubiquitous is not enabled for org mode or magit mode, because those modes have their own support for ido.

Installation:

M-x list-packages and select ido-ubiquitous package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: ido-ubiquitous                                   ;;
;;                                                           ;;
;; GROUP: Development -> Extensions -> Ido -> Ido Ubiquitous ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ido-ubiquitous-mode +1)

Usage:

Once you activated Ido, it is available where you expect to select and narrow down candidates.

Package: flx-ido

Author: Le Wang

Homepage: Github

Features: M-x list-packages and select flx-ido package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: flx-ido                                          ;;
;;                                                           ;;
;; GROUP: Development -> Extensions -> Ido                   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; smarter fuzzy matching for ido
(flx-ido-mode +1)
;; disable ido faces to see flx highlights
(setq ido-use-faces nil)

Usage:

flx-ido provides fuzzy completion to select completion candidates. For example, if you want to select a file src/foo/bar.txt, you only need to type in Ido prompt "sfb", short for (s)rc/(f)oo/(b)ar.

Package: smex

Author: Cornelius Mika, cornelius.mika@gmail.com

Homepage: Github

Features:

Smex is a M-x enhancement for Emacs. Built on top of Ido, it provides a convenient interface to your recently and most frequently used commands. And to all the other commands, too.

smex.png

Installation:

M-x list-packages and select flx-ido package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: smex                                             ;;
;;                                                           ;;
;; GROUP: Convenience -> Extensions -> Smex                  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)

Usage:

smex is an improved M-x command. After you setup, M-x to run smex and M-X to select only commands in the current major mode.

setup-files.el

Remember to include the line (provide 'setup-files), otherwise Emacs won't be able to load your module. My sample customization:

(provide 'setup-files)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; group: Files                      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq large-file-warning-threshold 100000000) ;; size in bytes

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Files -> Back up            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar backup-directory "~/.backups")
(if (not (file-exists-p backup-directory))
    (make-directory backup-directory t))
(setq
 make-backup-files t        ; backup a file the first time it is saved
 backup-directory-alist `((".*" . ,backup-directory)) ; save backup files in ~/.backups
 backup-by-copying t     ; copy the current file into backup directory
 version-control t   ; version numbers for backup files
 delete-old-versions t   ; delete unnecessary versions
 kept-old-versions 6     ; oldest versions to keep when a new numbered backup is made (default: 2)
 kept-new-versions 9 ; newest versions to keep when a new numbered backup is made (default: 2)
 auto-save-default t ; auto-save every buffer that visits a file
 auto-save-timeout 20 ; number of seconds idle time before auto-save (default: 30)
 auto-save-interval 200 ; number of keystrokes between auto-saves (default: 300)
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Files -> Dired              ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq
 dired-dwim-target t            ; if another Dired buffer is visible in another window, use that directory as target for Rename/Copy
 dired-recursive-copies 'always         ; "always" means no asking
 dired-recursive-deletes 'top           ; "top" means ask once for top level directory
 dired-listing-switches "-lha"          ; human-readable listing
 )

;; automatically refresh dired buffer on changes
(add-hook 'dired-mode-hook 'auto-revert-mode)

;; if it is not Windows, use the following listing switches
(when (not (eq system-type 'windows-nt))
  (setq dired-listing-switches "-lha --group-directories-first"))

;;; KEY BINDINGS.
;; (define-key ctl-x-map "\C-j" 'dired-jump)
;; (define-key ctl-x-4-map "\C-j" 'dired-jump-other-window))
;; (define-key dired-mode-map "\C-x\M-o" 'dired-omit-mode)
;; (define-key dired-mode-map "*O" 'dired-mark-omitted)
;; (define-key dired-mode-map "\M-(" 'dired-mark-sexp)
;; (define-key dired-mode-map "*(" 'dired-mark-sexp)
;; (define-key dired-mode-map "*." 'dired-mark-extension)
;; (define-key dired-mode-map "\M-!" 'dired-smart-shell-command)
;; (define-key dired-mode-map "\M-G" 'dired-goto-subdir)
;; (define-key dired-mode-map "F" 'dired-do-find-marked-files)
;; (define-key dired-mode-map "Y"  'dired-do-relsymlink)
;; (define-key dired-mode-map "%Y" 'dired-do-relsymlink-regexp)
;; (define-key dired-mode-map "V" 'dired-do-run-mail)
(require 'dired-x) ; provide extra commands for Dired

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Files -> Dired -> Wdired    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; wdired allows you to edit a Dired buffer and write changes to disk
;; - Switch to Wdired by C-x C-q
;; - Edit the Dired buffer, i.e. change filenames
;; - Commit by C-c C-c, abort by C-c C-k
(require 'wdired)
(setq
 wdired-allow-to-change-permissions t   ; allow to edit permission bits
 wdired-allow-to-redirect-links t       ; allow to edit symlinks
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Files -> Recentf            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(recentf-mode)
(setq
 recentf-max-menu-items 30
 recentf-max-saved-items 5000
 )

Package: dired+

Author: Drew Adams, drew.adams@oracle.com

Homepage: Emacswiki

Features: Dired+ (library dired+.el), which extends functionalities provided by standard GNU Emacs libraries dired.el, dired-aux.el, and dired-x.el. The standard functions are all available, plus many more.

dired-plus.jpg

Installation:

M-x list-packages and select dired+ package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: dired+                     ;;
;;                                     ;;
;; GROUP: Files -> Dired -> Dired Plus ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'dired+)

Usage:

Please refer to Emacswiki usage. Note that Dired+ has A LOT of features, but you don't have to learn to use all of them at once. Even the extra faces are useful enough.

Package: recentf-ext

Features:

Extension of `recentf' package.

  • `dired' buffers can be handled.
  • Switching to file buffer considers it as most recent file.

Installation:

M-x list-packages and select recentf-ext package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: recentf-ext    ;;
;;                         ;;
;; GROUP: Files -> Recentf ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'recentf-ext)

Usage:

When you visit a directory, that directory is saved by recentf as well.

Package: ztree

Author: Alexey Veretennikov, alexey.veretennikov@gmail.com

Homepage: Github

Features:

Ztree is a project dedicated to implementation of several text-tree applications inside Emacs. It consists of 2 sub-projects: ztree-diff and ztree-dir(the basis of ztree-diff).

  • ztree-diff: Perform diff on two directories. Really handy when you want to create a big patch between two directories.

ztree-diff.png

  • ztree-dir: a simple tree explorer.

ztree-dir.png

Installation:

M-x list-packages and select ztree package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: ztree  ;;
;;                 ;;
;; GROUP: No group ;;
;;;;;;;;;;;;;;;;;;;;;
;; since ztree works with files and directories, let's consider it in
;; group Files
(require 'ztree-diff)
(require 'ztree-dir)

Usage:

M-x ztree-diff, then select the left and right directories to compare.

M-x ztree-dir to explorer filesystem:

  • Open/close directories with double-click, RET or Space keys.
  • To jump to the parent directory, hit the Backspace key.
  • To toggle open/closed state of the subtree of the current directory, hit the x key.

Package: vlf

Author: Andrey Kotlarski, m00naticus@gmail.com

Homepage: Github

Features:

Emacs minor mode that allows viewing, editing, searching and comparing large files in batches. Batch size can be adjusted on the fly and bounds the memory that is to be used for operations on the file. This way multiple large files (like terabytes or whatever) can be instantly and simultaneously accessed without swapping and degraded performance.

This is development version of the GNU ELPA VLF package. Here’s what it offers in a nutshell:

  • regular expression search on whole file (in constant memory determined by current batch size)
  • chunk editing (if size has changed, saving is done in constant memory determined by current batch size)
  • Occur like indexing
  • options to jump to beginning, end or arbitrary file chunk
  • ability to jump/insert given number of batches at once
  • newly added content is acknowledged if file has changed size meanwhile
  • automatic scrolling of batches
  • as a minor mode, font locking and functionality of the respective major mode is also present
  • by batch Ediff comparison
  • can be added as option to automatically open large files
  • smooth integration with hexl-mode
  • works with TRAMP so accessing network files is fine

GNU Emacs 23 and 24 are supported.

Installation:

M-x list-packages and select ** package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: vlf        ;;
;;                     ;;
;; GROUP: Files -> Vlf ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'vlf-integrate)
(setq vlf-application 'dont-ask) ;; automatically use vlf on large file,
                                 ;; when the file exceed large-file-warning-threshold

Usage:

Please refer to Detail Usage section.

setup-text.el

I only use default configuration for "Text" group. You can customize it if you want or leave this file blank, so you can add customizations when needed. This group is useful if you edit text frequently and need bibliography, or you want to write Latex.

(provide 'setup-text)

setup-data.el

Remember to include the line (provide 'setup-data), otherwise Emacs won't be able to load your module. Sample configuration:

(provide 'setup-data)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Data -> Saveplace ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; saveplace remembers your location in a file when saving files
(require 'saveplace)
(setq-default save-place t)
;; use (toggle-save-place-globally 1) in Emacs above 24.4

setup-external.el

Remember to include the line (provide 'setup-external), otherwise Emacs won't be able to load your module. Sample configuration:

(provide 'setup-external)

;; GROUP: Processes -> Flyspell
(if (executable-find "aspell")
    (progn
      (setq ispell-program-name "aspell")
      (setq ispell-extra-args '("--sug-mode=ultra")))
  (setq ispell-program-name "ispell"))

(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'org-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Processes -> Gud            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq gud-chdir-before-run nil)

;; term-mode, used in M-x term
(defun my-term-setup ()
  (interactive)
  (define-key term-raw-map (kbd "C-y") 'term-send-raw)
  (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  (define-key term-raw-map (kbd "C-s") 'term-send-raw)
  (define-key term-raw-map (kbd "C-r") 'term-send-raw)
  (define-key term-raw-map (kbd "M-w") 'kill-ring-save)
  (define-key term-raw-map (kbd "M-y") 'helm-show-kill-ring)
  (define-key term-raw-map (kbd "M-d") (lambda () (interactive) (term-send-raw-string "\ed")))
  (define-key term-raw-map (kbd "<C-backspace>") (lambda () (interactive) (term-send-raw-string "\e\C-?")))
  (define-key term-raw-map (kbd "M-p") (lambda () (interactive) (term-send-raw-string "\ep")))
  (define-key term-raw-map (kbd "M-n") (lambda () (interactive) (term-send-raw-string "\en")))
  (define-key term-raw-map (kbd "M-,") 'term-send-input)
  (define-key term-raw-map (kbd "C-c y") 'term-paste)
  (define-key term-raw-map (kbd "C-S-y") 'term-paste)
  (define-key term-raw-map (kbd "C-h") nil) ; unbind C-h
  (define-key term-raw-map (kbd "M-x") nil) ; unbind M-x
  (define-key term-raw-map (kbd "C-c C-b") 'helm-mini)
  (define-key term-raw-map (kbd "C-1") 'zygospore-toggle-delete-other-windows)
  (define-key term-raw-map (kbd "C-2") 'split-window-below)
  (define-key term-raw-map (kbd "C-3") 'split-window-right)
  (define-key term-mode-map (kbd "C-0") 'delete-window))
(add-hook 'term-mode-hook 'my-term-setup t)
(setq term-buffer-maximum-size 0)

(require 'term)

;; taken from here: http://www.enigmacurry.com/2008/12/26/emacs-ansi-term-tricks/
(defun visit-ansi-term ()
  "If the current buffer is:
     1) a running ansi-term named *ansi-term*, rename it.
     2) a stopped ansi-term, kill it and create a new one.
     3) a non ansi-term, go to an already running ansi-term
        or start a new one while killing a defunt one"
  (interactive)
  (let ((is-term (string= "term-mode" major-mode))
        (is-running (term-check-proc (buffer-name)))
        (term-cmd "/bin/zsh")
        (anon-term (get-buffer "*ansi-term*")))
    (if is-term
        (if is-running
            (if (string= "*ansi-term*" (buffer-name))
                ;; (call-interactively 'rename-buffer)
                (ansi-term term-cmd)
              (if anon-term
                  (switch-to-buffer "*ansi-term*")
                (ansi-term term-cmd)))
          (kill-buffer (buffer-name))
          (ansi-term term-cmd))
      (if anon-term
          (if (term-check-proc "*ansi-term*")
              (switch-to-buffer "*ansi-term*")
            (kill-buffer "*ansi-term*")
            (ansi-term term-cmd))
        (ansi-term term-cmd)))))

(global-set-key (kbd "<f2>") 'visit-ansi-term)

;; PACKAGE: shell-pop
;; GROUP: Processes -> Shell -> Shell Pop
(require 'shell-pop)
(global-set-key (kbd "C-c t") 'shell-pop)

setup-communication.el

This group allows to customize communications, networking, and remote access to files. For example, ftp, ldap, dig, whois, netstat… I only enable goto-address-mode to enable URL highlighting and able to click on it in an buffer. Very useful. Sample configuration:

(provide 'setup-communication)

;; go-to-address-mode
(add-hook 'prog-mode-hook 'goto-address-mode)
(add-hook 'text-mode-hook 'goto-address-mode)

setup-programming.el

Remember to include the line (provide 'setup-programming), otherwise Emacs won't be able to load your module. Sample configuration:

(provide 'setup-programming)
;; GROUP: Programming -> Languages -> C

;; Available C style:
;; “gnu”: The default style for GNU projects
;; “k&r”: What Kernighan and Ritchie, the authors of C used in their book
;; “bsd”: What BSD developers use, aka “Allman style” after Eric Allman.
;; “whitesmith”: Popularized by the examples that came with Whitesmiths C, an early commercial C compiler.
;; “stroustrup”: What Stroustrup, the author of C++ used in his book
;; “ellemtel”: Popular C++ coding standards as defined by “Programming in C++, Rules and Recommendations,” Erik Nyquist and Mats Henricson, Ellemtel
;; “linux”: What the Linux developers use for kernel development
;; “python”: What Python developers use for extension modules
;; “java”: The default style for java-mode (see below)
;; “user”: When you want to define your own style
(setq c-default-style "linux" ; set style to "linux"
      c-basic-offset 4)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Programming -> Tools -> Gdb ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq gdb-many-windows t        ; use gdb-many-windows by default
      gdb-show-main t)          ; Non-nil means display source file containing the main routine at startup

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Programming -> Tools -> Compilation ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Compilation from Emacs
(defun prelude-colorize-compilation-buffer ()
  "Colorize a compilation mode buffer."
  (interactive)
  ;; we don't want to mess with child modes such as grep-mode, ack, ag, etc
  (when (eq major-mode 'compilation-mode)
    (let ((inhibit-read-only t))
      (ansi-color-apply-on-region (point-min) (point-max)))))

;; setup compilation-mode used by `compile' command
(require 'compile)
(setq compilation-ask-about-save nil          ; Just save before compiling
      compilation-always-kill t               ; Just kill old compile processes before starting the new one
      compilation-scroll-output 'first-error) ; Automatically scroll to first
(global-set-key (kbd "<f5>") 'compile)

;; GROUP: Programming -> Tools -> Makefile
;; takenn from prelude-c.el:48: https://github.com/bbatsov/prelude/blob/master/modules/prelude-c.el
(defun prelude-makefile-mode-defaults ()
  (whitespace-toggle-options '(tabs))
  (setq indent-tabs-mode t))

(setq prelude-makefile-mode-hook 'prelude-makefile-mode-defaults)

(add-hook 'makefile-mode-hook (lambda ()
                                (run-hooks 'prelude-makefile-mode-hook)))

;; GROUP: Programming -> Tools -> Ediff
(setq ediff-diff-options "-w"
      ediff-split-window-function 'split-window-horizontally
      ediff-window-setup-function 'ediff-setup-windows-plain)

Package: diff-hl

Author: Dmitry Gutov, dgutov@yandex.ru

Homepage: Github

Features:

diff-hl-mode highlights uncommitted changes on the left side of the window, allows you to jump between and revert them selectively.

diff-hl-buffer.png

For the usage instructions and the list of commands, see the Commentary section inside the file.

Tested with Git, Mercurial, Bazaar and SVN. May work with other VC backends, too.

The package also contains auxiliary modes:

  • diff-hl-dired-mode provides similar functionality in Dired.

    diff-hl-dired.png

  • diff-hl-margin-mode changes the highlighting function to use the margin instead of the fringe.

    diff-hl-margin.png

  • diff-hl-amend-mode shifts the reference revision back by one.

Installation:

M-x list-packages and select diff-hl package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: diff-hl                             ;;
;;                                              ;;
;; GROUP: Programming -> Tools -> Vc -> Diff Hl ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-diff-hl-mode)
(add-hook 'dired-mode-hook 'diff-hl-dired-mode)

Usage:

To see diff-hl in action, open a buffer under a version control and type something and save. You will see highlighted changes in the fringe on the left.

It is also similar with diff-hl-dired-mode.

Package: magit

Author:

Original Author: Marius Vollmer marius.vollmer@gmail.com

Maintainer: Jonas Bernoulli, jonas@bernoul.li

Former-Maintainers:

  • Nicolas Dudebout, nicolas.dudebout@gatech.edu
  • Peter J. Weisberg, pj@irregularexpressions.net
  • Phil Jackson, phil@shellarchive.co.uk
  • Rémi Vanicat, vanicat@debian.org
  • Yann Hodique, yann.hodique@gmail.com

Homepage: http://magit.github.io

Features: Magit is an interface to the version control system Git, implemented as an Emacs extension.

Unlike Emacs' native Version Control package which strives to provide a unified interface to various version control systems, Magit only supports Git and can therefore better take advantage of its native features.

Magit supports GNU Emacs 23.2 or later; 24.1 or later is recommended. Magit supports Git 1.7.2.5 or later; 1.8.2 or later is recommended. The minimal versions are those available in Debian oldstable.

Installation:

M-x list-packages and select magit package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: magit                       ;;
;;                                      ;;
;; GROUP: Programming -> Tools -> Magit ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'magit)
(set-default 'magit-stage-all-confirm nil)
(add-hook 'magit-mode-hook 'magit-load-config-extensions)

;; full screen magit-status
(defadvice magit-status (around magit-fullscreen activate)
  (window-configuration-to-register :magit-fullscreen)
  ad-do-it
  (delete-other-windows))

(global-unset-key (kbd "C-x g"))
(global-set-key (kbd "C-x g h") 'magit-log)
(global-set-key (kbd "C-x g f") 'magit-file-log)
(global-set-key (kbd "C-x g b") 'magit-blame-mode)
(global-set-key (kbd "C-x g m") 'magit-branch-manager)
(global-set-key (kbd "C-x g c") 'magit-branch)
(global-set-key (kbd "C-x g s") 'magit-status)
(global-set-key (kbd "C-x g r") 'magit-reflog)
(global-set-key (kbd "C-x g t") 'magit-tag)

Usage:

Getting started with Magit is really easy:

  • M-x magit-status to see git status, and in the status buffer:
  • s to stage files
  • c c to commit, type in your commit message then C-c C-c to save the message and commit, C-c C-k to abort current commit message and go back magit-status.
  • b b to switch to a branch.

Other handy keys:

  • P P to do a git push
  • F F to do a git pull
  • try to press TAB on entries.

If you want to view the raw git commands, i.e. you want to know how git push is doing, press $.

For more usage, please refer to the official manual.

Package: flycheck

Author: Sebastian Wiesner, swiesner@lunaryorn.com

Homepage: http://flycheck.readthedocs.org/

Features:

  • Supports over 30 programming and markup languages with more than 60 different syntax checking tools
  • Fully automatic, fail-safe, on-the-fly syntax checking in background
  • Nice error indication and highlighting
  • Optional error list popup
  • Many customization options
  • A comprehensive manual
  • A simple interface to define new syntax checkers
  • A “doesn't get in your way” guarantee
  • Many 3rd party extensions

Installation;

M-x list-packages and select flycheck package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: flycheck                       ;;
;;                                         ;;
;; GROUP: Programming -> Tools -> Flycheck ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'flycheck)
(add-hook 'after-init-hook #'global-flycheck-mode)

Usage:

After you installed and activated flycheck, your supported buffers are automatically checked against errors as you typed and the errors are displayed in echo area.

Package: flycheck-tip

Author: Yuta Yamada, cokesboy@gmail.com

Homepage: Github

Features:

Show flycheck error by popupo.

Installation: M-x list-packages and select flycheck-tip package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: flycheck-tip                                      ;;
;;                                                            ;;
;; GROUP: Flycheck Tip, but just consider it part of Flycheck ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'flycheck-tip)
(flycheck-tip-use-timer 'verbose)

Usage:

The errors are now displayed by popup, instead of printing into the echo area. Echo area should be preserved for other things like eldoc-mode.

setup-applications.el

Remember to include the line (provide 'setup-applications), otherwise Emacs won't be able to load your module.Sample configuration:

(provide 'setup-applications)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Applications-> Eshell       ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'eshell)
(require 'em-alias)
(require 'cl)

;; Advise find-file-other-window to accept more than one file
(defadvice find-file-other-window (around find-files activate)
  "Also find all files within a list of files. This even works recursively."
  (if (listp filename)
      (loop for f in filename do (find-file-other-window f wildcards))
    ad-do-it))

;; In Eshell, you can run the commands in M-x
;; Here are the aliases to the commands.
;; $* means accepts all arguments.
(eshell/alias "o" "")
(eshell/alias "o" "find-file-other-window $*")
(eshell/alias "vi" "find-file-other-window $*")
(eshell/alias "vim" "find-file-other-window $*")
(eshell/alias "emacs" "find-file-other-windpow $*")
(eshell/alias "em" "find-file-other-window $*")

(add-hook
 'eshell-mode-hook
 (lambda ()
   (setq pcomplete-cycle-completions nil)))

;; change listing switches based on OS
(when (not (eq system-type 'windows-nt))
  (eshell/alias "ls" "ls --color -h --group-directories-first $*"))

setup-development.el

Remember to include the line (provide 'setup-development), otherwise Emacs won't be able to load your module. Sample configuration:

(provide 'setup-development)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Development -> Extensions -> Eldoc  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Development -> Internal     ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Start garbage collection every 100MB to improve Emacs performance
(setq gc-cons-threshold 100000000)

setup-environment.el

Remember to include the line (provide 'setup-environment), otherwise Emacs won't be able to load your module. Sample configuration:

(provide 'setup-environment)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Environment -> Initialization ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq
 inhibit-startup-screen t
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Environment -> Minibuffer   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (icomplete-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Environment -> Minibuffer -> Savehist ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; savehist saves minibuffer history by defaults
(setq savehist-additional-variables '(search ring regexp-search-ring) ; also save your regexp search queries
      savehist-autosave-interval 60     ; save every minute
      )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Environment -> Windows -> Winner ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(winner-mode 1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Environment -> Mode Line    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(column-number-mode 1)

Package: nyan-mode

Author: Jacek "TeMPOraL" Zlydach, temporal.pl@gmail.com

Homepage: http://nyan-mode.buildsomethingamazing.com/

Features:

Nyan Mode is an analog indicator of your position in the buffer. The Cat should go from left to right in your mode-line, as you move your point from 0% to 100%.

nyan-mode.png

  • Mind dumbing content included,
  • Experimental animation (M-x nyan-start-animation, M-x nyan-stop-animation),
  • Wavy rainbow (M-x set-variable <ret> nyan-wavy-trail <ret> t),
  • Customizable properties.

NOT INCLUDED: music.

Installation:

M-x list-packages and select nyan-mode package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: nyan-mode                    ;;
;;                                       ;;
;; GROUOP: Environment -> Frames -> Nyan ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; only turn on if a window system is available
;; this prevents error under terminal that does not support X
(case window-system
  ((x w32) (nyan-mode)))

Usage:

As you scroll through a buffer, the cat moves to indicate the position in buffer.

Package: golden-ratio

Author: Roman Gonzalez, romanandreg@gmail.com

Homepage: Github

Features:

Automatic resizing of Emacs windows to the golden ratio

When working with many windows at the same time, each window has a size that is not convenient for editing.

golden-ratio helps on this issue by resizing automatically the windows you are working on to the size specified in the "Golden Ratio". The window that has the main focus will have the perfect size for editing, while the ones that are not being actively edited will be re-sized to a smaller size that doesn't get in the way, but at the same time will be readable enough to know it's content.

golden-ratio.gif

Installation:

M-x list-packages and select golden-ratio package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: golden-ratio                         ;;
;;                                               ;;
;; GROUP: Environment -> Windows -> Golden Ratio ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'golden-ratio)

(add-to-list 'golden-ratio-exclude-modes "ediff-mode")
(add-to-list 'golden-ratio-exclude-modes "helm-mode")
(add-to-list 'golden-ratio-exclude-modes "dired-mode")
(add-to-list 'golden-ratio-inhibit-functions 'pl/helm-alive-p)

(defun pl/helm-alive-p ()
  (if (boundp 'helm-alive-p)
      (symbol-value 'helm-alive-p)))

;; do not enable golden-raio in thses modes
(setq golden-ratio-exclude-modes '("ediff-mode"
                                   "gud-mode"
                                   "gdb-locals-mode"
                                   "gdb-registers-mode"
                                   "gdb-breakpoints-mode"
                                   "gdb-threads-mode"
                                   "gdb-frames-mode"
                                   "gdb-inferior-io-mode"
                                   "gud-mode"
                                   "gdb-inferior-io-mode"
                                   "gdb-disassembly-mode"
                                   "gdb-memory-mode"
                                   "magit-log-mode"
                                   "magit-reflog-mode"
                                   "magit-status-mode"
                                   "IELM"
                                   "eshell-mode" "dired-mode"))

(golden-ratio-mode)

Usage:

C-x o and see your windows being resized.

setup-faces-and-ui.el

Remember to include the line (provide 'setup-faces-and-ui), otherwise Emacs won't be able to load your module. Sample configuration:

(provide 'setup-faces-and-ui)

;; you won't need any of the bar thingies
;; turn it off to save screen estate
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))

;; the blinking cursor is nothing, but an annoyance
(blink-cursor-mode -1)

(setq scroll-margin 0
      scroll-conservatively 100000
      scroll-preserve-screen-position 1)

(size-indication-mode t)

;; more useful frame title, that show either a file or a
;; buffer name (if the buffer isn't visiting a file)
;; taken from prelude-ui.el
(setq frame-title-format
      '("" invocation-name " - " (:eval (if (buffer-file-name)
                                                    (abbreviate-file-name (buffer-file-name))
                                                  "%b"))))

;; change font to Inconsolata for better looking text
;; remember to install the font Inconsolata first
(setq default-frame-alist '((font . "Inconsolata-11")))
;; set italic font for italic face, since Emacs does not set italic
;; face automatically
(set-face-attribute 'italic nil
                    :family "Inconsolata-Italic")

Package: highlight-numbers

Author: Fanael Linithien, fanael4@gmail.com

Homepage: Github

Features:

highlight-numbers is an Emacs minor mode that highlights numeric literals in source code.

Installation:

M-x list-packages and select highlight-numbers package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: highlight-numbers         ;;
;;                                    ;;
;; GROUP: Faces -> Number Font Lock   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'prog-mode-hook 'highlight-numbers-mode)

Usage:

Numbers automatically have distinct colors in buffer.

Package: highlight-symbol

Author: Nikolaj Schumacher, me@nschum.de

Homepage: Github

Features:

Automatic and manual symbol highlighting for Emacs.

Installation:

M-x list-packages and select highlight-symbol package, then install it. After finish installing, add this code snippet to activate the package:

(require 'highlight-symbol)

(highlight-symbol-nav-mode)

(add-hook 'prog-mode-hook (lambda () (highlight-symbol-mode)))
(add-hook 'org-mode-hook (lambda () (highlight-symbol-mode)))

(setq highlight-symbol-idle-delay 0.2
      highlight-symbol-on-navigation-p t)

(global-set-key [(control shift mouse-1)]
                (lambda (event)
                  (interactive "e")
                  (goto-char (posn-point (event-start event)))
                  (highlight-symbol-at-point)))

(global-set-key (kbd "M-n") 'highlight-symbol-next)
(global-set-key (kbd "M-p") 'highlight-symbol-prev)

Usage:

If you move point on a symbol, it automatically highlights all the symbols in the current screen. From now on, pressing M-n and M-p will immediately jump to the next/previous symbols in a buffer.

Change Emacs appearance by using color theme

Emacs has many color themes available for you to use. My personal one is color-theme-sanityinc-tomorrow or grandshell-theme or monokai-theme. Some popular themes are emacs-color-theme-solarized and zenburn. You can select themes of your choice from MELPA.

setup-help.el

Remember to include the line (provide 'setup-help), otherwise Emacs won't be able to load your module.

(provide 'setup-help)

Package: info+

Author: Drew Adams, drew.adams@oracle.com

Homepage: Emacswiki

Features: Info+ helps you read Info documents more enjoyable with extra highlighting it provides.

Installation:

M-x list-packages and select info+ package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GROUP: Help -> Info+               ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'info+)

Package: discover-my-major

Author: steckerhalter

Homepage: Github

Features:

Discover key bindings and their meaning for the current Emacs major mode.

discover-my-major.png

Installation:

M-x list-packages and select discover-my-major package, then install it. After finish installing, add this code snippet to activate the package:

;; A quick major mode help with discover-my-major
(global-unset-key (kbd "C-h h"))        ; original "C-h h" displays "hello world" in different languages
(define-key 'help-command (kbd "h m") 'discover-my-major)

Usage:

The above setup binds C-h h m to discover-my-major. In a buffer, C-h h m and you will see key bindings of that major mode and its description, as opposed to usual C-h m which gives mappings between keys and commands.

Package: rainbow-mode

Author: Julien Danjou, julien@danjou.info

Homepage: GNU ELPA

Features:

This minor mode sets background color to strings that match color names, e.g. #0000ff is displayed in white with a blue background.

rainbow-mode.png

Installation: M-x list-packages and select rainbow-mode package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PACKAGE: rainbow-mode              ;;
;;                                    ;;
;; GROUP: Help -> Rainbow             ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'html-mode-hook 'rainbow-mode)
(add-hook 'css-mode-hook 'rainbow-mode)

It is useful to always activate rainbow-mode in those two major modes. For other modes, it is situational, so I don't use prog-mode-hook.

Usage:

As you type a hex number or a color string in a buffer with rainbow-mode activated, the hex number or color string is colourized.

Package: help+

Author: Drew Adams, drew.adams@oracle.com

Homepage: Emacswiki

Features:

Extensions to `help.el' for Emacs

Installation:

M-x list-packages and select help+ package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: help+                     ;;
;;                                    ;;
;; GROUP: Help                        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'help+)

Usage:

The following bindings are made:

`C-h u' `manual-entry' `C-h C-a' `apropos' `C-h C-l' `locate-library' `C-h RET' `help-on-click/key' `C-h M-a' `apropos-documentation' `C-h M-o' `pop-to-help-toggle' `C-h C-M-a' `tags-apropos' [mouse-1] `mouse-help-on-click' (non-mode-line) [mouse-1] `mouse-help-on-mode-line-click' (mode-line)

Package: help-fns+

Author: Drew Adams, drew.adams@oracle.com

Homepage: Emacswiki

Features:

Extensions to `help-fns.el'

Installation:

M-x list-packages and select help-fns+ package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: help-fns+                 ;;
;;                                    ;;
;; GROUP: Help                        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'help-fns+)

Usage:

Keys bound here:

Keys Bindings
C-h B describe-buffer
C-h c describe-command (replaces describe-key-briefly)
C-h o describe-option
C-h C-c describe-key-briefly (replaces C-h c)
C-h C-o describe-option-of-type
C-h M-c describe-copying (replaces C-h C-c)
C-h M-f describe-file
C-h M-k describe-keymap
C-h M-l find-function-on-key

Package: help-mode+

Author: Drew Adams, drew.adams@oracle.com

Homepage: Emacswiki

Features:

Extensions to `help-mode.el'

Links to libraries are provided whenever library names appear in buffer ‘*Help*’. After loading help-mode+.el, library names in buffer Help have mouse-over links to the corresponding library code.

For example, ‘C-h v features’ describes the variable ‘features’; this description lists all of the libraries currently loaded in Emacs.

  • In vanilla Emacs (without help-mode+.el loaded), the library names are not linked, unless a library (such as ‘grep’) happens to have the same name as an Emacs function or variable, in which case clicking the name displays the function or variable description in buffer Help.
  • With help-mode+.el loaded, each library name in the ‘C-h v features’ list is linked to the library (code) itself. Click a name to edit/view the library file.

Installation:

M-x list-packages and select help-mode+ package, then install it. After finish installing, add this code snippet to activate the package:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package: help-mode+                ;;
;;                                    ;;
;; GROUP: Help                        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'help-mode+)

Usage:

If a *Help* buffer contains other library names, the names automatically becomes links to jump to.

setup-local.el

If you define your own Customization Group locally to your computer, your Customization Group should be added under Local parent and customize it here. The only sub-group in Local group is holiday, and I do not use it, so I leave this file blank.

More Emacs Lisp resources

If you want to learn more about Emacs Lisp programming, GNU Emacs Lisp Manual is great to start real Lisp programming.

comments powered by Disqus