Pages

Tuesday, June 4, 2013

emacs javasscript

(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))

(eval-after-load 'js2-mode '(progn
                              (require 'js-beautify)

                              (add-to-list 'load-path "~/.emacs.d/jquery-doc.el")
                              (require 'jquery-doc)
                              (require 'flymake-jshint)

                              (add-hook 'js2-mode-hook '(lambda ()
                                                          (flymake-mode 1)
                                                          (jquery-doc-setup)
                                                          (local-set-key "\M-t" 'js-beautify)
                                                          (define-key js2-mode-map [(shift f10)]  (lambda()(interactive)(jslint-thisfile)))))

                              (eval-after-load 'js2-mode
                                '(progn
                                   (define-key js2-mode-map (kbd "TAB") (lambda()
                                                                          (interactive)
                                                                          (let ((yas/fallback-behavior 'return-nil))
                                                                            (unless (yas/expand)
                                                                              (indent-for-tab-command)
                                                                              (if (looking-back "^\s*")
                                                                                  (back-to-indentation))))))))

                              ;; javascript lint 
                              (defun jslint-thisfile ()
                                (interactive)
                                (compile (format "jsl -process %s" (buffer-file-name))))

                              (require 'js-comint)
                              ;; Use node as our repl
                              (setq inferior-js-program-command "node")
                              (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 ".*1G\.\.\..*5G" "..."
                                                                               (replace-regexp-in-string ".*1G.*3G" ">" output))))))

                              ))

(provide 'rgr-javascript)