Difference between revisions of "Keyboard macros"

From WikEmacs
Jump to navigation Jump to search
(Intermediary exposes to the sun on the west Kamaqiao approachs a state indefinitely sufficient in already just left give a contract 3 years0)
(Undo VANDALISM revision 4527 by 5.135.164.12 (talk))
Line 1: Line 1:
 +
{{Manual|emacs|Basic-Keyboard-Macro|Basic Keyboard Macro}}
  
Intermediary exposes to the sun on the west Kamaqiao approachs a state indefinitely sufficient in already just left give a contract 3 years
+
'''Keyboard macros''' can be used to automate or repeat tedious editing tasks in Emacs.
The country is sufficient choose handsome seem a big play, the eye is being looked at entered wonderful sections and chapters. At present the coach of foreign nationality of big shop sign in fokelore is you are sung I come on stage, it is the message flies all over the sky at the same time; Across is ceaseless what refute a rumor and ask blame place to answer. Pull Gongneisi, Beinitesi from A, arrive again to path Mu Kamaqiao, mix now China male sufficient advocate the person of the relation on Shuai Pan is increasing, among them after all who most rely on chart? Yesterday, spain is famous media " A Si signs up for " take the lead in publishing gave a informations: Those who block Ma Qiao to leave Chinese group is handsome already closer and closer! This newspaper confirms even, chinese respect opens the contract that gave a by a definite date 3 years for Kamaqiao, renown Shuai Zheng is considering this Spain of 56 years old in.  
+
 
It is reported, the country is sufficient choose this handsome basically aimed at Spain to teach a head, asking is " 60 years old of the following world-class the name is handsome " . According to this condition, accord with China most sufficient assist of the requirement is Beinitesi and Kamaqiao, but Beinitesi ask a price is too high, accordingly, ka Maqiao is considered as a country by the outside recently sufficient new handsome the biggest popular, after all the yearly salary enough of 4 million euro moves. Nowadays, this kind guesses and the hearsay became a fact.
+
==Example usage==
" A Si signs up for " say in the report, china hopes to invite Kamaqiao to lead a team to pound 2014 Brazil world cup, it is the contract that gave a by a definite date 3 years, and block Ma Qiao to studying this contract. " A Si signs up for " early childhood, china just faces Kamaqiao to have hope very much, affirmatory have in working lieutenant general " absolute right " . This also is the first time in Spanish media appears to teach about Spaish the message of Chinese team.  
+
Consider the standard <code>*scratch*</code> buffer:
  analysis
+
 
Ability of ironhanded coach individual is beyond question
+
<pre>
Ka Maqiao is the person with hot check of one individual character, when emperor Ma Zhushuai is being taken up the post of before, be on bad terms with club high level with respect to two, and finish class early. In recent years, of Ka Maqiao teach it is general that success can say only, the beginning of the year because military successes not beautiful and from on the west the team of abstruse Sa Su Na of armour finishs class. 5 many months come to come off sentry duty, ka Maqiao all the time be unemployed is in the home. teach career only then 1992 Baliekanuo team, spaish went later, saiweiliya and royal Madrid team, and lead go on an expedition of Spanish nation group Ou Jin was surpassed 2000 and 2002 world cup. Portuguese Benfeika also is heretofore the first yes besides exclusive Spain teach experience.  
+
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
Apply all along the Kamaqiao of ironhanded policy, be in small club to be able to depend on his mana direct troops, but in emperor horse such rich and powerful family, ka Maqiao's style cannot get a welcome. Ka Maqiao taught for the first time 1998 when emperor horse, insisted 22 days to get the air only, took up the post of emperor Ma Zhushuai the 2nd times to also be maintained only 2004 be less than 4 months.
+
;; If you want to create a file, visit that file with C-x C-f,
Because personality is strong, the player since criticism of tall blocking a horse will always be without scruple, the core player such as dagger of Luonaerduo, Carlos, humble, Gu Di stands to oppose with Kamaqiao directly early or late, pass finally 0 than 3 after be defeated by Lewokusen, kamaqiaodi gives resignation, ma Zhi teaching experiences emperor of many days 100 to draw full stop at this point.  
+
;; then enter the text in that file's own buffer.
Since can take up the post of Spain,block Ma Qiao nevertheless advocate handsome, still explain capable really. Taught <a href="UR"L>air jordan 1</a> 1992 Baliekanuo leads second class team the team raises on the west armour; Taught 1994 Spaish, also let add peaceful team to enter the toppest league matches with a sports season only. The Shuang Renjian effect that this shows nature of wrist of Qiao Tie blocking a horse adequately also.  
+
</pre>
  attention
+
 
The battle with 23 days of sufficient countries fears Gao Hongbo the peak of poetic perfection
+
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.
Current, be unemployed of Qiao Zaijia blocking a horse, be like what report as Spanish media really if really in that way, approach a state already indefinitely sufficient handsome, so, want a contract only nonexistent difference, block Ma Qiao general to be able to set out at any time hurry off to China. That is to say, gao Hongbo is in of national group handsome, can have entered time, 23 days are in this month the match of Kunming, be afraid the peak of poetic perfection that becomes group of Gao Hongbo nation likely really to teach.
+
 
About the time of new handsome arrival, wei Di's attitude is very specific, "I think ocean commander in chief will more quickly had been jumped over, china is sufficient assist already had made sufficient thought and working preparation, in order to had been handled outside teach brash a series of issues that assume office and trade handsome place to bring temporarily. " nevertheless, wei Di also expresses: "The mood is agog on one hand, what outside Shanghaiguan teachs retain the job also cannot urgent in unripe chaos. China is sufficient assist should be in charge of to foreign nationality coach already, also want to be in charge of to Chinese team. Also want to be in charge of to Chinese team..  
+
# Make sure [[point]] is at the start of the buffer.
  To the arrangement that Gao Hongbo did not come to, china is sufficient assist early already somewhat final conclusion, that is medium group leader of square drill group. As to the relation between group leader of group of foreign Shuai Yuzhong's square drill, china is sufficient assist vice-chairman Yu Hongchen expresses: "We are very clear before those unsuccessful example, accordingly we have confidence not to allow meddlesome addle thing this, through divide the work and be being coordinated reasonably, hope people tacit understanding cooperates in the job, won't appear collide and fall. Won't appear collide and fall..  
+
# 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.
  blocks equestrian Qiao Zhi to teach personal details
+
# 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.
1992-1993 Baliekanuo
+
# Hit backspace to delete that "a".
1994-1996 Spaish
+
 
  Wei Liya of 1996-1997 a place of strategic importance
+
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.
1997-1998 Spaish
+
 
Group of 1998-2002 Spain nation
+
<ol start="5">
2002-2004 Ben Fei gets stuck
+
<li>Hit <code>C-e C-f</code> to move point to the beginning of the next line.</li>
2004 emperor horse
+
<li>Hit <code>C-x )</code> to finish the recording of our macro.</li>
2007-2008 Ben Fei gets stuck
+
</ol>
Su Na of 2008-2011 abstruse Sa
+
 
  is tracked
+
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.
China is sufficient assist be utterly ignorant as before
+
 
The country is sufficient choose handsome, n/COL the head of a family China is sufficient assist without any messages, it is each media each shows special prowess, guess the foreign Shuai Ren of national sufficient future is chosen in succession. Yesterday, be about to take office as a country in Kamaqiao sufficient advocate when handsome news is acclaimed bubbling with noisely, the reporter calls China sufficient assist news Guan Donghua, dong Hua is to be utterly ignorant as before, "I do not understand this business, do not want to guess at random please. Do not want to guess at random please..
+
<ol start="7">
It is reported, china is sufficient assist before Ceng Tong lives the third way, handsome Beinitesi gave out Liverpudlian name to invite, nevertheless, beinitesi did not show the inclination that shows China up to now. Under photograph comparing, ka Maqiao is sufficient to China assist invite more active, so, just appeared to block Ma Qiao to be close to the view of Chinese football indefinitely.
+
<li>Hit <code>C-x e</code> once to call that macro.</li>
In fact, because the country is sufficient,choose handsome it is act of a kind of trade, be in China in the light of this matter so sufficient assist interior keeps secret highly, the reportorial information that because this media is right,picks handsome be related comes from greatly at agent or it is bilateral precatory tripartite. In domestic media according to choose handsome level mad when frying each candidate, foreign media is sufficient to the country also choose handsome close attention, especially the media of candidate place country, it is to release an information first more. That is to say, in the news that this moment announces, although have certain accuracy, but cannot believe completely, want Kamaqiao to had been not mixed only after all China is sufficient assist sign working contract, everything returns existence variable.
+
<li>Continue hitting <code>e</code> to call it several times. Hit any other key to get out of the macro repetition.</li>
This group manuscript reporter Yu Yang(Fan Texi surpasses the line on the activity after basketball hassle season | Sport one ball becomes famous dazzle eye storm will raid
+
</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 07:43, 2 May 2013

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

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

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