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.

Filter by
Sorted by
Tagged with
1 vote
4 answers
65 views

how to define keyboard macro from text

I am using shell inside Emacs. Often I need to execute a series of shell commands around ~40 chars, as of now I copy all the commands together and paste it from documentation. Is there any way to ...
  • 11
1 vote
1 answer
22 views

Simple keyboard macro to jump to \begin{document} regardless of current location in file

If you are in the preamble of a TeX document you can do C-s \begin{document} or C-r \begin{document} if you are in the body of the document. It would useful to have a simple, all-purpose macro (say, M-...
  • 157
1 vote
2 answers
85 views

Emacs 28: How to use `RET` without exiting a recursive edit within a keyboard macro?

Now that I switched to using GNU Emacs 28.1 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95)) of 2022-05-11 I can no longer end my use of my keyboard macro that ...
1 vote
1 answer
50 views

How to write a Lisp representation of a keyboard macro and bind it to a command name?

I'm using spacemacs with vim-bindings, but I only mention it so you don't scratch your head too long at the keystrokes of the macro. A regular emacs solution will work just the same. I've read through ...
0 votes
0 answers
17 views

How to control behavior of command storage for macro repeat?

There are some actions which I would like to repeat however repeating the action doesn't work as I would like it to. Take dabbrev, if I repeat a dabbrev completion, the result may be different based ...
  • 7,441
2 votes
1 answer
16 views

shortcut to select data to the last row

I'm new to Emacs. First of all sorry if my English is weird because it is not my first language. I don't know much about the terminologies used in Emacs. Currently, I'm just using Emacs for data ...
2 votes
0 answers
44 views

How to edit keyboard macro saved in file?

Here is my custom keyboard macro: (fset 'gen-numbers (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (...
  • 3,505
3 votes
2 answers
32 views

count-matches' result in kill-ring?

I'm trying to create a keyboard macro to generate a report which displays the number of times a certain string occurs. I have two buffers, with all the strings to look for(on a separate line) the ...
  • 291
1 vote
1 answer
45 views

How to automate the test step in "debugging by bisection"?

Sometimes I run into a problem with Emacs that goes away if invoke Emacs with the --no-init-flag. In other word, I can deduce that the problem in question is caused by code somewhere in my .emacs file....
  • 2,951
0 votes
0 answers
42 views

Make undo during I-search revert last call to ding

Entering a failing search string during I-search triggers a call to ding(). If this happens during a macro recording that ding when the macro is being played will abort the macro which in turns ...
  • 415
2 votes
0 answers
26 views

Is it possible to control how a command is recorded as a keyboard macro?

Some actions don't work well when repeated in a keyboard macro. For example, dabbrev-expand may give a different expansion based on the surrounding context. I would like to repeat the action as if I ...
  • 7,441
1 vote
1 answer
52 views

How to tell, with Elisp, whether a command is running as part of a keyboard macro?

In some situations a command will use timers or hooks in a way that doesn't work when repeating as a keyboard macro. How can I detect if a function is running as part of a keyboard macro that is being ...
  • 7,441
0 votes
1 answer
56 views

Do something for all regular expression matches

I have a named-and-saved keyboard macro that I want to apply to all regular expression matches. How to do that? (Related: I found this stackoverflow post: Running a macro till the end of text file in ...
1 vote
1 answer
44 views

how to end macro expansion in *scratch* buffer and return to writable buffer

In scratch buffer, Emacs can expand macros(C-c e; macrostep-expand). But once I expanded the macro, it seems to become a read-only buffer. I don't know how to end macro expansion and return to ...
  • 11
0 votes
1 answer
104 views

`C-c C-c` compilation stopped working in SLIME but works if manually typed, how to fix it?

I am new to Emacs and Slime. I have been using both of them daily for the last 10 days. And it is amazing! I am impressed. Today, I decided to install and try the package Paredit. Not sure if this is ...
0 votes
0 answers
94 views

Kill buffers - how to make *scratch* and *Messages* last

Any setting I can use to get back the old behavior where killing a buffer I get to the next buffer for the files I have given on the command line? I have been using Emacs like this for years Open ...
  • 11
0 votes
1 answer
73 views

Change vertical characters to horizontal

I have the following data and want to change from Code 1 to Code 2. Is there any useful method to do that? Code 1 11130101 11130102 11130201 Code 2 11130101, 11130102, 11130201
  • 101
3 votes
1 answer
42 views

How to write documentation for saved keyboard macros?

I have recently defined a keyboard macro using C-x ( and C-x). I then gave the keyboard macro a name using M-x name-last-kbd-macro RET defined-kbd-macro. And saved it to a file using M-x insert-kbd-...
  • 288
1 vote
1 answer
46 views

How to duplicate text but increment a numeric part of a name?

Say that I have rect1 one and I'll multiply it 3 times by yanking. let rect1 = Rectangle { width: 10, height: 40, } let rect1 = Rectangle { width: 10, height: 40, } ...
0 votes
1 answer
101 views

Execute function by using evil-set-register

I use evil and I want to execute a function by using Emacs macro system. Let's say I have the following macro. (evil-set-register ?f [?i ?f ?o ?o ?b ?a ?r escape]) I can run the macro by using @f. ...
0 votes
0 answers
63 views

How to run a keyboard macro (saved in my init.el) automatically when Emacs starts up?

I have saved a keyboard macro in my init.el file as follows (fset 'remember-notes-my-macro (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-...
  • 135
1 vote
1 answer
23 views

How to reference the contents of a variable in a keyboard macro definition?

I have a macro called f5, which I globally bind the keyboard key <f5> to: (fset 'f5 [?i ?\[ ?* ?* ?P ?1 ? ?\] escape ?h ?a]) (global-set-key (kbd "<f5>") 'f5) So when I ...
0 votes
1 answer
160 views

How to overwrite by pasting a string without selecting a region?

I can't figure out how to paste a string, for example 145 characters long, into a text line in a way, that the next 145 characters after the string are overwritten by this string or simply erased. An ...
0 votes
1 answer
15 views

Get keyboard macro mapping

What functionality is available in emacs to get information about a keyboard macro? Even something as simple as printing out what the macro evaluates.
1 vote
0 answers
104 views

How do I disable Swiper while defining a keyboard macro?

I don't like the swiper behavior when interactively defining a macro, it is slow and seems to cause other problems. How can I revert bound keys to isearch-forward and isearch-backward when defining ...
1 vote
0 answers
49 views

keyboard macro with input-method inserts characters twice

When I define keyboard macro with some input method enabled (lets say, english-dvorak), self-insert commands are repeated twice. For example, if I define macro like this: F3insert chars asdfF4 and ...
  • 249
3 votes
2 answers
468 views

How do I get an initial M-x argument?

I use an asterisk in my function names, so that to execute one of my own functions, I would begin by typing M-x *. Now I would like to save myself a keystroke and achieve the same by M-X. How do I ...
  • 2,994
0 votes
0 answers
14 views

How to execute a keyboard macro until termination inside another one, without stopping the recording?

I have a buffer with the following content and I need to delete the duplicate lines. 57,04/15/2020 03:02PM,'Weight'='2.478 lb','tare'='0.918 lb' 57,04/15/2020 03:02PM,'Weight'='2.478 lb','tare'='0....
  • 219
3 votes
1 answer
216 views

Emacs keyboard macros ? all over

I have used keyboard macros for a long time, but moved between companies, systems, and various machines over my career. I used to be able to record macros and insert-kbd-macro into my .emacs file and ...
  • 31
0 votes
1 answer
35 views

Customizing f6-key for fast "M-x imenu" + "Pr" + Enter

I wish to customize my f6key so it corresponds to a fast way of doing M-x imenu, then Pr RET. I've added the following to my ~/.emacs: (global-set-key [f6] 'imenu) Then I've tried to add different ...
2 votes
1 answer
231 views

Associate (and save) macro with current file (+/- evil spacemacs)

After edit : I am using evil-mode. I often record macros very specific to the file I am editing with qq or qw. Is there a way to autosave those macros and the key associated to them when saving the ...
1 vote
0 answers
49 views

isearch in kmacro-step-edit-macro

I'm trying to edit a keyboard macro using kmacro-step-edit-macro. The macro starts by isearching for a word. C-s ;; isearch-forward binary_function ;; self-insert-command * 15 RET ...
1 vote
3 answers
204 views

How to create loops for inserting text?

Imagine I want to create a list with 10 items, i. e. 1. 2. 3. ... 10. In Vim I can use the command :for i in range(1,10) | put =i.'. ' | endfor for this. How can I do the same thing in Emacs? ...
1 vote
0 answers
55 views

Simple regexp inside emacs keyboard macro

Newbie question: I'm trying to record a keyboard macro with a simple regexp inside (search-backward-regexp ^[0-9]). This works well when recording the macro, but as soon as I try to execute it, the ...
  • 11
3 votes
1 answer
191 views

alphabetic keyboard macro "counter"?

I very much {like, use} the kmacro-*-counter family of commands. However I sometimes find myself needing to generate alphabetic sequences (e.g., A, B, C, ...) instead of integer sequences (e.g., 1, 2, ...
  • 582
0 votes
1 answer
197 views

keyboard macro for opening a file

How can I create a keyboard macro where a file myfile is opened by executing M-x openmyfile. The main part should look like (fset 'openmyfile [?\C-x ?\C-f <dir of myfile> return]) but I don'...
3 votes
1 answer
112 views

Octal character representation in keyboard macros

I generated a macro as a help for generating indices for words I have marked before. Now this macro looks as follows (fset 'index "\367\\index{\C-y") What does \367stand for and where can I look ...
0 votes
1 answer
204 views

How can I apply a keyboard macro to every line that starts with rectangle mark region

Lets suppose I would like to edit my text and to add comments to the column in the text. This is my text: something-text1 foobar1 something-text1 something-text2 foobar2 something-text2 --- ...
  • 308
1 vote
0 answers
106 views

execute-kbd-macro apparently not working according to its doc?

The doc of execute-kbd-macro says: (execute-kbd-macro MACRO &optional COUNT LOOPFUNC) ... If MACRO is a symbol, its function definition is used. I tried M-: (execute-kbd-macro 'ignore). ...
  • 30.8k
0 votes
1 answer
42 views

Creating a macro to change dictionary and run ispell

I would like to create a simple key binding (e.g. C-c s e) to spell check the (mu4e) email message I am composing using English (and use other bindings for other languages). I thought I'd simply ...
0 votes
1 answer
49 views

macro execution with i-search fails under Linux and succeeds under windows?

Imagine you've got file with FirstName|LastName| like this : John|toto| Hanz|titi| and want to put the first names at the end of the lines (just an stupid exemple). You may use Macro Recordind for ...
  • 111
2 votes
0 answers
98 views

After 0 kbd macro iterations: read-kbd-macro: Variable binding depth exceeds max-specpdl-size

Here my kbd macros in mycustom.el (fset 'keep-tv-channels-names (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([134217848 107 101 return 69 88 84 ...
  • 3,505
0 votes
1 answer
165 views

how to generate dynamic json data with emacs (macros)?

I was in a meeting yesterday where I was presenting a program that referenced a certain json file with data like this: [ { id: 1, text: '...', ... }, { id: 2, text: '...', ... } ] In ...
  • 153
4 votes
1 answer
250 views

Binding a key sequence to a key sequence instead of a command

In my .emacs, I tried to use (global-set-key (kbd "M-r") (kbd "C-x r j") so I can use M-r to jump to a register. However, doing this and using the command gives After 0 kbd macro iterations: Args ...
4 votes
2 answers
719 views

Inserting the plus minus unicode symbol ± as a keyboard macro

I insert the plus minus symbol ± frequently enough that I want to bind it to a key. From emacs -Q, I've tried this: (global-set-key (kbd "C-c m") "±") However, when I enter C-c m, the minibuffer ...
  • 20.7k
0 votes
1 answer
78 views

What is wrong with this keyboard macro ?

I would like to accomplish following Set mark Advance to end of sentence Copy selection -> macro start here Open journal using ^c c Paste copied item Save using C-x C-s Exit using C-c C-c ...
  • 533
1 vote
1 answer
236 views

What is the difference between `C-i` and `<C-i>`?

I've just set (define-key input-decode-map "\C-i" [\C-i]) (define-key input-decode-map "\C-m" [\C-m]) (define-key input-decode-map "\C-[" [\C-\[]) in my config, but I noticed that C-i is now ...
0 votes
2 answers
590 views

How to deal with particular key-binding conflict (F3 key on Mac)

I would like to make a very basic macro on my Mac, to have a command that writes a list of slashes in the current file : //////////////////// The "Basic emacs macros" section of the manual says : ‘&...
0 votes
1 answer
225 views

Hydra that executes interactive search

What I want is an easy-to-use hydra for macro execution. Typically I execute a keyboard macro a few times (e), and then might want to repeat infinitely until the end of a buffer (u). Sometimes I ...
3 votes
3 answers
218 views

Keyboard macros or command for quick refiling using dired or similar

I scan all the mail (not email, but good ol' mail) I receive and have these saved as PDF files into a directory, which we think of as an inbox. I would like to find a workflow to quickly refile these ...
  • 151