init-js-two.el 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ;;; init-js-two.el --- .Emacs Configuration -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;;; JavaScript configuration - IDE
  4. ;;; Code:
  5. ;; js2-mode: enhanced JavaScript editing mode
  6. ;; https://github.com/mooz/js2-mode
  7. (use-package js2-mode
  8. :ensure t
  9. :defer 20
  10. :hook ((js2-mode . (lambda ()
  11. (company-mode))))
  12. :mode (("\\.js\\'" . js2-mode))
  13. :custom
  14. (js2-include-node-externs t)
  15. (js2-global-externs '("customElements"))
  16. (js2-highlight-level 3)
  17. (js2r-prefer-let-over-var t)
  18. (js2r-prefered-quote-type 2)
  19. (js-indent-align-list-continuation t)
  20. (global-auto-highlight-symbol-mode t)
  21. ;; use eslint_d insetad of eslint for faster linting
  22. (flycheck-javascript-eslint-executable "eslint_d")
  23. :config
  24. (setq js-indent-level 2)
  25. ;; patch in basic private field support
  26. (advice-add #'js2-identifier-start-p
  27. :after-until
  28. (lambda (c) (eq c ?#))))
  29. ;; js2-refactor: refactoring options for emacs
  30. ;; https://github.com/magnars/js2-refactor.el
  31. (use-package js2-refactor
  32. :pin "MELPA"
  33. :after js2-mode
  34. :bind
  35. (:map js2-mode-map
  36. ("C-k" . js2r-kill)
  37. ("C-c h r" . js2-refactor-hydra/body))
  38. :hook ((js2-mode . js2-refactor-mode))
  39. :config (js2r-add-keybindings-with-prefix "C-c C-r")
  40. (defhydra js2-refactor-hydra (:color blue :hint nil)
  41. "
  42. ^Functions^ ^Variables^ ^Buffer^ ^sexp^ ^Debugging^
  43. ------------------------------------------------------------------------------------------------------------------------------
  44. [_lp_] Localize Parameter [_ev_] Extract variable [_wi_] Wrap buffer in IIFE [_k_] js2 kill [_lt_] log this
  45. [_ef_] Extract function [_iv_] Inline variable [_ig_] Inject global in IIFE [_ss_] split string [_dt_] debug this
  46. [_ip_] Introduce parameter [_rv_] Rename variable [_ee_] Expand node at point [_sl_] forward slurp
  47. [_em_] Extract method [_vt_] Var to this [_cc_] Contract node at point [_ba_] forward barf
  48. [_ao_] Arguments to object [_sv_] Split var decl. [_uw_] unwrap
  49. [_tf_] Toggle fun exp and decl [_ag_] Add var to globals
  50. [_ta_] Toggle fun expr and => [_ti_] Ternary to if
  51. [_q_] quit"
  52. ("ee" js2r-expand-node-at-point)
  53. ("cc" js2r-contract-node-at-point)
  54. ("ef" js2r-extract-function)
  55. ("em" js2r-extract-method)
  56. ("tf" js2r-toggle-function-expression-and-declaration)
  57. ("ta" js2r-toggle-arrow-function-and-expression)
  58. ("ip" js2r-introduce-parameter)
  59. ("lp" js2r-localize-parameter)
  60. ("wi" js2r-wrap-buffer-in-iife)
  61. ("ig" js2r-inject-global-in-iife)
  62. ("ag" js2r-add-to-globals-annotation)
  63. ("ev" js2r-extract-var)
  64. ("iv" js2r-inline-var)
  65. ("rv" js2r-rename-var)
  66. ("vt" js2r-var-to-this)
  67. ("ao" js2r-arguments-to-object)
  68. ("ti" js2r-ternary-to-if)
  69. ("sv" js2r-split-var-declaration)
  70. ("ss" js2r-split-string)
  71. ("uw" js2r-unwrap)
  72. ("lt" js2r-log-this)
  73. ("dt" js2r-debug-this)
  74. ("sl" js2r-forward-slurp)
  75. ("ba" js2r-forward-barf)
  76. ("k" js2r-kill)
  77. ("q" nil)))
  78. ;; json-mode: Major mode for editing JSON files with emacs
  79. ;; https://github.com/joshwnj/json-mode
  80. (use-package prettier-js
  81. :pin "MELPA")
  82. (use-package json-mode
  83. :pin "MELPA"
  84. :ensure t
  85. :defer 20
  86. :custom
  87. (json-reformat:indent-width 2)
  88. (json-reformat:pretty-string? t)
  89. (js-indent-level 2)
  90. :mode "\\.js\\(?:on\\|[hl]int\\(rc\\)?\\)\\'"
  91. :hook ((json-mode . prettier-js-mode))
  92. :bind (:package json-mode-map
  93. :map json-mode-map
  94. ("C-c <tab>" . json-mode-beautify)))
  95. ;; eslintd-fix: Emacs minor-mode to automatically fix javascript with eslint_d.
  96. ;; https://github.com/aaronjensen/eslintd-fix/tree/master
  97. (use-package eslintd-fix)
  98. (provide 'init-js-two)
  99. ;; Local Variables:
  100. ;; byte-compile-warnings: (not free-vars)
  101. ;; End:
  102. ;;; init-js-two.el ends here