user1951460
user1951460

Reputation:

transform structured text block in emacs

I want to learn from expert about how to transform this text from

    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('title', sa.String(100)),
    sa.Column('isbn', sa.String(20)),
    sa.Column('authors',sa.String(400),nullable=False),
    sa.Column('year',sa.Integer,nullable=False)

to

  id          = Column(Integer, primary_key=True)
  title       = Column(String(100))
  isbn        = Column(String(20))
  authors     = Column(String(400),nullable=False)
  year        = Column(Integer,nullable=False)

using either macro of multi-cursor. Please shed some light.

Upvotes: 2

Views: 130

Answers (2)

phils
phils

Reputation: 73400

I'd use multiple cursors to edit all the lines simultaneously.

Upvotes: 1

PascalVKooten
PascalVKooten

Reputation: 21481

This is how I did it, though my general advice would be just to look at it a couple of times, find what the general things are, then record a macro (sometimes including mistakes; do it over again, or continue if it isn't harmful)

<start recording>

Macro:

C-SPC               ;; set-mark-command
<C-right>           ;; right-word
<right>             ;; right-char
C-.                 ;; mark-next-like-this
<backspace>         ;; delete-char
2*<C-right>         ;; right-word
2*<right>           ;; right-char
2*<backspace>       ;; delete-char
M-DEL               ;; backward-kill-word
<backspace>         ;; delete-char
M-\                 ;; delete-horizontal-space
C-e                 ;; end-of-line
<backspace>         ;; delete-char
C-a                 ;; beginning-of-line
C-y                 ;; yank
SPC                 ;; self-insert-command
=                   ;; self-insert-command
SPC                 ;; self-insert-command
C-a                 ;; beginning-of-line
<down>              ;; next-line

<end recording>

Upvotes: 4

Related Questions