Python 当文件不';我没有.py扩展名

Python 当文件不';我没有.py扩展名,python,emacs,lisp,flymake,pyflakes,Python,Emacs,Lisp,Flymake,Pyflakes,我根本不是一个lisp人,但我的主要脚本环境是emacs,我需要一些帮助,以便在文件上没有.py扩展名时运行我的flymake/pyflakes。因为我工作中的一些脚本没有.py扩展名 当我读取/编码一个扩展名为.py的文件时,使用pylint、pep8、pychecker等非常有效 ;; flymake for python (add-to-list 'load-path "~/.emacs.d/plugins/flymake") (when (load "flymake" t) (de

我根本不是一个lisp人,但我的主要脚本环境是emacs,我需要一些帮助,以便在文件上没有.py扩展名时运行我的flymake/pyflakes。因为我工作中的一些脚本没有.py扩展名

当我读取/编码一个扩展名为.py的文件时,使用pylint、pep8、pychecker等非常有效

;; flymake for python
(add-to-list 'load-path "~/.emacs.d/plugins/flymake")

(when (load "flymake" t)
  (defun flymake-pylint-init (&optional trigger-type)
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-with-folder-structure))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name)))
           (options (when trigger-type (list "--trigger-type" trigger-type))))
      (list "~/.emacs.d/plugins/flymake/pyflymake.py" (append options (list local-file)))))
  (add-to-list 'flymake-allowed-file-name-masks
               '("\\.py\\'" flymake-pylint-init)))

(add-hook 'find-file-hook 'flymake-find-file-hook)

;; flymake help on minibuffer
(defun my-flymake-show-help ()
  (when (get-char-property (point) 'flymake-overlay)
   (let ((help (get-char-property (point) 'help-echo)))
    (if help (message "%s" help)))))

(add-hook 'post-command-hook 'my-flymake-show-help)
我已经尝试在没有.py扩展名的情况下获取这个正在工作的init代码段。我用python模式钩子包装了上面的代码,并将\.py\部分更改为\.*\

然而,这不仅仅是为python文件调用flymake pylint init函数。它称之为emacs中打开的任何东西

顺便说一句,我不能在没有扩展名文件的情况下使用m-x flymake模式,它不能打开次要模式


我很想知道如何让它工作。谢谢

AFAIU结束仅对自动检测所需的缓冲区模式很重要。
您可以显式地调用模式resp。任何文件的交互式M-x python模式。

让我首先说,下面的代码通常不是解决Emacs问题的方法。我要做的是加载flymake,然后在其中一个核心函数上跺脚。由于flymake的编写方式,我无法找到一种方法来连接函数,甚至无法使用advice。如果flymake改变了这个函数或者它的调用方式,它将不再工作。也就是说,多年来它一直在为我工作:)

这是基本代码:

(require 'flymake)

(defun flymake-get-file-name-mode-and-masks (file-name)
  "Return the corresponding entry from `flymake-allowed-file-name-masks'."
  (unless (stringp file-name)
    (error "Invalid file-name"))
  (let ((fnm flymake-allowed-file-name-masks)
        (mode-and-masks nil)
        (matcher nil))
    (while (and (not mode-and-masks) fnm)
      (setq matcher (car (car fnm)))
      (if (or (and (stringp matcher) (string-match matcher file-name))
              (and (symbolp matcher) (equal matcher major-mode)))
          (setq mode-and-masks (cdr (car fnm))))
      (setq fnm (cdr fnm)))
    (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks))
    mode-and-masks))
然后从上面的代码,而不是这个:

(add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pylint-init))
这样做:

(add-to-list 'flymake-allowed-file-name-masks '(python-mode flymake-pylint-init))

您也可以对Perl等进行同样的操作。

如果您不介意我问的话,为什么不将文件扩展名设为.py?甚至可以将内容临时复制到.py缓冲区。您好,先生,谢谢您花时间。然而,这对我不起作用,(它甚至不起作用。py文件)我的配置文件看起来像这样;我正在运行
emacs24.2.1
,我安装了flymake的分叉版本,从这里开始让它与tramp一起工作;我错过什么了吗?再次感谢。请尝试摆脱
(当(加载“flymake”t)
行(以及相应的结束参数),或者将我给你的代码移到里面。我一直得到
错误的类型参数:stringp,python mode
minibuffer上的错误。顺便说一句,我发现你在这里提供的基本代码已经在我的flymake.el文件中。不,不是。正如我上面所说的,我正在用这个函数覆盖其中一个flymake.el函数。你的问题是我的函数不太可能先加载,然后被原始函数覆盖。请确保此代码位于最后。