Difference between revisions of "Keyboard macros"

From WikEmacs
Jump to navigation Jump to search
(5 finger vibram billige converse sko converse støvler idce)
(Undo revision 5438 by 198.27.74.193 (talk))
Line 1: Line 1:
Prosecutors will moose made reference to describe as Mulberry Sale, hijacked maersk pirates gang leader.  ÿþ<> Ce budget finance une équipe de recherchedesign de 25 personnes et des tests en situation, à l'image de ceux qui ont fondé le succès de la marque en 1954 lorsque les premiers alpinistes à vaincre le K2, le deuxième plus haut sommet de la planète, avaient été équipés de semelles Vibram. Jour 1: Arrivé à Reykjavik, découverte de la ville, nuit sur placeJour 2 : Visite du Cercle d'or, nuit à SkalholtJour 3 : Passage par Hjalparfoss, en direction de Leirubakki pour départ vers Landmannalaugar en bus. 
+
{{Manual|emacs|Basic-Keyboard-Macro|Basic Keyboard Macro}}
  
Au cours de l'excellent, votre pronation, pose, et le crépitement autre arbre bouchée est un de taille avec peutêtre pris en considération. La nuit tombera vite sous un ciel chargé d'une semelle homogène, fine et sans le moindre vent. ÿþ<> Prosecutors will moose made reference to describe as Mulberry Sale, hijacked maersk pirates gang leader.
+
'''Keyboard macros''' can be used to automate or repeat tedious editing tasks in Emacs.
ÿþh
+
 
<>] Paris, Marseille, New York et Washington sont les quatre villes couvertes. Many people do this all a joke coach sale people do not criticize those of other elderly people to waste so much time has really not expected to do business. <>] Depuis que les grands chefs les cuisinent à toutes les sauces, les graines germées jouent la hype food et la touche bienêtre dans l'assiette. You can Vibram Five Fingers Sale products with high quality footwear ught a pair with the Cheap Five Fingers Shoes footwear in Grey Palm shade. ÿþ<> Chaussure flexible, résistant et dynamique, fournie de haute niveau de fonctionnalité et de confort, parfaite pour qui aime les activités outdoor légères sur terraines secs ou humides. These shoes are made of premium leather and lightweight mesh uppers for durability, abrasion resistance and support.  
+
 
+
==Basic Use==
Cette opération peut aussi bien se faire, comme chez nous, sur un siège incliné avec un bac, ou sur le siège où l'on vous coupera les cheveux, sans bac et donc sans eau ! Il faudra alors se deplacer, la tête blanche, où il est possible d'enlever la mousse. Elles contiennent autant de protéines que le fromage, jusqu'à quatorze fois plus de calcium que le lait, trente fois plus de fer que les épinards et mille fois. ÿþ<> "Un jour de sentier, huit jours de santé!" certifie un adage de la FFRP.  
+
 
ÿþh
+
; {{Keys|<F3>}}, or {{Keys|C-x (}}
Une première collection, déroutante et très tendance, conçue en partie avec le créateur de mode milanais Bruno Bordese, a vu discrètement le jour l'hiver dernier. Directattach development for prolonged lasting longevity.. <>] Je préfère aller lentement, le laisser être découvert par le public, à des prix accessiblesÿþ<> Possibly your safer even more sometimes surface area will surely have errant rubble plus destroyed cup that may not be seen. Which works because thats how much I should be running today. J aussi l plaisir d que mon ancien et nouveau coll de travail s la 6 place au scratch (en 2H et quelques minutes), et 1er dans sa cat Excellent ! Les minimalistes ont du bon ! Bravo, les gar qui r leur premier trail.
+
: Start defining a macro.
 +
; {{Keys|<F4>}}, or {{Keys|C-x )}}
 +
: Stop defining a macro.
 +
; {{Keys|<F4>}}, or {{Keys|C-x e}}
 +
: Execute a macro
 +
 
 +
To execute a macro multiple times, use [[prefix argument]]:
 +
 
 +
; {{Keys|C-u 37 C-x}} or {{Keys|C-u 37 <F4>}}
 +
 
 +
 
 +
 
 +
==Example usage==
 +
Consider the standard <code>*scratch*</code> buffer:
 +
 
 +
<pre>
 +
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
 +
;; If you want to create a file, visit that file with C-x C-f,
 +
;; then enter the text in that file's own buffer.
 +
</pre>
 +
 
 +
Suppose you want to remove the first occurrence of the letter "a" on every row in that piece of text. You could write a [[regular expression]] to do the job, but let's assume you want to use a keyboard macro this time.
 +
 
 +
# Make sure [[point]] is at the start of the buffer.
 +
# Hit <code>C-x (</code> to start recording your macro. '''Note:''' If you hit <code>C-g</code> or if an error occurs, your keyboard macro recording will stop.
 +
# Hit <code>C-s</code> followed by <code>a</code> to find the first "a". Now, point is right after the first "a" in the text.
 +
# Hit backspace to delete that "a".
 +
 
 +
The first occurrence of "a" of the first line has been deleted. Let's move point to the beginning of the next line and then stop recording.
 +
 
 +
<ol start="5">
 +
<li>Hit <code>C-e C-f</code> to move point to the beginning of the next line.</li>
 +
<li>Hit <code>C-x )</code> to finish the recording of our macro.</li>
 +
</ol>
 +
 
 +
The macro you have just recorded performs the operation of removing the first occurrence of "a" it can find and then moving point to the next line.
 +
 
 +
<ol start="7">
 +
<li>Hit <code>C-x e</code> once to call that macro.</li>
 +
<li>Continue hitting <code>e</code> to call it several times. Hit any other key to get out of the macro repetition.</li>
 +
</ol>
 +
 
 +
==Saving macros==
 +
{{Manual|emacs|Save-Keyboard-Macro|Save Keyboard Macro}}
 +
 
 +
===Binding to a key===
 +
To bind a keyboard macro to a key use <code>C-x C-k b</code>.  To avoid problems caused by overriding existing bindings, the key sequences <code>C-x C-k 0</code> through <code>C-x C-k 9</code> and <code>C-x C-k A</code> through <code>C-x C-k Z</code> are reserved for your own keyboard macro bindings.  You can, however, bind a keyboard macro to whatever you like.
 +
 
 +
==Variables==
 +
 
 +
Variables can be stored in lisp or in [[registers]]. Here's an example using lisp:
 +
 
 +
<pre>
 +
[M-: (setq x 1)]
 +
<F3>
 +
Line number [C-u M-: x]
 +
[M-: (setq x (+ x 1))]
 +
<F4>
 +
</pre>
 +
 
 +
Now execute the macro four times with the command <code>C-x e e e e</code> and you get:
 +
 
 +
line number 1<br />
 +
line number 2<br />
 +
line number 3<br />
 +
line number 4

Revision as of 10:14, 19 October 2013

Basic Keyboard Macro (`(info "(emacs) Basic Keyboard Macro")')

Keyboard macros can be used to automate or repeat tedious editing tasks in Emacs.


Basic Use

<span title="Try `C-h k <F3>' for more information." style="border-bottom
1px dotted">[<F3>], or [C-x (]
Start defining a macro.
<span title="Try `C-h k <F4>' for more information." style="border-bottom
1px dotted">[<F4>], or [C-x )]
Stop defining a macro.
<span title="Try `C-h k <F4>' for more information." style="border-bottom
1px dotted">[<F4>], or [C-x e]
Execute a macro

To execute a macro multiple times, use prefix argument:

[C-u 37 C-x] or <span title="Try `C-h k C-u 37 <F4>' for more information." style="border-bottom
1px dotted">[C-u 37 <F4>]


Example usage

Consider the standard *scratch* buffer:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

Suppose you want to remove the first occurrence of the letter "a" on every row in that piece of text. You could write a regular expression to do the job, but let's assume you want to use a keyboard macro this time.

  1. Make sure point is at the start of the buffer.
  2. Hit C-x ( to start recording your macro. Note: If you hit C-g or if an error occurs, your keyboard macro recording will stop.
  3. Hit C-s followed by a to find the first "a". Now, point is right after the first "a" in the text.
  4. Hit backspace to delete that "a".

The first occurrence of "a" of the first line has been deleted. Let's move point to the beginning of the next line and then stop recording.

  1. Hit C-e C-f to move point to the beginning of the next line.
  2. Hit C-x ) to finish the recording of our macro.

The macro you have just recorded performs the operation of removing the first occurrence of "a" it can find and then moving point to the next line.

  1. Hit C-x e once to call that macro.
  2. Continue hitting e to call it several times. Hit any other key to get out of the macro repetition.

Saving macros

Save Keyboard Macro (`(info "(emacs) Save Keyboard Macro")')

Binding to a key

To bind a keyboard macro to a key use C-x C-k b. To avoid problems caused by overriding existing bindings, the key sequences C-x C-k 0 through C-x C-k 9 and C-x C-k A through C-x C-k Z are reserved for your own keyboard macro bindings. You can, however, bind a keyboard macro to whatever you like.

Variables

Variables can be stored in lisp or in registers. Here's an example using lisp:

[M-: (setq x 1)]
<F3>
Line number [C-u M-: x]
[M-: (setq x (+ x 1))]
<F4>

Now execute the macro four times with the command C-x e e e e and you get:

line number 1
line number 2
line number 3
line number 4