defunkt / coffee-mode

Emacs Major Mode for CoffeeScript
http://ozmm.org/posts/coffee_mode.html
574 stars 147 forks source link

Ability to run npm tests and file clickable on error output #306

Open shakthimaan opened 9 years ago

shakthimaan commented 9 years ago

Hi,

Firstly, thanks for writing and maintaining coffee-mode.

1 Is there a way to run 'npm run tests' defined in a project package.json from coffee-mode. I currently use:

(setq inferior-js-mode-hook
      (lambda ()
        ;; We like nice colors
        (ansi-color-for-comint-mode-on)
        ;; Deal with some prompt nonsense
        (add-to-list
         'comint-preoutput-filter-functions
         (lambda (output)
           (replace-regexp-in-string "\033\\[[0-9]+[GK]" "" output)))))

and run "npm run test" manually in M-x shell. But, I would like to be able to do it with a short-cut. Is there a way to enable this mode automatically when opening *.coffee files?

2 If there are errors in the npm output, the errored files are not clickable in the Emacs buffer. Is there a way to change the format of npm output such that the files are clickable inside Emacs buffers?

I was not able to use the following for *.coffee files: https://github.com/startup-class/dotfiles/blob/master/.emacs.d/js-config.el

Appreciate your help in this regard.

Thanks!

syohex commented 9 years ago

Is there a way to run 'npm run tests' defined in a project package.json from coffee-mode.

no way. You can write such command as below.

;; for displaying ANSI escape sequences correctly
(eval-after-load 'compile
  '(add-hook 'compilation-filter-hook
        (lambda () (ansi-color-process-output nil))))

(defun npm-test ()
  (interactive)
  (let ((root (locate-dominating-file default-directory "package.json")))
    (unless root
      (error "Here is not npm package"))
    (let ((default-directory root))
      (compile "npm run test"))))

If there are errors in the npm output, the errored files are not clickable in the Emacs buffer. Is there a way to change the format of npm output such that the files are clickable inside Emacs buffers?

It may be possible if you set compilation-error-regexp-alist-alist properly. However I think it is difficult because output of npm run test vary among test framework. (Sorry I don't understand npm well)

shakthimaan commented 9 years ago

Thanks for the code snippet. I tried the above and I am able to now see a clickable pointer to the lines containing files, although I still need to look into setting compilation-error-regexp-alist. But, I still see the control characters in the compilation output. For example:

^[[2K^[[0G 2) "after all" hook
^[[2K^[[0G a\234\223 should return the expected output

What could I be missing?

syohex commented 9 years ago

Do you evaluate following expression ?

(eval-after-load 'compile
  '(add-hook 'compilation-filter-hook
        (lambda () (ansi-color-process-output nil))))

If you evaluate it, then you get output like following screenshot. npm-test

shakthimaan commented 9 years ago

I tried evaluating the above, but, I still see the control characters in the output.

^[[2K^[[0G 2) "after all" hook
^[[2K^[[0G a\234\223 should return the expected output

Could it be because of my custom settings?

https://github.com/shakthimaan/cask-dot-emacs/tree/master/etc

I tried starting emacs with "-Q" option, and after evaluating the above S-expressions I still see the control characters. I also tried your dot_files, and after evaluating the above S-expressions, I still see the control characters.

What was the configuration that you used to get the above screenshot?