diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..114e85a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/pom.xml +*jar +/lib +/classes +/native +/.lein-failures +/checkouts +/.lein-deps-sum diff --git a/README b/README new file mode 100644 index 0000000..d1a6e94 --- /dev/null +++ b/README @@ -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. diff --git a/kibit-mode.el b/kibit-mode.el new file mode 100644 index 0000000..54c1550 --- /dev/null +++ b/kibit-mode.el @@ -0,0 +1,87 @@ +;;; kibit-mode.el --- Enhance clojure-mode with Kibit analysis + +;; Copyright (C) 2012 Alex Redington +;; 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 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 diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..4b68073 --- /dev/null +++ b/project.clj @@ -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"]]) diff --git a/src/kibit_mode/core.clj b/src/kibit_mode/core.clj new file mode 100644 index 0000000..5384259 --- /dev/null +++ b/src/kibit_mode/core.clj @@ -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)))