Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: fe721654bd
Fetching contributors…

Cannot retrieve contributors at this time

88 lines (76 sloc) 3.431 kB
;;; starter-kit-js.el --- Some helpful Javascript helpers
;; Part of the Emacs Starter Kit
(eval-after-load 'js2-mode
;; Cosmetics
'js2-mode `(("\\(function *\\)("
(0 (progn (compose-region (match-beginning 1) (match-end 1)
1 font-lock-warning-face t)))
(defun js-lambda () (interactive) (insert "function () {\n}")
(backward-char 5))
(add-hook 'js2-mode-hook 'coding-hook)
(define-key js2-mode-map (kbd "C-c l") 'js-lambda)
(define-key js2-mode-map "\C-\M-h" 'backward-kill-word)
;; Fix js2's crazy indentation
(define-key js2-mode-map (kbd "TAB") (lambda () (interactive)
(setq js2-bounce-indent-flag nil
js2-indent-on-enter-key t)
(defun js-continued-var-decl-list-p ()
"Return non-nil if point is inside a continued variable declaration list."
(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)))))))
(defun esk-pp-json ()
"Pretty-print the json object following point."
(require 'json)
(let ((json-object (save-excursion (json-read))))
(switch-to-buffer "*json*")
(delete-region (point-min) (point-max))
(insert (pp json-object))
(goto-char (point-min))))
(provide 'starter-kit-js)
;;; starter-kit-js.el ends here
Jump to Line
Something went wrong with that request. Please try again.