5

以下是我init.el与 Flymake 相关的片段:

(add-hook 'python-mode-hook 
      (lambda () 
        (unless (eq buffer-file-name nil) (flymake-mode 1)) ;dont invoke flymake on temporary buffers for the interpreter
        (local-set-key [f2] 'flymake-goto-prev-error)
        (local-set-key [f3] 'flymake-goto-next-error)
        (local-set-key [f4] 'flymake-display-err-menu-for-current-line)
        (hs-minor-mode)
        (orgtbl-mode)
        (outline-minor-mode -1)))

...

;;===== PyFlakes
;; code checking via pyflakes+flymake
(when (load "flymake" t)
  (defun flymake-pyflakes-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
               'flymake-create-temp-inplace))
       (local-file (file-relative-name
            temp-file
            (file-name-directory buffer-file-name))))
      (list "pychecker" (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
           '("\\.py\\'" flymake-pyflakes-init)))

(mapcar (lambda (hook) (add-hook 'find-file-hook hook))
    (list 'flymake-find-file-hook))

(unload-feature 'flymake) ; unloaded in an attempt to get rid of the error

但是每次我find-filerevert-buffer(extensions .xml, .php, .html) 我都会收到以下错误(不是.py):

Flymake:无法使用 args 启动语法检查进程“php”(-f _posteddata_flymake.php -l):搜索程序:权限被拒绝,php。Flymake 将关闭

或者

Flymake:无法使用 args 启动语法检查过程“xml”(val //path/to/file/config/prod-conf_flymake.xml):搜索程序:权限被拒绝,xml。Flymake 将关闭

我也试过做(load "flymake" nil),但也没有用。

打开或重新加载大量文件时会花费大量时间。

我该如何解决?

4

2 回答 2

3

只是不要将 Flymake 添加到find-file-hook. 而是仅将其添加到主要模式的挂钩中,您想在其中使用它。

您可能还想查看替代的Flycheck包,它可以更安全地在全球范围内启用,支持更多语言,并且需要更少的定制。免责声明:我是这个包的作者。

于 2013-12-26T18:48:39.693 回答
3

我最终遇到了这个问题,试图在默认调用的 python-mode / elpy 中禁用 flymake。它并不完美,但它有效,所以我只是发布它,以防它对最终遇到同样问题的其他人有所帮助。

假设您在配置中使用“use-package”,并且您想用 flycheck 替换 flymake,要启用 flycheck,您只需将以下内容添加到您的配置中:

(use-package flycheck
  :ensure t
  :init
  (global-flycheck-mode t))

然后添加elpy和python模式,代码如下:

(use-package python
  :mode ("\\.py" . python-mode)
  :ensure t
  :config
  (flymake-mode) ;; <- This line makes the trick of disabling flymake in python mode!
  (use-package elpy
    :ensure t
    :init
    (add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
    :config
    (remove-hook 'elpy-modules 'elpy-module-flymake) ;; <- This removes flymake from elpy
    (setq elpy-rpc-backend "jedi")
    :bind (:map elpy-mode-map
              ("M-." . elpy-goto-definition)
              ("M-," . pop-tag-mark))
  )
  (elpy-enable)
)

每次您处于 python-mode / 编辑 python 文件时,上面的代码都会启用 elpy 模式。问题是python模式在加载时会自动启用flymake,然后elpy正在加载flycheck。因此,您将同时运行两个检查器。

flymake-mode我提出的解决方案是在加载 python 模式后再次调用,从而禁用它。这可能也适用于其他模式/案例。

我知道“正确”的解决方案是找到一种在加载 python 模式时根本不加载 flymake 的方法,但在我设法做到这一点之前,这应该就足够了。

于 2018-10-25T08:20:02.563 回答