Emacs 24 Keyboard Macros Are Slow

I noticed that keyboard macros are very slow in emacs 24

for example - I just tried running a macro to add β€œ0” to the end of each line in line text file 105615

Cx ( Ce TAB 0 Cn Ca Cx ) 

then

 Cu 105615 Cx e 

takes about 5 minutes to complete

I never noticed that they work so slowly, I wondered if this is due to the upgrade from 23 to 24?

Is there something I can do to improve performance?

+4
source share
4 answers

Yes, you're right, it's damn slow.

For this specific task you can use replace-regexp .

 Mx buffer-disable-undo Mx replace-regexp $ <ENTER> Cq TAB 0 <ENTER> 
+4
source

This answer, of course, will not always be applicable, but if the main mode turns out to be irrelevant for the macro under consideration, then a good way to improve the keyboard macro execution speed is to switch the buffer to the main mode first. In some cases, which can provide a significant increase in speed, since you eliminate the overhead of primary and secondary modes.

If changing the main modes is not possible, you can still get significant benefit from turning off some of the secondary modes for a duration.

However, according to the accepted answer and comments, if there is enough search and replacement, it will always be much faster than any macro.

+9
source

In the keyboard layout, I see two potential sources of slowness:

  • TAB : depending on the main mode, this can do a lot of work, for example. to determine the indentation to use.
  • Cn : starting with Emacs-23, it tries to move on to the next line of display, so it may take a lot more work than before (it should take into account the visualization of the display with details such as variable width fonts, images, ...). In addition, it is not reliable for your use, since on a line longer than the display, it Cn move to the next line of display, but will remain on the same logical line that the subsequent ca will simply return to the beginning of the same line (because ca works on logical lines, not display lines). Of course, it all depends on line-move-visual and visual-line-mode .

I don’t have a good recommendation for TAB, because I don’t know what it intended to do (it depends on the main mode), but I would replace Cn Ca with Cf , which will be much faster and more reliable.

+5
source

My reading of the information suggests that (forward-line) may be a better replacement for Cn Ca , because it ignores any visual line breaks (therefore it can be more efficient) and moves to the beginning of the line (saving Ca ).

0
source

Source: https://habr.com/ru/post/1437775/


All Articles