Questions tagged [keyboard-macros]

A "keyboard macro" is a command defined by an Emacs user which represents a sequence of keys. Calling a keyboard macro is equivalent to typing that key sequence.

117 questions
53
votes
3 answers

How to save a keyboard macro as a Lisp function?

Very frequently I would need to perform the set of steps requiring multiple key strokes. For the same session those steps can be recorded in a keyboard macro. An example is saving a frequently executed search/replace operation as a keyboard macro.…
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
12
votes
2 answers

How to handle next-line in keyboard macro?

I created a keyboard macro to join lines in a buffer using: F3 C-n M-x join-line RET F4. It works fine, except when lines get too long and start to wrap – which makes this macro dependent on the width of the frame. next-line doesn’t seem to go to…
10
votes
4 answers

How can I run a keyboard macro in selected buffers from Ibuffer or selected files from dired?

If I have to do some variable name refactoring, I use ag and multiple-cursors. But when I have to do some code block removal/addition/moving, I use keyboard macros. But I need to switch to each buffer and initiate that macro run manually. Is there a…
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
10
votes
4 answers

How to resume an INCOMPLETE keyboard macro recording?

Classic use-case: You start recording a macro: C-x ( You do some stuff, let's say hello. You run a command that throws an error, let's say C-g (e.g. you mistakenly run C-s and you have to cancel that with C-g, now your work is lost). Now your…
10
votes
2 answers

What might be unused keys on Emacs that generally can be used to bind keyboard macros?

I read that the usual way to bind key to keyboard macros are C-x C-k 0 to 9 and A to Z. So for example, after we define a keyboard macro, we can type C-x C-k b and Emacs will ask for a key to bind. And the reserved keys for this purpose are C-x C-k…
nonopolarity
  • 273
  • 1
  • 7
9
votes
2 answers

Translating strings to keypresses

Given a string in elisp, I'd like to simulate emacs receiving whatever keypresses are necessary to re-create that string. So given the string "Hello" emacs would act exactly the same as if I had pressed Shift+H,e,l,l,o. Note that this is not always…
Joseph Garvin
  • 2,061
  • 8
  • 21
8
votes
2 answers

Sleep in an kbd macro

I was completing the python koans in emacs, and I was using a kdb macro to test my changes in a shell buffer and jump back into the python code. I wanted to take the line number of the next error from the shell buffer so that I could leap to it…
Matthew Piziak
  • 5,958
  • 3
  • 29
  • 77
7
votes
2 answers

query-replace in keyboard macro

Let me define a keyboard-macro: I enter C-x (, then go to beginning with M-<, then type M-% to query-replace some occurrences of foo by bar. Out of 3 occurrences found, I replace only the last 2, then save with C-x C-s and finish the kbd-macro with…
phs
  • 1,095
  • 6
  • 13
6
votes
1 answer

Is possible to execute a key binding in a function?

Say, the C-M-j is bound to c-indent-new-comment-line for c-mode (and c++-mode) and indent-new-comment-line for other modes, but I want to define a function that will execute C-M-j to c-indent-new-comment-line in c-mode (and c++-mode) and…
CodyChan
  • 2,599
  • 1
  • 19
  • 33
6
votes
1 answer

Editing a stored keyboard macro and storing the edited version

In my ~/.emacs, there are several keyboard macros stored. They appear as (fset 'dhteu-macro-name ... entries. BTW, dhteu is just a random alphabet combination prefixed to avoid collision with any existing commands. I can C-x C-k e M-x supply a macro…
deshmukh
  • 1,852
  • 13
  • 29
6
votes
2 answers

Key bound to string does not handle some chars in string correctly

(I ask this question after reading this one.) The form (global-set-key (kbd "M-e") "e") is, as far as I can tell, equivalent to (global-set-key (kbd "M-e") (lambda () (interactive) (insert "e"))) However, after evaluating (global-set-key (kbd…
T. Verron
  • 4,233
  • 1
  • 22
  • 55
6
votes
1 answer

Function to count how many times a keyboard macro is invoked?

I am quite bad at counting and remember how many times I have invoked a special command, so I wonder is there any way to count and show in the minibuffer how many time a keyboard macro was invoked? Say that I want to use the macro to navigate the…
JKRT
  • 201
  • 2
  • 4
5
votes
1 answer

Define a keyboard macro to indefinitely execute another keyboard macro and then do something else

I've defined one keyboard macro, bound to keystroke 1, say, and I want to define a second keyboard macro that executes the first one indefinitely and then returns to the beginning of the buffer. I assume that the first one always terminates if…
5
votes
3 answers

Saving and restoring highlighting patterns

I have some log files that I spend a lot of time reading, and I find myself doing the same series of commands to get useful highlighting each time I open a new log. Typically some combination of M-x highlight-phrase and M-x…
Millhouse
  • 153
  • 4
5
votes
2 answers

Keybinding for buffer word count

The following in my .emacs file does not produced the desired result of showing me the word count for the current buffer (it "does nothing"): (global-set-key (kbd "") (kbd "C-u M-=")) Is this because M-= is an interactive function? Would I need…
SabreWolfy
  • 1,378
  • 1
  • 13
  • 26
1
2 3 4 5 6 7 8