2017-05-25 70 views
0

如何使用align emacs命令對齊如下結構的文件?使用emacs對齊「鍵值註釋」文件類型

key.name1 "his value 1"; # the comment 
key.name2  "his other value"; 
otherkey.id 10; # comment 
key.without.other ; # comment 
key2.without.other true;    # comment 

我使用conf-mode下的emacs 25.

的列編碼如下:

  • 第一列(密鑰)是沒有空格的字符串,
  • 第二列(值)到達分號,
  • 第三列(註釋)並非總是存在,並以#開頭「

結果應該是

key.name1   "his value 1";  # the comment 
key.name2   "his other value"; 
otherkey.id  10;    # comment 
key.without.other ;     # comment 
key2.without.other true;    # comment 

回答

1

這將是最好的,如果你能描述你希望如何看到這種對齊。

通過選擇這些行並使用前綴參數運行align-regexp,我可以使用以下正則表達式通過查找多個連續空格來對齊所有這些字段。這可能不是最好的解決方案,但它適用於此示例數據。

C-ùM-Xalign-regexpRET\(\s-\s-+\)RETRETRETý

結果:

key.name1 "his value 1"  # the comment 
key.name2 "his other value" # another comment 
otherkey.id 10    # comment 
+0

感謝您的建議。我編輯了更具體的問題 –