Skip to content

Instantly share code, notes, and snippets.

@kchodorow
Created September 16, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kchodorow/082a5175b7edcb42f0e206f19b94993d to your computer and use it in GitHub Desktop.
Save kchodorow/082a5175b7edcb42f0e206f19b94993d to your computer and use it in GitHub Desktop.
Emacs config
(setq-default indent-tabs-mode nil)
(setq column-number-mode t)
(custom-set-variables
'(js2-global-externs (quote ("goog"))))
(add-hook 'js2-post-parse-callbacks
(lambda ()
(let ((buf (buffer-string))
(index 0))
(while (string-match "\\(goog\\.require\\|goog\\.provide\\)('\\([^'.]*\\)" buf index)
(setq index (+ 1 (match-end 0)))
(add-to-list 'js2-additional-externs (match-string 2 buf))))))
(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))
))))
(add-hook 'after-save-hook
(lambda()
(if (string-match "BUILD" (file-name-base (buffer-file-name)))
(progn
(shell-command (concat "/home/k/buildifier/bazel-bin/buildifier/buildifier " (buffer-file-name)))
(find-alternate-file (buffer-file-name))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment