首页 > 解决方案 > 如何在 emacs 27 中为外部命令设置别名

问题描述

我试图让 Emacs 27 为 javascript + flow 工作。有很多步骤/包/配置可以让它工作。

我目前坚持的一个特定步骤。

我无法全局安装 npm 包(因为我们的 monorepo 为 repo 中的不同应用程序使用不同版本的 node_module 包)。所以我们不能用 npm -g 安装 flow、typescript 和其他东西,而是需要将 emacs 指向 ./node_modules/.bin/flow (例如)。

这是我在启动 emacs 时收到的具体错误消息

Command "javascript-typescript-stdio" is not present on the path.                                                                      
Command "typescript-language-server --stdio" is not present on the path.                                                               
Command "flow lsp" is not present on the path. 

所以,如果可能的话,我想在我的 .emacs javacript-typescript-stdio typescript-language-server 流中定义

这样他们将指向 /node_modules/.bin/ 哪里是我启动 emacs 的目录

当搜索这个主题时,大多数查询都返回了一些关于别名内部 emacs 函数的内容,但这不是我想要的。

我的 .emacs 部分与此相关:

;; lsp-javascript specific start
;; https://github.com/emacs-lsp/lsp-mode/issues/489
(use-package js2-mode
  :mode "\\.js\\'"
  :init
  (add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
  (setf js2-mode-indent-inhibit-undo t)
  :config
  (with-eval-after-load "lsp-javascript-typescript"
    (add-hook 'js2-mode-hook #'lsp)))


;; for flow start
(add-hook 'js2-mode-hook 'flow-minor-enable-automatically)
;; for flow end 


;; JSON
(use-package json-mode
  :defer t)

标签: emacs

解决方案


exec-path保存位置以搜索可执行文件,因此在那里添加一个条目应该可以工作,

(add-to-list 'exec-path "./node_modules/.bin")

在这种情况下,路径是相对于default-directory,见。


推荐阅读