[英]How to complete disable flymake and all the things it is hooked to?
以下是我的init.el
與init.el
相關的片段:
(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-file
或revert-buffer
(擴展名.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)
但它也沒有用。
打開或重新加載大塊文件時,很長一段時間。
我該如何解決?
只是不要將Flymake添加到find-file-hook
。 而只是將它添加到主要模式的鈎子中,你想要使用它。
您可能還想查看替代Flycheck軟件包,它可以更安全地在全球范圍內啟用,支持更多語言,並且需要更少的自定義。 免責聲明:我是這個包的作者。
我最終在這個問題中嘗試禁用默認調用的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 / editing python文件時,上面的代碼都會啟用elpy模式。 問題是python模式在加載時自動啟用flymake,然后elpy正在加載flycheck。 所以你有兩個跳棋運行。
我提出的解決方案是在加載python模式后再次調用flymake-mode
mode,從而禁用它。 這可能也適用於其他模式/案例。
我知道一個“正確的”解決方案是在加載python-mode時找到一種不加載flymake的方法,但是直到我設法做到這一點,這應該足夠了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.