1

I have the following Clojure code snippet:

{ :id "SchK-Cash-contributions-(60%)"      :description "Schedule K - Cash contributions (60%)"      :line "L12a" :ultratax-coord 225}
                        { :id "SchK-Cash-contributions-(30%)"      :description "Schedule K - Cash contributions (30%)"      :line "L12a" :ultratax-coord 226}
                        { :id "SchK-Capital-gain-property-(20%)"   :description "Schedule K - Capital gain property (20%)"   :line "L12a" :ultratax-coord 227}
                        { :id "SchK-Book-Section-179-amount"       :description "Schedule K - Book Section 179 amount"       :line "var"  :ultratax-coord 228}
                        { :id "SchK-Other-deductions"              :description "Schedule K - Other deductions"              :line "L12d" :ultratax-coord 230}
                        { :id "SchK-Investment-interest-expense"   :description "Schedule K - Investment interest expense"   :line "L12b" :ultratax-coord 231}
                        { :id "SchK-Section-59(e)-expenditures"    :description "Schedule K - Section 59(e) expenditures"    :line "L12c" :ultratax-coord 234}
                        { :id "SchK-Commercial-revitalization-ded" :description "Schedule K - Commercial revitalization ded" :line "L12d" :ultratax-coord 236}
                        { :id "SchK-Preproductive-period-expenses" :description "Schedule K - Preproductive period expenses" :line "L12d" :ultratax-coord 237}
                        { :id "SchK-Penalty-on-early-withdrawal"   :description "Schedule K - Penalty on early withdrawal"   :line "L12d" :ultratax-coord 238}
                        { :id "SchK-Shrhldr-level-int-deduction"   :description "Schedule K - Shrhldr level int deduction"   :line "L14i" :ultratax-coord 240}
                        { :id "SchK-Shrhldr-level-other-deduction" :description "Schedule K - Shrhldr level other deduction" :line "L14j" :ultratax-coord 241}
                        { :id "SchK-Ded-at-corp-level-to-frgn-inc" :description "Schedule K - Ded at corp level to frgn inc" :line "L14m" :ultratax-coord 242}
                        { :id "SchK-Deduct---portfolio-(Other)"    :description "Schedule K - Deduct - portfolio (Other)"    :line "L12d" :ultratax-coord 245}
                        { :id "SchK-Reforestation-expenses"        :description "Schedule K - Reforestation expenses"        :line "L12d" :ultratax-coord 246}
                        { :id "SchK-Noncash-contributions-(50%)"   :description "Schedule K - Noncash contributions (50%)"   :line "L12a" :ultratax-coord 247}
                        { :id "SchK-Noncash-contributions-(30%)"   :description "Schedule K - Noncash contributions (30%)"   :line "L12a" :ultratax-coord 248}
                        { :id "SchK-Cap-gain-prop-(30%)"           :description "Schedule K - Cap gain prop (30%)"           :line "L12a" :ultratax-coord 249}

                        { :id "SchK-Qualified-conservation-(50%)"  :description "Schedule K - Qualified conservation (50%)"  :line "L12a" :ultratax-coord 390}
                        { :id "SchK-Qualified-conservation-(100%)" :description "Schedule K - Qualified conservation (100%)" :line "L12a" :ultratax-coord 391}]}

As you see, there is a pattern of an unnecessary whitespace on the beginning of every line after { and before :id.

I would like to remove the whitespace to have:

[{:id "SchK-Cash-contributions-(60%)"      :description "Schedule K - Cash contributions (60%)"      :line "L12a" :ultratax-coord 225}
                        {:id "SchK-Cash-contributions-(30%)"      :description "Schedule K - Cash contributions (30%)"      :line "L12a" :ultratax-coord 226}
                        {:id "SchK-Capital-gain-property-(20%)"   :description "Schedule K - Capital gain property (20%)"   :line "L12a" :ultratax-coord 227}
                        {:id "SchK-Book-Section-179-amount"       :description "Schedule K - Book Section 179 amount"       :line "var"  :ultratax-coord 228}
                        {:id "SchK-Other-deductions"              :description "Schedule K - Other deductions"              :line "L12d" :ultratax-coord 230}
                        {:id "SchK-Investment-interest-expense"   :description "Schedule K - Investment interest expense"   :line "L12b" :ultratax-coord 231}
                        {:id "SchK-Section-59(e)-expenditures"    :description "Schedule K - Section 59(e) expenditures"    :line "L12c" :ultratax-coord 234}
                        {:id "SchK-Commercial-revitalization-ded" :description "Schedule K - Commercial revitalization ded" :line "L12d" :ultratax-coord 236}
                        {:id "SchK-Preproductive-period-expenses" :description "Schedule K - Preproductive period expenses" :line "L12d" :ultratax-coord 237}
                        {:id "SchK-Penalty-on-early-withdrawal"   :description "Schedule K - Penalty on early withdrawal"   :line "L12d" :ultratax-coord 238}
                        {:id "SchK-Shrhldr-level-int-deduction"   :description "Schedule K - Shrhldr level int deduction"   :line "L14i" :ultratax-coord 240}
                        {:id "SchK-Shrhldr-level-other-deduction" :description "Schedule K - Shrhldr level other deduction" :line "L14j" :ultratax-coord 241}
                        {:id "SchK-Ded-at-corp-level-to-frgn-inc" :description "Schedule K - Ded at corp level to frgn inc" :line "L14m" :ultratax-coord 242}
                        {:id "SchK-Deduct---portfolio-(Other)"    :description "Schedule K - Deduct - portfolio (Other)"    :line "L12d" :ultratax-coord 245}
                        {:id "SchK-Reforestation-expenses"        :description "Schedule K - Reforestation expenses"        :line "L12d" :ultratax-coord 246}
                        {:id "SchK-Noncash-contributions-(50%)"   :description "Schedule K - Noncash contributions (50%)"   :line "L12a" :ultratax-coord 247}
                        {:id "SchK-Noncash-contributions-(30%)"   :description "Schedule K - Noncash contributions (30%)"   :line "L12a" :ultratax-coord 248}
                        {:id "SchK-Cap-gain-prop-(30%)"           :description "Schedule K - Cap gain prop (30%)"           :line "L12a" :ultratax-coord 249}

                        {:id "SchK-Qualified-conservation-(50%)"  :description "Schedule K - Qualified conservation (50%)"  :line "L12a" :ultratax-coord 390}
                        {:id "SchK-Qualified-conservation-(100%)" :description "Schedule K - Qualified conservation (100%)" :line "L12a" :ultratax-coord 391}]

How can I do it? Maybe use a keyboard macro? Or some regular expression trick?

3
  • 1
    Sure. Just start recording a keyboard macro at the place where you begin the necessary edits for a single row, then perform those operations, then stop recording. The C-u 999 C-x e to repeat the macro 999 times or until end of buffer. Be sure to record whatever movements are need to get to the right position to start playback for the next row.
    – Drew
    Commented Jan 11, 2023 at 1:33
  • 1
    A regex search-and-replace will also work quite well: replace " :id" with just ":id". Another way to do it is to define the rectangle with the spaces that you want to remove (on lines 2-22 or whatever - line 1 is going to be a special case) and then use kill-rectangle.
    – NickD
    Commented Jan 11, 2023 at 2:40
  • 2
    Personally, I think that the most obvious thing to do here is to use kill-rectangle, as @NickD suggests. I'd suggest writing more general and concise questions, thus hiding details about the concrete problem you're solving.
    – aadcg
    Commented Jan 11, 2023 at 8:44

1 Answer 1

1

Use M-x replace-regexp

  1. Highlight the region of text where you want to apply this bulk edit.
  2. M-x replace-regexp { :id RET {:id RET

Evil Alternative

  1. Highlight the region as before.
  2. : s/{: id/{:id/ RET

Same idea -- different notation.

1
  • 2
    In this case replace-string is better than replace-regexp
    – matteol
    Commented Jan 11, 2023 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.