Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

86 lines (72 sloc) 3.648 kb
(setq-default js2-allow-rhino-new-expr-initializer nil)
(setq-default js2-auto-indent-p nil)
(setq-default js2-enter-indents-newline nil)
(setq-default js2-global-externs '("module" "require" "jQuery" "$" "_" "buster" "sinon" "assert" "refute" "setTimeout" "clearTimeout" "setInterval" "clearInterval" "location" "__dirname"))
(setq-default js2-idle-timer-delay 0.1)
(setq-default js2-indent-on-enter-key nil)
(setq-default js2-mirror-mode nil)
(setq-default js2-strict-inconsistent-return-warning nil)
(setq-default js2-auto-indent-p t)
(setq-default js2-rebind-eol-bol-keys nil)
(setq-default js2-include-rhino-externs nil)
(setq-default js2-include-gears-externs nil)
(setq-default js2-concat-multiline-strings 'eol)
(require 'js2-mode)
(require 'js2-refactor)
(require 'js2-imenu-extras)
(js2-imenu-extras-setup)
(define-key js2-mode-map (kbd "C-c RET jt") 'jump-to-test-file)
(define-key js2-mode-map (kbd "C-c RET ot") 'jump-to-test-file-other-window)
(define-key js2-mode-map (kbd "C-c RET js") 'jump-to-source-file)
(define-key js2-mode-map (kbd "C-c RET os") 'jump-to-source-file-other-window)
(define-key js2-mode-map (kbd "C-c RET jo") 'jump-between-source-and-test-files)
(define-key js2-mode-map (kbd "C-c RET oo") 'jump-between-source-and-test-files-other-window)
(define-key js2-mode-map (kbd "C-c RET ta") 'toggle-assert-refute)
(defadvice js2r-inline-var (after reindent-buffer activate)
(cleanup-buffer))
(defun js2-hide-test-functions ()
(interactive)
(save-excursion
(goto-char (point-min))
(ignore-errors
(while (re-search-forward "\"[^\"]+\": function (")
(js2-mode-hide-element)))))
(define-key js2-mode-map (kbd "C-c t") 'js2-hide-test-functions)
;; js2-mode steals TAB, let's steal it back for yasnippet
(defun js2-tab-properly ()
(interactive)
(let ((yas/fallback-behavior 'return-nil))
(unless (yas/expand)
(indent-for-tab-command)
(if (looking-back "^\s*")
(back-to-indentation)))))
(define-key js2-mode-map (kbd "TAB") 'js2-tab-properly)
;; Use lambda for anonymous functions
(font-lock-add-keywords
'js2-mode `(("\\(function\\) *("
(0 (progn (compose-region (match-beginning 1)
(match-end 1) "\u0192")
nil)))))
;; Use right arrow for return in one-line functions
(font-lock-add-keywords
'js2-mode `(("function *([^)]*) *{ *\\(return\\) "
(0 (progn (compose-region (match-beginning 1)
(match-end 1) "\u2190")
nil)))))
;; After js2 has parsed a js file, we look for jslint globals decl comment ("/* global Fred, _, Harry */") and
;; add any symbols to a buffer-local var of acceptable global vars
;; Note that we also support the "symbol: true" way of specifying names via a hack (remove any ":true"
;; to make it look like a plain decl, and any ':false' are left behind so they'll effectively be ignored as
;; you can;t have a symbol called "someName:false"
(add-hook 'js2-post-parse-callbacks
(lambda ()
(when (> (buffer-size) 0)
(let ((btext (replace-regexp-in-string
": *true" " "
(replace-regexp-in-string "[\n\t ]+" " " (buffer-substring-no-properties 1 (buffer-size)) t t))))
(mapc (apply-partially 'add-to-list 'js2-additional-externs)
(split-string
(if (string-match "/\\* *global *\\(.*?\\) *\\*/" btext) (match-string-no-properties 1 btext) "")
" *, *" t))
))))
(provide 'setup-js2-mode)
Jump to Line
Something went wrong with that request. Please try again.