2014-10-20 29 views
0

我已經閱讀了關於align-regexp的emacs文檔,但仍然難以理解它的工作原理。我在說的是它的前綴形式是C-u M-x align-regexp,而不是簡單的形式M-x align-regexp。我的問題是:瞭解emacs align-regexp

  • 第一個參數(正則表達式)是否必須匹配整行字符串?如果正則表達式只匹配字符串的一部分會怎麼樣?
  • 什麼提供給第二個參數(要修改的括號組(如果是負數,則爲justify))?據我所知,我需要提供一個捕獲的組號碼(從1開始計數),對吧?如果我想讓第3組右對齊,我會提供-3作爲輸入嗎?
  • 第三個參數「間距量(或列負數)」是什麼意思?我完全不明白這個參數的作用。

我收集了一些文字示例來練習。如果任何人都可以使用下面的文字作爲例子,這將是非常有用的

class CreateStudents < ActiveRecord::Migration 
    def change 
    create_table :students, :comment => "學生信息表" do |t| 
     t.string :political_status, :comment => "政治面貌" 
     t.string :education_level, :comment => "培養層次" 
     t.string :enroll_method, :comment => "入學方式" 
     t.date :enrolled_at, :comment => "入學時間" 
     t.string :charge_type, :comment => "收費類別" 
     t.string :enrolled_year, :comment => "學籍年度" 
     t.string :enrolled_place, :comment => "生源所在地" 
     t.string :bank_card_number, :comment => "銀行卡號" 
     t.string :bank_account_number, :comment => "銀行賬號" 
     t.boolean :is_active_duty, :default => false, :comment => "是否現役軍人" 
     t.boolean :is_equivalent_degree, :default => false, :comment => "是否同等學歷" 
     t.boolean :is_on_record, :default => true, :comment => "是否在籍" 
     t.boolean :is_at_school, :default => true, :comment => "是否在校" 
     t.timestamps 
    end 
    end 
end 

class CreateStudents < ActiveRecord::Migration 
    def change 
    create_table :students, :comment => "學生信息表" do |t| 
     t.string :political_status,  :comment => "政治面貌" 
     t.string :education_level,  :comment => "培養層次" 
     t.string :enroll_method,  :comment => "入學方式" 
     t.date :enrolled_at,   :comment => "入學時間" 
     t.string :charge_type,   :comment => "收費類別" 
     t.string :enrolled_year,  :comment => "學籍年度" 
     t.string :enrolled_place,  :comment => "生源所在地" 
     t.string :bank_card_number,  :comment => "銀行卡號" 
     t.string :bank_account_number, :comment => "銀行賬號" 
     t.boolean :is_active_duty,  :default => false, :comment => "是否現役軍人" 
     t.boolean :is_equivalent_degree, :default => false, :comment => "是否同等學歷" 
     t.boolean :is_on_record,   :default => true, :comment => "是否在籍" 
     t.boolean :is_at_school,   :default => true, :comment => "是否在校" 
     t.timestamps 
    end 
    end 
end 

my @primes = (
    1,2,3,5,7, 
    11,13,17,19,23, 
    29,31,37,41,43, 
); 

my @primes = (
    1, 2, 3, 5, 7, 
    11, 13, 17, 19, 23, 
    29, 31, 37, 41, 43, 
); 

回答

0

對於第一種情況,選擇的區域(以下create table),並嘗試C-ùM-Xalign-regexp\(:\)-11y

對於第二種情況下,選擇該區域,並嘗試C-ùM-Xalign-regexp\([0-9]+\)-11y

正如你所看到的,正則表達式不必匹配整個字符串。你對第二個參數的理解似乎是正確的。有關更多詳細信息,請參閱align-rules-list的幫助:

`column' For alignment rules, if the `column' attribute is set -- 
     which must be an integer, or a symbol whose value is an 
     integer -- it will be used as the column in which to align 
     the alignment character. If the text on a particular line 
     happens to overrun that column, a single space character, 
     or tab stop (see `align-to-tab-stop') will be added 
     between the last text character and the alignment 
     character. 

`spacing' Alignment rules may also override the amount of spacing 
     that would normally be used by providing a `spacing' 
     attribute. This must be an integer, or a list of integers 
     corresponding to the number of parenthesis groups matched 
     by the `group' attribute. If a list of value is used, and 
     any of those values is nil, `align-default-spacing' will 
     be used for that subgroup. See `align-default-spacing' 
     for more details on spacing, tab stops, and how to 
     indicate how much spacing should be used. If TAB-STOP is 
     present, it will override the value of `align-to-tab-stop' 
     for that rule. 
+1

您在'\(:)'中缺少反斜槓。此外,這並沒有真正回答這個問題。 – Squidly 2014-10-21 15:28:10