Created
May 16, 2011 09:58
-
-
Save andialbrecht/974174 to your computer and use it in GitHub Desktop.
Emacs mode for running gjslint from Closure library
This file contains hidden or 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
;;; closure-gjslint.el --- Closure Lint mode | |
;; Copyright (C) 2011 Andi Albrecht | |
;; Author: Andi Albrecht <[email protected]> | |
;; Keywords: | |
;; 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 code is derived from python-pylint written by Ian Eure | |
;; <[email protected]> | |
;;; Code: | |
(defgroup closure-gjslint nil | |
"Minor mode for running gjslint" | |
:prefix "closure-gjslint-" | |
:group 'tools) | |
(defvar closure-gjslint-last-buffer nil | |
"The most recent GJSLINT buffer. | |
A GJSLINT buffer becomes most recent when you select GJSLINT mode in it. | |
Notice that using \\[next-error] or \\[compile-goto-error] modifies | |
`compilation-last-buffer' rather than `closure-gjslint-last-buffer'.") | |
;; (defconst closure-gjslint-regexp-alist | |
;; (let ((base "^Line \\([0-9]+\\),\s+\\(%s.*\\)$")) ;"^\\(.*\\) \\([0-9]+\\),\s+\\(\\[%s.*\\)$")) | |
;; (list | |
;; (list (format base "[FE]") (buffer-file-name compilation-last-buffer) 1 nil 2) | |
;; (list (format base "[RWC]") nil 1 nil 1))) | |
;; "Regexp used to match GJSLINT hits. See `compilation-error-regexp-alist'.") | |
(defcustom closure-gjslint-options '("--unix_mode") | |
"Options to pass to gjslint" | |
:type '(repeat string) | |
:group 'closure-gjslint) | |
(defcustom closure-gjslint-command "gjslint" | |
"PYLINT command." | |
:type '(file) | |
:group 'closure-gjslint) | |
(defcustom closure-gjslint-ask-about-save nil | |
"Non-nil means \\[closure-gjslint] asks which buffers to save before compiling. | |
Otherwise, it saves all modified buffers without asking." | |
:type 'boolean | |
:group 'closure-gjslint) | |
(define-compilation-mode closure-gjslint-mode "GJSLINT" | |
(setq closure-gjslint-last-buffer (current-buffer)) | |
;; (set (make-local-variable 'compilation-error-regexp-alist) | |
;; closure-gjslint-regexp-alist) | |
(set (make-local-variable 'compilation-disable-input) t)) | |
(defvar closure-gjslint-mode-map | |
(let ((map (make-sparse-keymap))) | |
(set-keymap-parent map compilation-minor-mode-map) | |
(define-key map " " 'scroll-up) | |
(define-key map "\^?" 'scroll-down) | |
(define-key map "\C-c\C-f" 'next-error-follow-minor-mode) | |
(define-key map "\r" 'compile-goto-error) ;; ? | |
(define-key map "n" 'next-error-no-select) | |
(define-key map "p" 'previous-error-no-select) | |
(define-key map "{" 'compilation-previous-file) | |
(define-key map "}" 'compilation-next-file) | |
(define-key map "\t" 'compilation-next-error) | |
(define-key map [backtab] 'compilation-previous-error) | |
map) | |
"Keymap for GJSLINT buffers. | |
`compilation-minor-mode-map' is a cdr of this.") | |
;;;###autoload | |
(defun closure-gjslint () | |
"Run GJSLINT, and collect output in a buffer. | |
While gjslint runs asynchronously, you can use \\[next-error] (M-x next-error), | |
or \\<closure-gjslint-mode-map>\\[compile-goto-error] in the grep \ | |
output buffer, to go to the lines where gjslint found matches." | |
(interactive) | |
(save-some-buffers (not closure-gjslint-ask-about-save) nil) | |
(let* ((tramp (tramp-tramp-file-p (buffer-file-name))) | |
(file (or (and tramp | |
(aref (tramp-dissect-file-name (buffer-file-name)) 3)) | |
(buffer-file-name))) | |
(command (mapconcat | |
'identity | |
(list closure-gjslint-command | |
(mapconcat 'identity closure-gjslint-options " ") | |
(comint-quote-filename file)) " "))) | |
(compilation-start command 'closure-gjslint-mode))) | |
;;;###autoload | |
(defalias 'gjslint 'closure-gjslint) | |
(provide 'closure-gjslint) | |
;;; closure-glslint.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment