【问题标题】:Flymake specify location of MakefileFlymake 指定 Makefile 的位置
【发布时间】:2012-06-13 16:14:53
【问题描述】:

我正在尝试从 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 调用这个脚本而不是编译器,它只传递一个参数,正如我所期望的那样...... sigh

【问题讨论】:

  • 你越来越近了。当您开始执行 sytntax 检查的操作系统进程以非零状态码退出时,flymake 会发生 CFGERR 事情。在这种情况下,它看起来像是以状态 1 退出。Flymake 认为这是一个错误,并随后停止尝试检查语法。如果您的语法检查在成功完成时返回非零值,但是当它发现语法错误时,您需要修复 flymake-process-sentinel 函数。同样,我不知道仅通过设置将其关闭的方法。有关这方面的示例,请参阅emacswiki.org/emacs/vbnet-mode.el
  • 另外,为了帮助排除故障,您可以(setq flymake-log-level 3),在随后运行 flymake 时,您将在 emacs 中的 Messages 缓冲区中看到语法检查程序的输出.

标签: emacs haxe flymake


【解决方案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查看完整的省略号

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    相关资源
    最近更新 更多