【问题标题】:Making flymake work with Django?让 flymake 与 Django 一起工作?
【发布时间】:2012-02-22 07:07:38
【问题描述】:

我在处理 Django 模板时如何禁用 flymake?

Flymake 非常适合编辑 python 文件,但确实给我带来了 django 模板的问题。例如,以下模板不会引发错误,尽管语法突出显示不适用于模板标签:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>{% block title %}Page title{% endblock %}</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>

<body>
{% block content %}
  <p>… Your HTML content here …</p>
{% endblock %}
</body>
</html>

但是,以下模板充满了针对 flymake 错误的字体锁定:

{% extends base.html %}

{% block content %}
<h1>Welcome!</h1>
{% endblock %}

将鼠标悬停在错误上显示 flymake 正在抱怨“不允许文本”。

我已经关注了this related question 中的每个解决方案,但它们都没有为 html 缓冲区禁用 flymake。我什至尝试将所有模板文件重命名为以.djhtml 而不是.html 结尾,但重新访问文件后flymake 仍然处于活动状态。我确实更改了自动模式列表以将django-html-mode 应用于.djhtml 文件,所以问题可能就在那里。

更新:我发现切换到html-mode 没有这个问题,因为我已经实现了前面提到的解决方案。但是,如果我切换到 nxml-modedjango-html-mode(我想使用),flymake 会再次启动并告诉我它是:

Using schema /usr/local/Cellar/emacs/HEAD/share/emacs/24.0.93/etc/schema/xhtml.rnc

雪豹上的 Emacs24 Carbon。

GNU Emacs 24.0.93.1 (i386-apple-darwin10.8.0, NS apple-appkit-1038.36) of 2012-02-21 on hook

【问题讨论】:

    标签: html django macos emacs flymake


    【解决方案1】:

    django wiki 列出了使用 emacs 的几个选项,但并未就每种模式的特定优缺点提供大量指导。

    我目前使用的解决方法是使用django-html-mumamo-mode 而不是django-mode。这是我在使用 django 设置 emacs 的过程中发现的。

    请记住,随着这些软件包的开发,其中一些观察结果可能会发生变化。

    小马模式

    Looks promising,但文档不完整,模板中的语法突出显示对我不起作用。这是我真正追求的,但其他人可能会喜欢内置的其他功能。

    django-html-mumamo-mode

    这与nXhtml 捆绑在一起。没有包含任何 sn-ps,但可以使用 Google 找到 sn-ps,或使用 yasn-p 找到 imported from a Textmate bundle。说起来,这个模式conflicts with the yasnippet-bundle是通过ELPA提供的,所以一定要遵循开发主干,避免不得不restart emacs everytime you trigger a snippet。顺便说一句,语法高亮很棒,您可能会喜欢作为 nXhtml 一部分的通用 Web 开发功能。

    django 模式

    语法高亮和跳转到标签,包括一些sn-ps;但是,django-modedoesn't play nice with flymake,我认为这是因为它源自nxml-modedjango-mode 不再处于开发阶段,nxml-mode 也不是我能收集到的。 django-html-mumamo-mode 不会遇到这个 flymake 问题,因为 nXhtml 包含对开箱即用的 flymake 的非常好的支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      • 2023-01-16
      • 2014-05-15
      • 2018-01-26
      • 2017-09-19
      • 2017-05-08
      • 2011-04-02
      相关资源
      最近更新 更多