emacs写js的时候不会提示dom相关的操作方法.

就是一个小小的配置,为什么会讨论这么久。把下边代码保存到 /path/to/test-tern.el 然后按照 Usage 跑起来:

;;; Usage:
;;;
;;;     mkdir /path/to/testdir/
;;;     cd /path/to/testdir/
;;;     /path/to/emacs -nw -Q -l /path/to/test-tern.el
;;;
(toggle-debug-on-error)
(setq package-user-dir (format "%s/elpa--test-tern/%s" user-emacs-directory emacs-version))
(setq package-archives
      '(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
        ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/"))) ;; For China mainland
      ;; '(("gnu" . "http://elpa.emacs-china.org/gnu/")
      ;;   ("melpa" . "https://melpa.org/packages/")))

(package-initialize)

(defmacro try-install (pkg)
  `(unless (package-installed-p ,pkg)
     (package-refresh-contents)
     (package-install ,pkg)))

(try-install 'tern)
(try-install 'company)
(try-install 'company-tern)

;; ------------------------------------------------------------------

(add-hook 'after-init-hook
          '(lambda ()
             (let ((value (find-file-noselect "test.js" nil nil nil)))
               (if (listp value)
                   (mapcar 'switch-to-buffer (nreverse value))
                 (switch-to-buffer value)))
             (company-mode 1)
             (tern-mode 1)
             (insert "// Press `M-x company-tern` to complete\n")
             (insert "document.get")
             ))

(run-hooks 'after-init-hook)
;;; test-tern.el ends here