Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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
'(progn
;; Cosmetics
(font-lock-add-keywords
'js2-mode `(("\\(function *\\)("
(0 (progn (compose-region (match-beginning 1) (match-end 1)
"ƒ")
nil)))))
(font-lock-add-keywords
'js2-mode
'(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
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)
(indent-for-tab-command)
(back-to-indentation)))
(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."
(interactive)
(let ((start (save-excursion (js-re-search-backward "\\<var\\>" nil t))))
(and start
(save-excursion (re-search-backward "\n" start t))
(not (save-excursion
(js-re-search-backward
";\\|[^, \t][ \t]*\\(/[/*]\\|$\\)" start t))))))
(defun js-proper-indentation (parse-status)
"Return the proper indentation for the current line."
(save-excursion
(back-to-indentation)
(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-continued-var-decl-list-p)
(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]*\\(/[/*]\\|$\\)")
(progn
(skip-syntax-backward " ")
(when (= (char-before) ?\)) (backward-list))
(back-to-indentation)
(cond (same-indent-p
(current-column))
(continued-expr-p
(+ (current-column) (* 2 js2-basic-offset)))
(t
(+ (current-column) js2-basic-offset))))
(unless same-indent-p
(forward-char)
(skip-chars-forward " \t"))
(current-column)))
(continued-expr-p js2-basic-offset)
(t 0)))))))
(defun esk-pp-json ()
"Pretty-print the json object following point."
(interactive)
(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.