我一直在尝试从 emacs 开始进行基于 node.js 的项目开发。
我无法为此设置我的emacs。它更像是一种反复试验的黑匣子,导致挫败感。你能帮我设置一下吗:
我安装了插件M-x package-install
我的 emacs 文件如下所示:
;; added for javascript -------
; Use dictionaries by default
(setq-default ac-sources (add-to-list 'ac-sources 'ac-source-dictionary))
(global-auto-complete-mode t)
; Start auto-completion after 2 characters of a word
(setq ac-auto-start 2)
; case sensitivity is important when finding matches
(setq ac-ignore-case nil)
(require 'yasnippet)
;; now enable the yasnippet for snippets
(yas-global-mode 1)
;; set the snippets directory
(setq yas-snippet-dirs
'( "~/.emacs.d/plugins_old/yasnippet/yasmate/snippets" ;; the yasmate collection
"~/.emacs.d/plugins_old/yasnippet/snippets" ;; the snippet collection
"~/.emacs.d/elpa/yasnippet/snippets" ;; the default collection
))
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")
;; (define-key yas-minor-mode-map (kbd "TAB") 'yas-expand)
;; (define-key yas-minor-mode-map (kbd "<tab>") 'yas-expand)
;; (setq yas-trigger-key "")
;; (setq yas-next-field-key "")
;; (setq yas-prev-field-key "")
;; Let's have snippets in the auto-complete dropdown
(add-to-list 'ac-sources 'ac-source-yasnippet)
;; adding lint node
;; (add-to-list 'load-path "~/.emacs.d/plugins_old/lintnode")
;; finally followed this : http://www.emacswiki.org/emacs/FlymakeJavaScript to install jslint in emacs
(require 'flymake-jslint)
(add-hook 'js-mode-hook 'flymake-jslint-load)
;; Make sure we can find the lintnode executable
;; (setq lintnode-location "~/.emacs.d/plugins_old/lintnode")
;; JSLint can be... opinionated
;; (setq lintnode-jslint-excludes (list 'nomen 'undef 'plusplus 'onevar 'white))
;; Start the server when we first open a js file and start checking
;; (add-hook 'js-mode-hook
;; (lambda ()
;; (lintnode-hook)))
;; added red cursor for wrong lint node errors
(require 'flymake-cursor)
;; fold the functions
( add-hook 'js-mode-hook
(lambda ()
;; Scan the file for nested code blocks
(imenu-add-menubar-index)
;; Activate the folding mode
(hs-minor-mode t)))
;; Show-hide
(global-set-key (kbd "") 'hs-show-block)
(global-set-key (kbd "") 'hs-show-all)
(global-set-key (kbd "") 'hs-hide-block)
(global-set-key (kbd "") 'hs-hide-all)
;; repl for javascript
(require 'js-comint)
;; Use node as our repl
(setq inferior-js-program-command "node")
(setq inferior-js-mode-hook
(lambda ()
;; We like nice colors
(ansi-color-for-comint-mode-on)
;; Deal with some prompt nonsense
(add-to-list 'comint-preoutput-filter-functions
(lambda (output)
(replace-regexp-in-string ".*1G\.\.\..*5G" "..."
(replace-regexp-in-string ".*1G.*3G" ">" output))))))
;; -----------------------------
这是我最近添加的用于设置环境的部分;您可能会看到很多注释代码,表明我在任何地方都尝试过这个或那个。我主要关注的是:deadpansincerity,然后最近尝试使用turnongtx
我最想要的是 yasnippet 和 jslint 的自动完成功能吗?其他功能可以是插件,但我只在这些方面挣扎了两天。
我的 emacs 版本是 24.3.1,其中很多东西都会中断。
我观察到,经过 1 天的完整试验和错误,yasnippet 开始工作,但在重新启动 emacs 后它无法正常工作。这意味着我可能在该 emacs 会话期间通过重新加载 .emacs 文件做了一些正确的事情。但我又不知道在哪里发生了什么。
当我打开任何 js 文件并写入if
并点击时,TAB
什么也没有发生。
另外,M-x yas-expand
写完之后if
没有任何反应。但是消息确实来了You can run the command "yas-expand" with TAB
,但这有时也会发生。
我记得在某个时间点,做上述任何事情都会显示昨天的 if-expanded。
好消息是我的 jslint 正在工作。我使用 npm 安装它并添加了 flymake。:) 我也可以使用 comint nodejs repl :)
任何帮助,将不胜感激。
我完整的 emacs 文件在这里我的 emacs