Created
February 23, 2019 17:50
-
-
Save sjfricke/4b94ab7070e2decf285b96ed8312cbac to your computer and use it in GitHub Desktop.
Emacs setup for JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ## Packages to Install ## | |
;; js2-mode | |
;; js2-refactor | |
;; xref-js2 | |
;; sudo npm install -g tern | |
;; company-tern | |
(require 'package) | |
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos)) | |
(not (gnutls-available-p)))) | |
(proto (if no-ssl "http" "https"))) | |
(when no-ssl | |
(warn "\ | |
Your version of Emacs does not support SSL connections, | |
which is unsafe because it allows man-in-the-middle attacks. | |
There are two things you can do about this warning: | |
1. Install an Emacs version that does support SSL and be safe. | |
2. Remove this warning from your init file so you won't see it again.")) | |
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired | |
;;(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t) | |
(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t) | |
(when (< emacs-major-version 24) | |
;; For important compatibility libraries like cl-lib | |
(add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/"))))) | |
(package-initialize) | |
(custom-set-variables | |
(require 'js2-refactor) | |
(require 'xref-js2) | |
(add-hook 'js2-mode-hook #'js2-refactor-mode) | |
(js2r-add-keybindings-with-prefix "C-c C-r") | |
(define-key js2-mode-map (kbd "C-k") #'js2r-kill) | |
;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so | |
;; unbind it. | |
(define-key js-mode-map (kbd "M-.") nil) | |
(add-hook 'js2-mode-hook (lambda () | |
(add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))) | |
(require 'company) | |
(require 'company-tern) | |
(add-to-list 'company-backends 'company-tern) | |
(add-hook 'js2-mode-hook (lambda () | |
(tern-mode) | |
(company-mode))) | |
;; Disable completion keybindings, as we use xref-js2 instead | |
(define-key tern-mode-keymap (kbd "M-.") nil) | |
(define-key tern-mode-keymap (kbd "M-,") nil) | |
;; custom-set-variables was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
'(package-selected-packages (quote (company-tern xref-js2 js2-refactor)))) | |
(custom-set-faces | |
;; custom-set-faces was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
) | |
(require 'js2-mode) | |
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) | |
;; Better imenu | |
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment