flymake 和 python-execute-region
我在使用py-execute-region(绑定到C-c |)时,收到了来自flymake-get-file-name-mode-and-masks的错误提示“无效的文件名”。同时,出现了一个名为/tmp/python-3434.py的空缓冲区。
我的flymake设置如下:
(when (load "flymake" t)
(defun flymake-pylint-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 "epylint" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks '("\.py\'" flymake-pylint-init))) (add-hook 'python-mode-hook 'flymake-mode)
1 个回答
4
我也遇到过同样的问题,我通过让emacs不为传递给解释器的临时缓冲区加载flymake来解决这个问题。
这是我在Python中使用flymake的相关设置:
(when (load "flymake" t)
(defun flymake-python-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 "pyflymake" (list local-file)))) ; substitute epylint for this
(push '(".+\\.py$" flymake-python-init) flymake-allowed-file-name-masks))
(add-hook 'python-mode-hook
(lambda ()
; Activate flymake unless buffer is a tmp buffer for the interpreter
(unless (eq buffer-file-name nil) (flymake-mode t)) ; this should fix your problem
;; Bind a few keys for navigating errors
(local-set-key (kbd "C-c w") 'show-fly-err-at-point) ; remove these if you want
(local-set-key (kbd "M-n") 'flymake-goto-next-error)
(local-set-key (kbd "M-p") 'flymake-goto-prev-error)))