2011-12-13 81 views
0

由於您使用GNU/Emacs進行Android開發的一些人,您一定知道最新的Android工具引入了new xml formatter。我用的是優秀nxml模式編輯XML,因爲......我編輯XML文件)和我很高興,但...我可以自定義Nxml屬性縮進變量,該文件說:自定義GNU/Emacs 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模式壓痕行爲):

  • manifest元件的package屬性與xmlns:android decl
  • 的對準元素的屬性Bar activity元素與android:name元素對齊。

第二種情況(預期的結果):

  • manifest元件的package屬性與父manifest元件加的空間可配置數量的對準
  • Bar activity元件的android:label屬性是與父元素對齊,加上可配置的空格數

I ha我瀏覽了nxml模式的源代碼,並且縮進行爲以nxml-indent-line開頭,但由於我缺少lisp知識,我未能遵循許多subcalls來查看應該自定義什麼defun ...。

你可以看到manifest秒屬性不與第一

乾杯對齊,

雷諾(很難管理大量的頭痛與Android編碼和格式規則,以符合)

+0

你能展示一些XML例子嗎?我不明白你的意思是「當第一個屬性與元素位於同一行時,獨立屬性與第一個屬性對齊的回退」。 – mzjn 2011-12-14 11:24:10

+0

使用XML片段更新的問題;)對不起,我應該先把它們放在... – Renaud 2011-12-14 12:28:20

回答

1

沒有按看起來這種行爲很容易修改,因爲它似乎被硬編碼到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 emacs維護人員提交增強請求,以便將來可以輕鬆定製此行爲。