Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e1451b94d3
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (71 sloc) 3.348 kb
; js2
(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
; js-shell
(autoload 'javascript-shell "javascript-mode" nil t)
(defun js2-insert-console ()
(insert "console.log()")
(defun js2-execute-buffer ()
(shell-command (concat "johnson " (buffer-file-name))))
(defun js2-execute-line ()
(call-process-region (point-at-bol)
(get-buffer-create "*johnson-line*"))
(with-current-buffer (get-buffer "*johnson-line*")
(search-backward "\n\n" nil t)
(replace-match "" nil t)
(message (buffer-string))
(kill-buffer nil))))
(add-hook 'js2-mode-hook
'(lambda ()
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(define-key js2-mode-map (kbd "A-r") 'js2-execute-buffer)
(define-key js2-mode-map (kbd "A-R") 'js2-execute-line)
(define-key js2-mode-map "\C-L" 'js2-insert-console)
(defun js-continued-var-decl-list-p ()
"Return non-nil if point is inside a continued variable declaration
(let ((start (save-excursion (js-re-search-backward "\\<var\\>" nil t))))
(and start
(save-excursion (re-search-backward "\n" start t))
(not (save-excursion
";\\|[^, \t][ \t]*\\(/[/*]\\|$\\)" start t))))))
(defun js-proper-indentation (parse-status)
"Return the proper indentation for the current line."
(let ((ctrl-stmt-indent (js-ctrl-statement-indentation))
(same-indent-p (looking-at "[]})]\\|\\<case\\>\\|\\<default\\>"))
(continued-expr-p (js-continued-expression-p)))
(cond (ctrl-stmt-indent)
(js-re-search-backward "\\<var\\>" nil t)
(+ (current-indentation) js2-basic-offset))
((nth 1 parse-status)
(goto-char (nth 1 parse-status))
(if (looking-at "[({[][ \t]*\\(/[/*]\\|$\\)")
(skip-syntax-backward " ")
(when (= (char-before) ?\)) (backward-list))
(cond (same-indent-p
(+ (current-column) (* 2 js2-basic-offset)))
(+ (current-column) js2-basic-offset))))
(unless same-indent-p
(skip-chars-forward " \t"))
(continued-expr-p js2-basic-offset)
(t 0)))))))
Jump to Line
Something went wrong with that request. Please try again.