7 votes

Keybinding for buffer word count

Your binding does successfully run the keyboard macro you've specified. The problem is that the resulting message does not remain in the echo area long enough for you to see it, which is a side-...
phils's user avatar
  • 51.2k
7 votes
Accepted

How to delete all instances of a character in a bunch of files?

Unless you want an interactive confirmation, which you presumably don't since you're automatic the replacement of all occurrences, call replace-string or replace-regexp instead of query-replace-string ...
Gilles 'SO- stop being evil''s user avatar
7 votes
Accepted

Visualise keyboard macros (converting them to human readable key names)

If you purely want the human-readable key sequence, the key-description function is all you need: (key-description [return 3 16 14 5 return 21 3 46 return 24 98 return]) "<return> C-c C-p C-n C-...
phils's user avatar
  • 51.2k
7 votes
Accepted

Write `var0, var1, var2, ..., var10` in a buffer

The fastest way is to use the macro counter: C-x( starts recording a macro varF3,space inserts 0 as the initial value of the counter M-1M-0 repeat the following 10 times C-xe execute the macro
choroba's user avatar
  • 2,045
6 votes
Accepted

Incrementing characters in Emacs, next to numbers?

Characters are numbers (non-negative integers under some limit), in Emacs. If you want to increment a single character, including a digit character, then just increment it as a character: (defun ...
Drew's user avatar
  • 77.5k
6 votes
Accepted

Keybinding for buffer word count

simply (global-set-key (kbd "<f9>") 'count-words)
djangoliv's user avatar
  • 3,199
5 votes
Accepted

Editing a stored keyboard macro and storing the edited version

This is a bug in Emacs. When saving the macro, Emacs fails to add the kmacro property, so that when you start a new session, Emacs doesn't remember that dhteu-macro-name is actually a keyboard macro. ...
Stefan's user avatar
  • 26.4k
5 votes
Accepted

Transform selected text like a Python macro

This method will take the selected lines, wrap them in single quotes, and put them inside a list. (defun lines-to-list (point mark) (interactive "r") (let ((text (buffer-substring point mark))) ...
zck's user avatar
  • 9,092
5 votes

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

global-set-key is just a thin wrapper around define-key, ignoring some error checking it is (defun global-set-key (key def) (define-key (current-global-map) key def)) The documentation for define-...
icarus's user avatar
  • 1,914
5 votes
Accepted

Setting key problem: save and close just like vim

There is a function that does this already: (save-buffers-kill-emacs &optional ARG) Offer to save each buffer, then kill this Emacs process. With prefix ARG, silently save all file-...
Tyler's user avatar
  • 22.3k
5 votes
Accepted

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

I'm interested in getting a C-i not a \t C-i and \t are the same thing (ASCII character 9; aka TAB). If you want the TAB key to be different to C-i you can achieve that in a GUI environment (but not ...
phils's user avatar
  • 51.2k
5 votes
Accepted

Octal character representation in keyboard macros

This is a representation of the character whose code is 367 in octal. This "general escape representation" is described in the elisp manual. You can use the function text-char-description as: M-: (...
JeanPierre's user avatar
  • 7,465
5 votes
Accepted

alphabetic keyboard macro "counter"?

You can use the function kmacro-set-format, normally bound to C-x C-k C-f, to change the (printf-style) format used to insert the macro counter. You can set it to %c to treat the value of the macro ...
Omar's user avatar
  • 4,812
4 votes
Accepted

Repeat actions in slow motion, for presentation purposes

Actually, I've just discovered the tag screencast (I added it to my question as well), which contained 2 questions: how to repeat actions in slow motion, which contains a link to package-demo how to ...
Florent Georges's user avatar
4 votes
Accepted

How to use double keyboard macro, or keyboard macro of keyboard macro?

This looks like a bug. Using insert-kbd-macro You can look at what's actually stored in the macros: (fset 'm "a") (fset 'n [?\M-x ?m return ?a]) I created a macro called m that just prints 'a'...
Alan Third's user avatar
4 votes
Accepted

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

What is going on is that string in Emacs have historically been used in this context for 2 different purposes: sequence of characters. sequence of events. In your case, you're writing what you think ...
Stefan's user avatar
  • 26.4k
4 votes

Inserting the plus minus unicode symbol ± as a keyboard macro

You can get what you want with (global-set-key (kbd "C-c m") [177]) or if you prefer (global-set-key (kbd "C-c m") [?±]) Another solution uses the package key-chord which allows you to assign ...
Aidan Schofield's user avatar
4 votes
Accepted

Inserting the plus minus unicode symbol ± as a keyboard macro

With respect to why you saw what you saw: As Eli Zaretskii said in a reply to bug report #33829, the string is interpreted as a keyboard macro, and Emacs "interprets ±, which is a single byte with ...
Drew's user avatar
  • 77.5k
4 votes
Accepted

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

I can reproduce this in Emacs 25.2.2. The problem is that when jump-to-register attempts to read the character that identifies the register, Emacs still thinks it's running a macro, but it has no more ...
Gilles 'SO- stop being evil''s user avatar
4 votes
Accepted

How to write documentation for saved keyboard macros?

As the Elisp manual describes, you can also put the documentation string into the function-documentation property of the symbol of the macro. Example: (fset 'defined-kbd-macro (kmacro-lambda-form [?...
Tobias's user avatar
  • 33.2k
4 votes
Accepted

count-matches' result in kill-ring?

Assume you have two buffers: one with a list of strings to look for, one string per line, the other the buffer to search for the strings. Invoke this command in the buffer that lists the strings to ...
Drew's user avatar
  • 77.5k
4 votes
Accepted

Documenting keyboard macros Can I have a doc string for fset the same way as defun

You can use defalias instead of fset. You use it like fset but it takes a docstring as third argument. eg: (defalias 'pastebelow (kmacro-lambda-form [?y ?y ?p] 0 "%d") "This is my ...
dalanicolai's user avatar
  • 7,815
3 votes
Accepted

Removing preceding text from each line of a text

I would most likely use rectangle selection in this case. Put point at the top-left position, then hit C-x <SPC> (rectangle-mark-mode) to start selection. Move point to the lower-right corner ...
glucas's user avatar
  • 20.6k
3 votes

Ringing Bell in Macro with Search

The alternative mentioned in the emacs wiki link that Kevin Holmes gave works for me in emacs 25.2.1: while recording the macro, type Ctrl+s to start isearch, then type RET to switch to normal search (...
Jonathan Schuster's user avatar
3 votes

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

According to the documentation, C-c + letter and F5-F9 are reserved for the user. Another option is to bind M-m as a leader key and M-M to the original M-m instead.
Max Xiong's user avatar
  • 131
3 votes

Write `var0, var1, var2, ..., var10` in a buffer

print will output to the echo area rather than putting stuff in your buffer. You're looking for insert and dotimes: (dotimes (i 10) (insert (format "var%d, " i))) (alternatively you can use keyboard ...
rpluim's user avatar
  • 5,280
3 votes
Accepted

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

Try this: (defun insert-kbd-macro-in-register (register) "insert macro from register. prompt for register key if no argument passed. you may need to revise inserted s-expression." (...
gholk's user avatar
  • 76
3 votes

How do I get an initial M-x argument?

The key sequence M-x calls execute-extended-command. That command uses read-extended-command for reading from minibuffer. In read-extended-command the c-function completing-read does the main job. ...
Tobias's user avatar
  • 33.2k
3 votes

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

query-replace-regexp can do the trick. Select the region you want for replacing and : C-M % \brect1\b RET rect\,(1+ \#) RET ! for more information (info "(emacs)Regexp Replacement") ;;;;;...
gigiair's user avatar
  • 2,186
2 votes
Accepted

How to change keyboard shortcuts for copy, cut and paste and set keyboard shortcut for debugger (GDB)?

kill-ring-save for C-c kill-region for C-x yank for C-v gdb for M-g You should also look into enabling cua-mode, which ships with Emacs by default and allows usage of common keyboard shortcuts as ...
GDP2's user avatar
  • 1,350

Only top scored, non community-wiki answers of a minimum length are eligible