about keyboard macros

Table of Contents

1 basics

macros can help ease repetetive keyboard action.

1.1 generic

1.1.1 record

  • start recording.
  • press some keys.
  • finalize recording.

==> have a macro.

1.1.2 replay

the macro can be replayed!

no shit Sherlock!

1.2 concrete

1.2.1 record

  • function key <f3>
  • action: type something: e.g. "emacs ".
  • <f4>

stop recording any time with C-g.

1.2.2 replay

  • <f4>

2 beyond the basics

2.1 record (and some replay)

  • start alternatives:
    • <f3>
    • C-x (
    • M-x kmacro-start-macro
  • finalize recording:
    • C-x )
    • M-x kmacro-end-macro
    • <f4>
    • M-x kmacro-end-or-call-macro
    • C-x e
    • M-x kmacro-end-and-call-macro
    • C-x e e e

2.2 replay a number of times

  • have a macro.
  • prefix argument indicates number of repeats of the macro.

    e.g. C-u 42 C-x e
    
  • special prefix argument 0. ==> repeat until error.
    • use case: do something for all occurances.

2.3 replay for every line in region

C-x C-k r apply-macro-to-region-lines

3 view last macro

C-x C-k C-v kmacro-view-macro-repeat

4 edit a kmacro

C-x C-k E
M-x edit-last-kbd-macro .
(no term)
do some edits.
C-c C-c
apply the edits.
(no term)
enjoy the changes.

5 step through a macro

C-x C-k SPC kmacro-step-edit-macro

6 counter

  • there is a counter for use with keyboard macros.
  • M-x kmacro-set-counter.
  • M-x kmacro-insert-counter.
    • automatically +1 to the counter .
    • prefix-arg defines the amount to sum.
  • M-x kmacro-set-format. format strings look like "%03d".

7 break the flow

C-x q
give control to the user.
C-u C-x q
enter recursive edit.

8 bind a macro to key

  • C-x C-k b kmacro-bind-to-key

8.1 bind to a register

C-x C-k x register
kmacro-to-register
C-x r j register

9 more ways to edit

  • C-x C-k l kmacro-edit-lossage
  • C-x C-k e edit-kbd-macro

10 save a macro

  • name a macro.
    • C-x C-k n kmacro-name-last-macro
  • let a macro survive the switch off. (aka persistence)
    • name the macro.
    • switch to a writable buffer.
    • M-x insert-kbd-macro
      • choose the named macro.
    • ==> find code which defines the macro. insert that in your config file.

11 macro ring

  • there is a ring (aka list) which keeps the accessible macros. (without the named macros, I think.)
  • the head of that ring is the "last macro".
  • operations on the ring.

C-x C-k C-n kmacro-cycle-ring-next C-x C-k C-p kmacro-cycle-ring-previous C-x C-k C-d kmacro-delete-ring-head C-x C-k C-t kmacro-swap-ring C-x C-k C-l kmacro-call-ring-2nd-repeat

12 more

12.1 repeat movement

  • M-x repeat

12.2 performance

:(

12.3 documentation

12.4 lisp macros

  • keyboard macros vs. lisp macros.
    • it's not the same.

12.5 as always…

  • get creative!
  • do as you like!
  • thanks!

Author: Marco

Created: 2018-08-29 Wed 23:24

Validate