Difference between revisions of "Keyboard macros"

From WikEmacs
Jump to navigation Jump to search
(vibram fivefingers converse børn 5 finger vibram zskt)
m (refresh doc, add melpa packages)
(300 intermediate revisions by 52 users not shown)
Line 1: Line 1:
I have 4 kids and the most importnat reason I see for uniforms is that faculty know when they see a person without uniform that they should not be on campus and they stop and question them.  ÿþ[  Thienly and I are rotating weeks now for inspiration projects this week is my week! I was very excited to work on this little flip flop box, how fun, right? This would be great for party favors, etc. Islas de barlovento. 
+
{{Manual|emacs|Basic-Keyboard-Macro|Basic Keyboard Macro}}
  
Ladies, validate hemlines and cleavage with the "Handhigh Handlow" rule. If you are looking for a sandal that is feminine and flirty while remaining comforting and professional, the Naomi sandal from Dansko Shoes is the ideal choice for you. ÿþ[ These are generally strong and durable due to the prime quality information that most are crafted.
+
'''Keyboard macros''' can be used to automate or repeat tedious editing tasks in Emacs.
ÿþh
+
 
A really bad case. Many people think I own lots of property too. If you'd like to seriously highlight a enthralling part, you will these hiking footwear! Ensure that your look thrilling using these shoes or boots and you will definitely be able to revamp your thing!fitflop boots and shoes also come in selection of models, to should be able to in good shape with each woman despite whatever your girlfriend take a look is without a doubt! The footwear usually expenditure no more than typical activity boots are available in a wide range of colours and styles. It is NOT to help the American people and his goal is not to be honest. ÿþ[  The other 2 styles will be Casual and Beach to capture the brilliant practicality and effortlessness of sandals.. This means that the toes and most of the sides and top are uncovered and the straps can even go up the leg towards the knee and this type of sandal is often called a gladiator sandal.  
+
 
+
==Basic Use==
These travel wear goodies will surely keep you comfortable and looking sexy all day long (much to the delight of guys) but you need to keep a few points in mind while packing in your stuff. Sooner or later, it seems, every mom reaches a point where she declares, "I'm giving up shorts!" For some of us, this is an age thing (we're too old for shorts), while for others, it's a size thing (our legs are no longer what they were ten years ago).  ÿþ[  Fun things in the bag can include personalized bottled waters, bags of snacks, flip flops for dancing and the area map.
+
 
ÿþh
+
; {{Keys|F3}}, or {{Keys|C-x (}}
StarStyle tip: the mini is everywhere this season, dressed down during the day with flip flops or gussied up after dark. If you?re used to painting on wood as a medium, then you already know this. Pulsing with a layer of waterresistant PVC, it did make it seems to be new and not effortless to don and tear.  ÿþ[  To create this experience, the Standard Operating Procedures (SOPs) have got to be walltowall thick with detail. They have proven their worth in society trends.. My pedi has been recommending CIO since 4 mos, at which time we had asyetundiagnosed allergies and he was just getting over colic.
+
: 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.