正如你们中一些使用GNU/Emacs为Android开发的人一样,你们肯定知道最新的安卓工具引入了新xml格式化程序。我使用优秀的nxml模式编辑xml,因为…。我编辑xml文件;)而且我对它非常满意,但是…由于我可以自定义Nxml属性缩进变量,文档指出:
Indentation for the attributes of an element relative to the start-tag. Hide
This only applies when the first attribute of a tag starts a line.
In other cases, the first attribute on one line is indented the same
as the first attribute on the previous line.重要的是,当该属性位于元素的同一行时,独立属性在第一个属性上对齐的回退。
这是否有可能改变这种行为,以获得兼容Android工具的缩进?我只是在文档中什么都没找到,谷歌失败的…
更新:
这个评论帮助我意识到我不清楚。因此,下面是一个默认情况下nxml模式所做工作的示例:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.foo.bar"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<activity
android:name="Foo"
android:label="@string/foo" />
<activity android:name="Bar"
android:label="@string/bar" />
</application>
</manifest>我想要的是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.foo.bar"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<activity
android:name="Foo"
android:label="@string/foo" />
<activity android:name="Bar"
android:label="@string/bar" />
</application>
</manifest>第一种情况(默认的nxml模式缩进行为):
package元素的manifest属性与xmlns:android decl对齐android:label元素的Bar activity属性与android:name元素对齐。第二种情况(预期结果):
package元素的manifest属性与父manifest元素以及可配置的空格数对齐。android:label元素的Bar activity属性与父元素对齐,加上可配置的空格数。我浏览了nxml模式的源代码,缩进行为以nxml-indent-line开头,但是我没有按照许多子调用来查看应该定制什么defun。因为我缺乏lisp知识。
可以看到,manifest第二个属性与第一个属性没有对齐。
干杯,
Renaud (为了符合Android的编码和格式规则,很难解决这个大麻烦)
发布于 2011-12-14 15:31:44
这种行为看起来并不容易修改,因为它似乎是硬编码到nxml-compute-indent-in-start-tag函数中。相关的代码块似乎如下:
(let* ((att (car atts))
(start (xmltok-attribute-name-start att)))
(when (< start pos)
(goto-char start)
(setq off 0))))您可以始终将该方法复制到您自己的init文件中,对这些行进行注释,并在nxml模式加载后加载函数定义(这将覆盖原始实现)。
注意,您还可能希望向gnu维护人员提交一个增强请求,以使此行为在将来易于定制。
https://stackoverflow.com/questions/8494238
复制相似问题