Skip to content

aredington/kibit-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kibit-mode

kibit-mode is a combination of a thin wrapper around the excellent kibit tool, and a minor for Clojure buffers that will help you find ways to make your Clojure code more idiomatic.

Requirements

Configuration

Via el-get

I use el-get to manage my Emacs config. To add kibit-mode, I added the following to my package definitions:

(:name kibit-mode
       :type git
       :url "https://github.com/aredington/kibit-mode.git"
       :after (lambda ()
                (require 'kibit-mode)
                (add-hook 'clojure-mode-hook 'kibit-mode)))

The important bits are to get kibit-mode.el on your load-path, require it, and add it as a hook to clojure-mode. Hopefully this works for you if you also use el-get, if you do not use el-get you are on your own.

Via package.el melpa

You can also install kibit-mode with package.el whichis built-in package manager in Emacs 24+. If you use Emacs 23, you can get package.el yourself.

To install kibit-mode, you need this to your ~/.emacs.d/init.el.

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

And then you can install kibit-mode with the following command:

M-x package-install [RET] kibit-mode [RET]

or by adding this bit of Emacs Lisp code to your Emacs initialization file(.emacs or init.el):

(when (not (package-installed-p 'kibit-mode)
  (package-install 'kibit-mode)

If the installation dosen't work try refreshing the package list:

M-x package-refresh-contents [RET]

Usage

In an open Clojure buffer, hit C-c C-n (you can use the mnemonic that this Compilation tool will help you catch Noob mistakes) to open a compilation buffer that will tell you where you can replace code with a terser, more idiomatic expression of the same semantics.

The compilation buffer will output formatted filename and line number indicators of kibits suggestions, like follows:

/Users/alex/projects/pi/src/pi/core.clj:5:
  Replace
    (if (even? x) x nil)
  with
    (when (even? x) x)

You can jump immediately to the suggestion from the compilation buffer by hitting enter. If you do not have any code that kibit thinks it can improve, then it will exit happily and the compilation step will report success.

Reverse Double Secret Next Level Maneuver

If you add the following to your emacs config:

(add-hook 'clojure-mode-hook 'flymake-mode-on)

Then kibit-mode will be registered as a flymake checker and check your code for you as you write. It will highlight the line which starts the form relevant to kibit's suggestion. This part is pretty ugly and hacked together with a shell script, be warned.

To use kibit-mode with flycheck, add the following to your emacs config:

(add-hook 'clojure-mode-hook 'flycheck-mode)

License

Copyright (C) 2012 Alex Redington

Distributed under the MIT License

About

Exec Kibit as a compiler against your Clojure code in Emacs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published