Skip to content

Instantly share code, notes, and snippets.

@sharapeco
Created December 4, 2013 06:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharapeco/7783075 to your computer and use it in GitHub Desktop.
Save sharapeco/7783075 to your computer and use it in GitHub Desktop.
xyzzy で JSHint
(defun jshint (&optional (filename (get-buffer-file-name)))
"jscript-mode: このファイルの文法チェック"
(interactive)
(let (command
(bufname "*JSHint*")
(noerror-message "No errors detected")
buf
line
col
(error-message nil))
(when filename
(save-window-excursion
(execute-shell-command
(concat "jshint \"" filename "\"") nil bufname)
(switch-to-buffer bufname)
(goto-char (point-min))
(unless (looking-for noerror-message)
(when (scan-buffer "^.+: line \\([0-9]+\\), col \\([0-9]+\\), .+$" :regexp t)
(setq error-message (match-string 0)
noerror-message (match-string 0)
line (parse-integer (match-string 1))
col (parse-integer (match-string 2))
)))
(kill-buffer bufname))
(when error-message
(setq buf (get-file-buffer filename))
(unless buf
(setq buf (create-file-buffer filename)))
(switch-to-buffer buf)
(goto-line line)
(reverse-region (progn (goto-eol) (point))
(progn (goto-bol) (point)) t)
(goto-column (- col 1))
(ding))
(message noerror-message))))
(define-key *jscript-mode-map* '(#\C-c #\l) 'jshint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment