compile command. The setup required is not especially complex but could be mildly tricky to figure out for people new to emacs.
The additional emacs lisp code needed is simply:
;; Add parsing of jshint output in compilation mode (add-to-list 'compilation-error-regexp-alist-alist '(jshint "^\\(.*\\): line \\([0-9]+\\), col \\([0-9]+\\), " 1 2 3)) (add-to-list 'compilation-error-regexp-alist 'jshint)
(Add this code to a config file that is loaded by emacs, typically
To “compile” with
jshint run the emacs command
(or use an alternative shell glob to select the files you want to check). The compilation buffer should appear and should allow you to step through errors just like using a real compiler.
Compilation mode extracts error location information using a simple parser consisting of a regular expression and a few other bits of information. In the commands above we added a parser for the error messages from
New parsers are defined by a list as specified in the documentation for
jshint parser is as follows:
(jshint "^\\(.*\\): line \\([0-9]+\\), col \\([0-9]+\\), " 1 2 3)
The first element is the name of the parser. The second argument is a string containing the regex itself. The final arguments are the numbers of the matches (the first match is numbered 1) which specify the file, the line number and the column number respectively.
In fact emacs stores the parser information in a slightly more complex way. There are two lists: a list of available parsers (
compilation-error-regexp-alist-alist) and a list of which parsers to use (
compilation-error-regexp-alist). In the code above the first line defines the parser and adds it to the list of available parsers. The second line adds our new parser to the list of parsers to use.
The command to step through errors is
Also bind the commands
recompileto easy to press keys for best effect.
If you’re installing
jshinton a Debian-based system via
npmyou may need the additional package
nodejs-legacyto deal with name clashes (there are multiple Debian packages with binaries named
node. So the node binary installed by the standard nodejs package is called
nodejsinstead. Not many
npmpackages handle this correctly. The
nodejs-legacypackage adds a binary named