Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Redington
committed
May 18, 2012
0 parents
commit 5018863
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/pom.xml | ||
*jar | ||
/lib | ||
/classes | ||
/native | ||
/.lein-failures | ||
/checkouts | ||
/.lein-deps-sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# kibit-mode | ||
|
||
FIXME: write description | ||
|
||
## Usage | ||
|
||
FIXME: write | ||
|
||
## License | ||
|
||
Copyright (C) 2012 FIXME | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
;;; kibit-mode.el --- Enhance clojure-mode with Kibit analysis | ||
|
||
;; Copyright (C) 2012 Alex Redington <http://www.holychao.com> | ||
;; Authors: Alex Redington | ||
;; Created: 2012 | ||
;; Version: 0.1 | ||
;; Keywords: clojure kibit | ||
;; Package-Requires: ((clojure-mode "1.11.5") | ||
;; (mode-compile "2.29")) | ||
|
||
;;; Commentary: | ||
;; | ||
;; This file is NOT part of GNU Emacs. | ||
;; | ||
;; This program is free software: you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation, either version 3 of the License, or | ||
;; (at your option) any later version. | ||
;; | ||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
;; | ||
;; See <http://www.gnu.org/licenses/> for a copy of the GNU General | ||
;; Public License. | ||
|
||
|
||
;;; Documentation: | ||
;; | ||
;; This minor mode acts as a compilation mechanism for interactively replacing | ||
;; clojure s-expressions by their more idiomatic representations. It provides | ||
;; the following capabilities: | ||
;; | ||
;; * Run a check over the currently open file (bound to `\C-c \C-n`). This will | ||
;; open a compilation mode buffer showing the kibit replacements. | ||
;; | ||
;; * Implement a suggested replacement (bound to `r`). This will destroy the | ||
;; extant formatting when the replacement is inserted | ||
|
||
;;; Dependencies: | ||
;; This minor mode depends on `mode-compile` and `clojure-mode`. | ||
|
||
;;; Change Log: | ||
;; | ||
;; 0.1 - First cut of kibit-mode | ||
|
||
;;; Code: | ||
|
||
(require 'clojure-mode) | ||
|
||
(defconst kibit-mode-keymap (make-sparse-keymap) "Keymap used in kibit mode") | ||
|
||
(define-key kibit-mode-keymap (kbd "C-c C-n") 'kibit-check) | ||
|
||
(defgroup kibit-mode nil | ||
"Kibit minor mode.") | ||
|
||
(eval-and-compile | ||
(defvar kibit-mode-path | ||
(let ((path (or (locate-library "kibit-mode") load-file-name))) | ||
(and path (file-name-directory path))) | ||
"Directory containing the kibit-mode package. | ||
This is used to execute the supporting kibit analysis execution environment. | ||
The default value is automatically computed from the location of the | ||
Emacs Lisp package.")) | ||
|
||
|
||
;;;###autoload | ||
(define-minor-mode kibit-mode | ||
"Minor mode for kibit compilation support" | ||
:lighter " kibit" | ||
:keymap kibit-mode-keymap) | ||
|
||
(defun kibit-check () | ||
"Runs the current file through kibit check" | ||
(interactive) | ||
(cd kibit-mode-path) | ||
(compile (concat "lein run -m kibit-mode.core " | ||
(buffer-file-name)))) | ||
|
||
(add-to-list 'compilation-error-regexp-alist-alist | ||
'(kibit-mode "\\([0-9A-Za-z_./\:-]+\\.clj\\):\\([0-9]+\\):" 1 2)) | ||
(add-to-list 'compilation-error-regexp-alist 'kibit-mode) | ||
|
||
(provide 'kibit-mode) | ||
;;; kibit-mode.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(defproject kibit-mode "0.0.1" | ||
:description "A kibit compiler for Clojure files" | ||
:dependencies [[org.clojure/clojure "1.4.0"] | ||
[jonase/kibit "0.0.3"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(ns kibit-mode.core | ||
(:require [kibit.check :as c] | ||
[clojure.java.io :as io] | ||
[clojure.string :as s])) | ||
|
||
(defn report-error | ||
"Given a kibit simplification, print the line number and normalized | ||
form of the expr and the replacement" | ||
[file {:keys [expr alt line] :as simplify-map}] | ||
(println (str file | ||
":" | ||
line | ||
":\n Replace\n " | ||
(pr-str expr) | ||
"\n with\n " | ||
(pr-str alt) | ||
))) | ||
|
||
|
||
|
||
(defn check-file | ||
[file] | ||
(with-open [reader (io/reader file)] | ||
(let [errors (c/check-reader reader)] | ||
(doseq [simplify-map errors] | ||
(report-error file simplify-map)) | ||
errors))) | ||
|
||
(defn -main | ||
[file] | ||
(when-not (empty? (check-file file)) | ||
(System/exit 1))) |