Permalink
Browse files

Initial check-in

  • Loading branch information...
0 parents commit ede1acefee344fa396b7468265b061fbf19b47dd @purcell committed Nov 4, 2012
Showing with 96 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +95 −0 flymake-easy.el
@@ -0,0 +1 @@
+/flymake-easy.elc
@@ -0,0 +1,95 @@
+;;; flymake-easy.el --- Helpers for easily building flymake checkers
+
+;; Copyright (C) 2012 Steve Purcell
+
+;; Author: Steve Purcell <steve@sanityinc.com>
+;; URL: https://github.com/purcell/flymake-easy
+;; Keywords: convenience, internal
+
+;; 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.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides the `flymake-easy-load' helper function for
+;; setting up flymake checkers. Just call that function with the
+;; appropriate arguments in a major mode hook function. See
+;; `flymake-ruby' for an example:
+;; https://github.com/purcell/flymake-ruby
+
+;;; Code:
+
+(require 'flymake)
+
+(defvar flymake-easy--active nil
+ "Indicates when flymake-easy-load has successfully run in this buffer.")
+(defvar flymake-easy--command-fn nil
+ "The user-specified function for building the flymake command.")
+(defvar flymake-easy--location nil
+ "Where to create the temp file when checking, one of 'tempdir or 'inplace.")
+(defvar flymake-easy--extension nil
+ "The canonical file name extension to use for the current file.")
+
+(mapc 'make-variable-buffer-local
+ '(flymake-easy--active
+ flymake-easy--command-fn
+ flymake-easy--location
+ flymake-easy--extension))
+
+(defun flymake-easy--tempfile-in-temp-dir (file-name prefix)
+ "Create a temporary file for storing the contents of FILE-NAME in the system tempdir.
+Argument PREFIX temp file prefix, supplied by flymake."
+ (make-temp-file (or prefix "flymake-easy") nil flymake-easy--extension))
+
+(defun flymake-easy--flymake-init ()
+ "A catch-all flymake init function for use in `flymake-allowed-file-name-masks'."
+ (let* ((tempfile
+ (flymake-init-create-temp-buffer-copy
+ (cond
+ ((eq 'tempdir flymake-easy--location)
+ 'flymake-easy--tempfile-in-temp-dir)
+ ((eq 'inplace flymake-easy--location)
+ 'flymake-create-temp-inplace)
+ (t
+ (error "unknown location for flymake-easy: %s" flymake-easy--location)))))
+ (command (funcall flymake-easy--command-fn tempfile)))
+ (list (first command) (rest command))))
+
+(defun flymake-easy-load (command-fn err-line-patterns &optional location extension)
+ "Enable flymake in the containing buffer using a specific narrow configuration.
+Argument COMMAND-FN function called to build the
+ command line to run (receives filename, returns list).
+Argument ERR-LINE-PATTERNS patterns for identifying errors (see `flymake-err-line-patterns').
+Argument EXTENSION a canonical extension for this type of source file, e.g. \"rb\".
+Argument LOCATION where to create the temporary copy: one of 'tempdir (default) or 'inplace."
+ (let ((executable (first (funcall command-fn "dummy"))))
+ (if (executable-find executable)
+ (progn
+ (setq flymake-easy--command-fn command-fn
+ flymake-easy--location (or location 'tempdir)
+ flymake-easy--extension extension
+ flymake-easy--active t)
+ (set (make-local-variable 'flymake-allowed-file-name-masks)
+ '(("." flymake-easy--flymake-init)))
+ (set (make-local-variable 'flymake-err-line-patterns) err-line-patterns)
+ (flymake-mode t))
+ (message "Not enabling flymake: '%s' command not found" executable))))
+
+
+(defadvice flymake-post-syntax-check (before flymake-easy--force-check-was-interrupted activate)
+ (when flymake-easy--active
+ (setq flymake-check-was-interrupted t)))
+
+
+(provide 'flymake-easy)
+;;; flymake-easy.el ends here

0 comments on commit ede1ace

Please sign in to comment.