Find file
Fetching contributors…
Cannot retrieve contributors at this time
85 lines (73 sloc) 3 KB
;; Add "support" for js files in speedbar, interpreted as c
(speedbar-add-supported-extension ".js")
(add-to-list 'speedbar-fetch-etags-parse-list
'("\\.js" . speedbar-parse-c-or-c++tag))
(defun aj-js-compr-buffer()
;; Change yui compr to fit your path
(let ((yui-compr-jar (expand-file-name "~/lib/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar")))
(concat "java -jar " yui-compr-jar
" -o " (first (split-string (buffer-file-name)
"[.]js")) ".min.js"
" "(buffer-file-name)))))
;; From:
(defun my-js2-indent-function ()
(let* ((inhibit-point-motion-hooks t)
(parse-status (save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation)))
(indentation (espresso--proper-indentation parse-status))
;; I like to indent case and labels to half of the tab width
(if (looking-at "case\\s-")
(setq indentation (+ indentation (/ espresso-indent-level 2))))
;; consecutive declarations in a var statement are nice if
;; properly aligned, i.e:
;; var foo = "bar",
;; bar = "foo";
(setq node (js2-node-at-point))
(when (and node
(= js2-NAME (js2-node-type node))
(= js2-VAR (js2-node-type (js2-node-parent node))))
(setq indentation (+ 4 indentation))))
(indent-line-to indentation)
(when (> offset 0) (forward-char offset)))))
(defun my-js2-mode-hook ()
(require 'espresso)
;; fix bug with my-indent-sexp
(setq c-current-comment-prefix
(if (listp c-comment-prefix-regexp)
(cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
(assoc 'other c-comment-prefix-regexp)))
;; end bug with my-indent-sexp
(setq espresso-indent-level 4
indent-tabs-mode nil
c-basic-offset 4)
(c-toggle-auto-state 0)
(c-toggle-hungry-state 1)
(set (make-local-variable 'indent-line-function) 'my-js2-indent-function)
(define-key js2-mode-map [(meta control |)] 'cperl-lineup)
(define-key js2-mode-map [(meta control \;)]
(insert "/* -----[ ")
(insert " ]----- */"))
(define-key js2-mode-map [(meta q)] 'c-fill-paragraph)
(define-key js2-mode-map [(return)] 'newline-and-indent)
(define-key js2-mode-map [(backspace)] 'c-electric-backspace)
(define-key js2-mode-map [(control d)] 'c-electric-delete-forward)
(define-key js2-mode-map [(control meta q)] 'my-indent-sexp)
(if (featurep 'js2-highlight-vars)
(message "My JS2 hook"))
(add-hook 'js2-mode-hook 'my-js2-mode-hook)
(provide 'aj-js)