Difference between revisions of "Keyboard macros"

From WikEmacs
Jump to navigation Jump to search
(OffersoriWY)
m (refresh doc, add melpa packages)
(377 intermediate revisions by 76 users not shown)
Line 1: Line 1:
Cliquez sur le bouton "Rpondre" qui se trouve sous le commentaire. Votre commentaire s'affichera directement en dessous de celui auquel vous avez rpondu.HuffPost lyce accueille un quartier anim, un dbat rflchi dans la section commentaire. Gardez  l'esprit que les articles ici sont sous la plume de jeunes auteurs, de sorte s'il vous plat garder la critique respectueuse, et nous aider  <a href=httpwww.football49ersproshop.com21_FRANK_GORE_JERSEYWOMENS_FRANK_GORE_LIMITED_IMPACT_JERSEY_NIKE_NFL_SAN_FRANCISCO_49ERS_21_BLACK.html>Women's Frank Gore Limited Black Jersey</a> garder cette place <a href=httpwww.packersonlineofficialstore.com52_CLAY_MATTHEWS_JERSEYYOUTH_CLAY_MATTHEWS_GAME_JERSEY_NIKE_NFL_GREEN_BAY_PACKERS_52_WHITE_ROAD.html>Youth Clay Matthews Game White Jersey</a> un coffrefort et de soutien pour les crivains de tous ges de contribuer.Couillard dit que Marois a fabriquRIVIREDULOUP, Qc  La prosprit conomique va de pair avec l'affirmation identitaire, selon le chef libral Philippe Couillard, <a href=httpwww.shopgiantsnfljersey.com90_JASON_PIERREPAUL_JERSEYWOMENS_JASON_PIERREPAUL_ELITE_BREAST_CANCER_AWARENESS_JERSEY_NIKE_NFL_NEW_YORK_GIANTS_90_ROYAL_BLUE.html>Women's Jason Pierre-Paul Elite Royal Blue Jersey</a> qui se dit convaincu que les deux sont lies.D'abord, M. Couillard, ce n'est pas <a href=httpwww.officialnfltexansprostore.com23_ARIAN_FOSTER_JERSEYMENS_ARIAN_FOSTER_LIMITED_CAMO_FASHION_JERSEY_NIKE_NFL_HOUSTON_TEXANS_23_BLACK.html>Men's Arian Foster Limited Black Jersey</a> une crise, c'est un dbat. Remarquez, je ne m'tonne <a href=httpwww.nflofficialcowboys.com82_JASON_WITTEN_JERSEYWOMENS_JASON_WITTEN_ELITE_BREAST_CANCER_AWARENESS_JERSEY_NIKE_NFL_DALLAS_COWBOYS_82_PINK.html>Women's Jason Witten Elite Pink Jersey</a> pas de cette confusion puisque vous dirigez justement un parti o tout le monde est toujours d'accord avec tout le monde et duquel trs peu d'ides mergent. Pas tonnant que vous ne sachiez pas reconnatre <a href=httpwww.officialnfltexansprostore.com99_JJ_WATT_JERSEYMENS_JJ_WATT_LIMITED_CAMO_FASHION_JERSEY_NIKE_NFL_HOUSTON_TEXANS_99_BLACK.html>Men's J.J. Watt Limited Black Jersey</a> un dbat!Comment rpondre  un commentaire:Il faut se prparer avant qu'une crise arrive. Discutter des choses la tte fropide et ne pas attendre la prochaine crise.On ne signe pas son contrat de mariage et son rgime matrimonial le jour o la chicane pogne et qu'on est sur le bords de la rupture. Pareil pour un contrat de travail ou quoi que ce soit d'autre.Saviez vous, M. Couillard, que tous les politiciens Qubcois, de Ren Lvesque  Robert Bourassa, de Jacques Parizeau  Philippe <a href=httpwww.footballbuccaneersshop.comWOMENS-MARK-BARRON-JERSEY.html>Mark Barron Game Jersey</a> Couillard, tous les politiciens Qubcois sans exception sont tenus de prter serment d'allgeance au chef de l'glise anglicane afin d'avoir le droit de reprsenter les lecteurs qui les ont chois pour les reprsenter <a href=httpwww.ravensofficialnfljerseys.com5_JOE_FLACCO_JERSEYYOUTH_JOE_FLACCO_LIMITED_JERSEY_NIKE_NFL_BALTIMORE_RAVENS_5_SUPER_BOWL_XLVII_PURPLE_TEAM_COLOR_HOME.html>Youth Joe Flacco Limited Purple Team Color Jersey</a> de faon <a href=httpwww.footballfalconsprostore.com88_TONY_GONZALEZ_JERSEYMENS_TONY_GONZALEZ_GAME_JERSEY_NIKE_NFL_ATLANTA_FALCONS_88_WHITE_ROAD.html>Men's Tony Gonzalez Game White Jersey</a> dmocratique? Et malgr tout, le bon docteur Couillard nous ordonne de cesser de provoquer des crises? Et bien cette crise, comme vous l'appelez, cher "docteur" Couillard, c'est le rveil d'un peuple. Paniquez tant que vous le voulez, mais si le gouvernement Harper invalide notre charte, cela crera un prcdent qui nous permettra enfin de <a href=httpwww.footballfalconsprostore.com11_JULIO_JONES_JERSEYMENS_JULIO_JONES_LIMITED_JERSEY_NIKE_NFL_ATLANTA_FALCONS_11_BLACK_ALTERNATE.html>Men's Julio Jones Limited Black Jersey</a> nous dbarrasser ce scandaleux serment d'allgeance: c'est notre plan B!Se doter de rgles de fonctionnement, a se fait la tte froide, juystement lorsqu'il n'y a ni chicane, ni escalade motive.Le chef du Parti libral du Qubec a fait ces commentaires <a href=httpwww.officialcardinalsfootball.com21_PATRICK_PETERSON_JERSEYWOMENS_PATRICK_PETERSON_LIMITED_IMPACT_JERSEY_NIKE_NFL_ARIZONA_CARDINALS_21_BLACK.html>Women's Patrick Peterson Limited Black Jersey</a> vendredi, au terme d'un caucus de deux jours  RivireduLoup, en vue de prparer la rentre parlementaire de septembre.Ensuite, j'avoue que vous me faites bien rire quand vous accusez le PQ d'avoir cr une crise (sic) de toute pice. L'ironie est en effet mordante quand on sait qu'il y a tout juste un peu plus d'un an, votre parti a mis le feu la province, sem la zizanie au sein de la population et engendr la pire crise sociale dans l'histoire rcente du Qubec dans le seul <a href=httpwww.football49ersproshop.com52_PATRICK_WILLIS_JERSEYWOMENS_PATRICK_WILLIS_GAME_BREAST_CANCER_AWARENESS_JERSEY_NIKE_NFL_SAN_FRANCISCO_49ERS_52_SUPER_BOWL_XLVII_PINK.html>Women's Patrick Willis Game Pink Jersey</a> et unique but de faire oublier des sondages dsastreux et de <a href=httpwww.panthersofficialnfl.com1_CAM_NEWTON_JERSEYMENS_CAM_NEWTON_ELITE_JERSEY_NIKE_NFL_CAROLINA_PANTHERS_1_WHITE_ROAD.html>Men's Cam Newton Elite White Jersey</a> pouvoir dclencher des lections avant le dbut de la Commission Charbonneau. Srieusement: la <a href=httpwww.footballbuccaneersshop.comWOMENS-SAMMIE-STROUGHTER-JERSEY.html>Sammie Stroughter Jersey</a> parabole de la paille et de la poutre, vous connaissez?Retrouvez les articles du HuffPost sur notre page Facebook.D'o l'importance,  ses yeux, pour le <a href=httpwww.officialnflpackersproshop.comWOMENS-TRAMON-WILLIAMS-JERSEY.html>Womens Tramon Williams Jersey</a> gouvernement, de dvelopper une obsession pour favoriser une conomie forte qui attire les trangers et les incite partager l'identit qubcoise.Il y en a beaucoup qui pensent que parler des problmes, c'est crer les problmes. Ma blonde tait de mme avant. Mais c'est le contraire, si on parle des problmes juste quand on est dedans jusqu'au cou, on ne les rglera jamais.Il a rappel que l'automne sera occup pour sa formation politique, alors qu'il <a href=httpwww.officialfootballdolphins.com17_RYAN_TANNEHILL_JERSEYWOMENS_RYAN_TANNEHILL_GAME_DRIFT_FASHION_JERSEY_NIKE_NFL_MIAMI_DOLPHINS_17_AQUA_GREEN.html>Women's Ryan Tannehill Game Aqua Green Jersey</a> poursuivra sa tourne du Qubec, tandis que le parti tiendra des colloques rgionaux, puis un conseil gnral en novembre, avant un grand congrs d'orientation des membres cet hiver avec l'adoption du nouveau programme. Le parti devrait ainsi tre prt, si jamais des lections gnrales sont <a href=httpwww.packersonlineofficialstore.com52_CLAY_MATTHEWS_JERSEYMENS_CLAY_MATTHEWS_ELITE_JERSEY_NIKE_NFL_GREEN_BAY_PACKERS_52_NAVY_BLUE_ALTERNATE.html>Men's Clay Matthews Elite Navy Blue Jersey</a> dclenches au printemps prochain.Cliquez ici pour laisser un commentaire.En <a href=httpwww.officialnflseahawksprostore.com3_RUSSELL_WILSON_JERSEYYOUTH_RUSSELL_WILSON_ELITE_JERSEY_NIKE_NFL_SEATTLE_SEAHAWKS_3_NAVY_BLUE_TEAM_COLOR_HOME.html>Youth Russell Wilson Elite Navy Blue Team Color Jersey</a> point de presse, M. Couillard est revenu  la charge pour dplorer que le gouvernement avait selon lui fabriqu <a href=httpwww.bearsofficialonline.com90_JULIUS_PEPPERS_JERSEYWOMENS_JULIUS_PEPPERS_ELITE_JERSEY_NIKE_NFL_CHICAGO_BEARS_90_ORANGE_ALTERNATE.html>Women's Julius Peppers Elite Orange Jersey</a> de toutes pices une crise identitaire autour <a href=httpwww.footballbuccaneersshop.comWOMENS-MIKE-WILLIAMS-JERSEY.html>Mike Williams Black Jersey</a> du port de signes religieux, au lieu de mettre la priorit sur la cration d'emplois et la croissance conomique.
+
{{Manual|emacs|Basic-Keyboard-Macro|Basic Keyboard Macro}}
 +
 
 +
'''Keyboard macros''' can be used to automate or repeat tedious editing tasks in Emacs.
 +
 
 +
 
 +
==Basic Use==
 +
 
 +
; {{Keys|F3}}, or {{Keys|C-x (}}
 +
: Start defining a macro.
 +
; {{Keys|F4}}, or {{Keys|C-x )}}
 +
: Stop defining a macro.
 +
; {{Keys|F4}}, or {{Keys|C-x e}}
 +
: Execute a macro
 +
; {{Keys|C-u 37 C-x e}} or {{Keys|C-u 37 F4}}
 +
: Execute a macro multiple times, using [[prefix argument]]
 +
; {{Keys|C-u 0 C-x e}}
 +
: Execute a macro until the end of the buffer
 +
 
 +
==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>
 +
 
 +
== Naming and saving macros ==
 +
 
 +
You can:
 +
* give a name to the most recently defined macro (<code>C-x C-k n</code>)
 +
* bind it to a key sequence (<code>C-x C-k b</code>)
 +
* insert it in the current buffer as lisp code (<code>M-x insert-kbd-macro</code>).
 +
 
 +
{{Manual|emacs|Save-Keyboard-Macro|Save Keyboard Macro}}
 +
 
 +
 
 +
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
 +
 
 +
 
 +
= See also =
 +
 
 +
* [https://github.com/Silex/elmacro elmacro], to show keyboard macros as emacs-lisp
 +
* [https://github.com/abo-abo/centimacro centimacro] to (temporarily) bind any number of macros to any global shortcuts.
 +
* You can use keyboard macros à la vim in [[evil]].
 +
 
 +
 
 +
[[Category:Intermediate]]
 +
[[Category:Editing]]

Revision as of 15:34, 28 August 2014

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

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


Basic Use

[F3], or [C-x (]
Start defining a macro.
[F4], or [C-x )]
Stop defining a macro.
[F4], or [C-x e]
Execute a macro
[C-u 37 C-x e] or [C-u 37 F4]
Execute a macro multiple times, using prefix argument
[C-u 0 C-x e]
Execute a macro until the end of the buffer

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.

Naming and saving macros

You can:

  • give a name to the most recently defined macro (C-x C-k n)
  • bind it to a key sequence (C-x C-k b)
  • insert it in the current buffer as lisp code (M-x insert-kbd-macro).

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


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


See also

  • elmacro, to show keyboard macros as emacs-lisp
  • centimacro to (temporarily) bind any number of macros to any global shortcuts.
  • You can use keyboard macros à la vim in evil.