paradoxxxzero / emacs-git-gutter

Emacs port of GitGutter which is Sublime Text Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

git-gutter.el

Introduction

git-gutter.el is port of GitGutter which is a plugin of Sublime Text.

git-gutter.el also supports TRAMP so you can use git-gutter.el for remote files.

git-gutter.el does not work well with linum-mode. Please see git-gutter-fringe which can work with linum-mode, if you use linum-mode.

Screenshot

git-gutter.el

Requirements

  • Emacs 23 or higher
  • Git

Installation

You can install git-gutter.el from MELPA with package.el (M-x package-install git-gutter).

And you can also install it with el-get.

Global Minor Mode and Minor Mode

git-gutter.el provides global minor-mode(global-git-gutter-mode) and minor-mode(git-gutter-mode).

If you want to use git-gutter for files in git repository. You add following s-exp in your configuration file(~/.emacs.d/init.el or ~/.emacs).

(global-git-gutter-mode t)

Other case, you want to use git-gutter for some files, you can use git-gutter-mode. Following example of enabling git-gutter for some mode.

(add-hook 'ruby-mode-hook 'git-gutter-mode)
(add-hook 'python-mode-hook 'git-gutter-mode)

Basic Usage

git-gutter.el provides following commands.

Show changes from last commit or Update change information.

M-x git-gutter

Clear changes

M-x git-gutter:clear

Toggle git-gutter

M-x git-gutter:toggle

Jump to next hunk(alias git-gutter:next-diff)

M-x git-gutter:next-hunk

Jump to previous hunk(alias git-gutter:previous-diff)

M-x git-gutter:previous-hunk

Popup diff of current position

M-x git-gutter:popup-diff

git-gutter:next-hunk and git-gutter:previous-hunk update content of buffer popuped by git-gutter:popup-diff to current hunk.

Revert current hunk

M-x git-gutter:revert-hunk

Sample Configuration

(require 'git-gutter)

;; If you enable global minor mode
(global-git-gutter-mode t)

;; If you enable git-gutter-mode for some modes
(add-hook 'ruby-mode-hook 'git-gutter-mode)

(global-set-key (kbd "C-x C-g") 'git-gutter:toggle)
(global-set-key (kbd "C-x v =") 'git-gutter:popup-diff)

;; Jump to next/previous hunk
(global-set-key (kbd "C-x p") 'git-gutter:previous-hunk)
(global-set-key (kbd "C-x n") 'git-gutter:next-hunk)

;; Revert current hunk
(global-set-key (kbd "C-x r") 'git-gutter:revert-hunk)

Customize

Look and feel

git-gutter-multichar

You can change the signs and those faces.

(setq git-gutter:modified-sign "  ") ;; two space
(setq git-gutter:added-sign "++")    ;; multiple character is OK
(setq git-gutter:deleted-sign "--")

(set-face-background 'git-gutter:modified "purple") ;; background color
(set-face-foreground 'git-gutter:added "green")
(set-face-foreground 'git-gutter:deleted "red")

You can change minor-mode name in mode-line to set git-gutter:lighter. Default is " GitGutter"

;; first character should be a space
(setq git-gutter:lighter " GG")

Using full width characters

git-gutter-fullwidth

Emacs has char-width function which returns character width. git-gutter.el uses it for calculating character length of the signs. But char-width does not work for some full-width characters. So you should explicitly specify window width, if you use full-width character.

(setq git-gutter:window-width 2)
(setq git-gutter:modified-sign "")
(setq git-gutter:added-sign "")
(setq git-gutter:deleted-sign "")

Show Unchanged Information

git-gutter-unchanged

git-gutter.el can view unchanged information by setting git-gutter:unchanged-sign. Like following.

(setq git-gutter:unchanged-sign " ")
(set-face-background 'git-gutter:unchanged "yellow")

Default value of git-gutter:unchanged-sign is nil.

Always Show Gutter

Always show gutter if git-gutter:always-show-gutter is non-nil. (Default is nil)

(setq git-gutter:always-show-gutter t)

Pass option to 'git diff' command

You can pass git diff option to set git-gutter:diff-option.

;; ignore all spaces
(setq git-gutter:diff-option "-w")

Run hook

Run hook git-gutter-mode-on-hook when git-gutter-mode is turn on, and run hook git-gutter-mode-off-hook when git-gutter-mode is turn off.

See Also

GitGutter is Sublime Text plugin.

diff-hl has more features than git-gutter.el.

Vim version of GitGutter

Another implementation of git-gutter.el

How to write another implementation

About

Emacs port of GitGutter which is Sublime Text Plugin


Languages

Language:Emacs Lisp 100.0%