Difference between revisions of "Keyboard macros"

From WikEmacs
Jump to navigation Jump to search
(documentary exposes fashion)
m (Protected "Keyboard macros" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
 
(453 intermediate revisions by 99 users not shown)
Line 1: Line 1:
 +
{{Manual|emacs|Basic-Keyboard-Macro|Basic Keyboard Macro}}
  
documentary exposes fashion
+
'''Keyboard macros''' can be used to automate or repeat tedious editing tasks in Emacs.
  
PARIS (AP) Discovered at 14 outside her Manhattan school, Sara Ziff was quickly embroiled within the highglamour whirlwind on the fashion industry, jetting to Paris and Milan for shoots and shows and achieving paychecks that has an astonishing variety of zeros.
 
  
She and her boyfriend, a movie school graduate, started taking home videos backstage on a lark, although the couple hobby bloomed into something bigger an inside peek behind a highgloss facade into its darker side of body image problems, drugs and perhaps sexual abuse.
+
==Basic Use==
  
Ziff, a blueeyed blond who walked for luxury supernovas including Louis Vuitton and Chanel, says the pair documentary, Me, shows a niche sometimes out of control.
+
; {{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
  
sort of free airline, with folks feeling the guidelines don apply in style, i really enjoy seeing. I love experience making some type of adjustments in in this way, Ziff, 28, told The Associated Press.
+
==Example usage==
  
She and her boyfriend and codirector, Ole Schell, were in Paris Monday to encourage the show amongst the fashion glitteratti, who sadly are flocking to the city for any springsummer 2011 readytowear show, which begins Tuesday. The show, that is currently playing in California, is scheduled to be sold in Paris next month.
+
Consider the standard <code>*scratch*</code> buffer:
  
Shot a duration of 5yrs by Ziff, Schell as well as their model friends, Me makes a convincing case for that dependence on getting some regulation within a industry where girls begin their careers at 14 and even who are only 12.
+
<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>
  
Ziff waited until after twelfth grade to pursue her career in earnest. Soon, she was gracing mammoth billboards in her own native Ny and outearning her father, a neurobiologist and professor at Manhattan University.
+
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.
  
Inside the film, we come across Ziff evolve at a wideeyed ingenue right harried and emotionally strungout young woman.
+
# 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".
  
She often in tears, reeling on the sheer exhaustion with the brutal monthlong fashion show calendar, or upset about a tactless comment from a belonging to the professionals backstage. Ziff says the industry tends to see models as objects that they are poked, prodded and painted, as an alternative to as sensitive girls.
+
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.
  
The film also prods what Ziff calls the and salacious underbelly of favor, with your girlfriend and her friends talking on camera around the taboo subjects of cocaine use backstage, bulemiaclogged toilets and photographers unwanted sexual advances.
+
<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>
  
Ziff, and Schell, 35, insist they hadn initially attempt to develop a tellall documentary.
+
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.
  
started by only innocently shooting for celebration, said Schell, adding it was his journalist father who convinced the happy couple to manufacture a film. we took this home videos, about two year period of home videos, after which interviewed a handful of Sara friends, other models, and photographers and designers.
+
<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>
  
though not always considered so cool to assess things from the fashion industry, said Schell, who also directed in China, a documentary about capitalism during the Asian giant. you peel back the layers and to consider the machinations behind the curtain, people are not keen on playing that. After Me debuted about the film festival circuit she changed agencies, she said.
+
== Naming and saving macros ==
  
Still, the film is not all negative. It showcases the camaraderie and also close bonds that develop between models as they turn to the other person for support, but it often targets the lighthearted and happy moments they share.
+
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>).
  
Me also underscores the way in which modeling allows teenage girls, often from small towns in Eastern Europe or Latin American, to lift their families away from grinding poverty.
+
{{Manual|emacs|Save-Keyboard-Macro|Save Keyboard Macro}}
  
Subsequent the movie, Ziff is seeking the best way from modeling and gets taken in Columbia University. Having paid her way over the Ivy League college for my child income from modeling, Ziff is always to graduate by using a degree in political science in December.
 
  
Along with making the video, Ziff also completed Democratic candidate Andrew Cuomo campaign kids York governor and said she was surprised the quality of crossover between fashion and politics.
+
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]]

Latest revision as of 15:27, 4 July 2016

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.