2

我正在尝试从 Haxe 编译器提供 flymake 输出,但我不知道如何告诉它 make 文件的位置(理想情况下,我会使用 nxml 文件)。到目前为止,我在 Makefile 中有这个:

BIN = ./bin
MAIN = com.wunderwafer.Main
SWF = wunderwafer.swf
SWFSETTINGS = -debug -swf-version 10 -swf-header 800:600:31
HFLAGS = -main $(MAIN) $(SWFSETTINGS) -cp ./src -swf $(BIN)/$(SWF)
HC = haxe

default: compile

compile: $(HC) $(HFLAGS)

clean:
    $(RM) -r $(BIN)/*

.PHONY: check-syntax

check-syntax:
    $(HC) $(HFLAGS)

如果我稍后像这样运行它:

$ make -k check-syntax

它产生预期的输出。然而,flymake 无法找到 Makefile(或者看起来如此),因为我试图检查的文件位于 src 目录的更深处。

配置flymake的方法是什么让它知道makefile在哪里?(或者,更好的是,只执行一个 shell 命令,因为编译 Haxe 代码的常用方法是使用 *.nxml 设置文件。

编辑:

看起来我越来越近了,非常感谢,但是 flymake 正在做一些奇怪的事情,我不明白它到底做了什么,所以,这里是日志:

received 65 byte(s) of output from process 967
file /home/wvxvw/projects/wafer/src/com/wunderwafer/map/Battlefield.hx, init=haxe-flymake-init
parsed 'Error : Invalid class name /home/wvxvw/projects/wafer/build.nxml', no line-err-info
file /home/wvxvw/projects/wafer/src/com/wunderwafer/map/Battlefield.hx, init=haxe-flymake-init
process 967 exited with code 1
cleaning up using haxe-flymake-cleanup
deleted file /tmp/flymake-Battlefield-855Cad.hx
Battlefield.hx: 0 error(s), 0 warning(s) in 0.15 second(s)
switched OFF Flymake mode for buffer Battlefield.hx due to fatal status CFGERR, warning Configuration error has occurred while running (haxe /home/wvxvw/projects/wafer/build.nxml)

我试图让它运行的命令如下所示:

(defun haxe-flymake-get-cmdline (source base-dir)
  "Gets the cmd line for running a flymake session in a Haxe buffer.
This gets called by flymake itself. The output is a list of two elements:
the command to run, and a list of arguments.  The resulting command is like:

  $ haxe ${project-root}/build.nxml

"
  (message "base-dir %s" (file-name-as-directory base-dir))
  (list *haxe-compiler*
        (list
     (concat (file-name-as-directory base-dir)
         *build-nxml*))))

打印的消息如下所示:

base-dir /home/wvxvw/projects/wafer/

因此,据我所知,生成的命令应该是:

haxe /home/wvxvw/projects/wafer/build.nxml

但是看起来 flymake 要么在参数之前或之后添加了一些东西,这使得 Haxe 编译器生成错误“错误:无效的类名” - 如果有一个额外的参数,编译器会理解为这个错误会给出一个额外的类来编译。但是日志没有显示正在发送的内容......

编辑2:

我已经添加:

#!/usr/bin/env bash

echo "$@" > /home/wvxvw/projects/wafer/log

并让flymake调用这个脚本而不是编译器,它只传递一个参数,正如我所期望的那样......叹息

4

1 回答 1

1

这是个好问题。我不知道在flymake中添加新的制作工具“风味”的简单方法。我知道一种方法,它并不简单。这就是我为 php codesniffer 所做的 - 对于任何任意的 make 工具都是类似的。

首先,定义一个安装 fn。

(defun fly/phpcs-install ()
  "install flymake stuff for PHP CodeSniffer files."
  (add-to-list
   'flymake-err-line-patterns
   (list fly/phpcs-error-pattern 1 2 3 4))

  (let* ((key "\\.php\\'")
         (phpentry (assoc key flymake-allowed-file-name-masks)))
    (if phpentry
        (setcdr phpentry '(fly/phpcs-init fly/phpcs-cleanup))
      (add-to-list
       'flymake-allowed-file-name-masks
       (list key 'fly/phpcs-init 'fly/phpcs-cleanup)))))

这会在 flymake alist 中安装一个新条目,键入 .php 作为文件扩展名。flymake 列表中的条目基本上将文件扩展名与一对函数相关联,一个用于初始化,一个用于清理。

init fn 只是返回要运行以检查语法的命令。这可以是一个带有适当参数的 shell 命令。对于codesniffer,这个fn看起来像这样:

(defun fly/phpcs-init ()
  "initialize flymake for PHP using the PHP CodeSniffer tool."
  (let ((create-temp-f 'fly/phpcs-create-temp-intemp)
        (use-relative-base-dir t)
        (use-relative-source t)
        (get-cmdline-f 'fly/phpcs-get-cmdline)
        args
        temp-source-file-name)
    (setq temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f)
          args (flymake-get-syntax-check-program-args
                temp-source-file-name "."
                use-relative-base-dir use-relative-source
                get-cmdline-f))
    args))

哎呀!我们去兔子洞。get-cmdline fn 如下所示:

(defun fly/phpcs-get-cmdline (source base-dir)
  "Gets the cmd line for running a flymake session in a PHP buffer.
This gets called by flymake itself. The output is a list of two elements:
the command to run, and a list of arguments.  The resulting command is like:

  php.exe -d auto_append_file="" -d auto_prepend_file="" phpcs\scripts\phpcs --report=emacs file.php

"
  (list fly/phpcs-phpexe
        (list
         "-d" "auto_append_file=''"
         "-d" "auto_prepend_file=''"
         (concat (file-name-as-directory fly/phpcs-phpcs-dir)
                 "scripts\\phpcs")
         (concat "--standard="  fly/phpcs-standard)
         "--report=emacs"
         "-s" ;; show the fullname of the rule being violated
         (expand-file-name source))))

您可以在http://www.emacswiki.org/emacs/flyphpcs.el看到完整的 elisp

可能有更简单的方法。我只是不知道。

于 2012-06-13T16:24:11.200 回答