Mercurial > emacs
comparison man/calc.texi @ 90071:f6b4d0ebf147
Merge from emacs--cvs-trunk--0
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 02 Jan 2005 09:21:32 +0000 |
parents | 95879cc1ed20 35a12f97aef3 |
children | cb67264d6096 |
comparison
equal
deleted
inserted
replaced
90070:95879cc1ed20 | 90071:f6b4d0ebf147 |
---|---|
6331 One technique is to enter a throwaway dummy definition for the macro, | 6331 One technique is to enter a throwaway dummy definition for the macro, |
6332 then enter the real one in the edit command. | 6332 then enter the real one in the edit command. |
6333 | 6333 |
6334 @smallexample | 6334 @smallexample |
6335 @group | 6335 @group |
6336 1: 3 1: 3 Keyboard Macro Editor. | 6336 1: 3 1: 3 Calc Macro Edit Mode. |
6337 . . Original keys: 1 @key{RET} 2 + | 6337 . . Original keys: 1 <return> 2 + |
6338 | 6338 |
6339 type "1\r" | 6339 1 ;; calc digits |
6340 type "2" | 6340 RET ;; calc-enter |
6341 calc-plus | 6341 2 ;; calc digits |
6342 + ;; calc-plus | |
6342 | 6343 |
6343 C-x ( 1 @key{RET} 2 + C-x ) Z K h @key{RET} Z E h | 6344 C-x ( 1 @key{RET} 2 + C-x ) Z K h @key{RET} Z E h |
6344 @end group | 6345 @end group |
6345 @end smallexample | 6346 @end smallexample |
6346 | 6347 |
6347 @noindent | 6348 @noindent |
6348 This shows the screen display assuming you have the @file{macedit} | |
6349 keyboard macro editing package installed, which is usually the case | |
6350 since a copy of @file{macedit} comes bundled with Calc. | |
6351 | |
6352 A keyboard macro is stored as a pure keystroke sequence. The | 6349 A keyboard macro is stored as a pure keystroke sequence. The |
6353 @file{macedit} package (invoked by @kbd{Z E}) scans along the | 6350 @file{edmacro} package (invoked by @kbd{Z E}) scans along the |
6354 macro and tries to decode it back into human-readable steps. | 6351 macro and tries to decode it back into human-readable steps. |
6355 If a key or keys are simply shorthand for some command with a | 6352 Descriptions of the keystrokes are given as comments, which begin with |
6356 @kbd{M-x} name, that name is shown. Anything that doesn't correspond | 6353 @samp{;;}, and which are ignored when the edited macro is saved. |
6357 to a @kbd{M-x} command is written as a @samp{type} command. | 6354 Spaces and line breaks are also ignored when the edited macro is saved. |
6355 To enter a space into the macro, type @code{SPC}. All the special | |
6356 characters @code{RET}, @code{LFD}, @code{TAB}, @code{SPC}, @code{DEL}, | |
6357 and @code{NUL} must be written in all uppercase, as must the prefixes | |
6358 @code{C-} and @code{M-}. | |
6358 | 6359 |
6359 Let's edit in a new definition, for computing harmonic numbers. | 6360 Let's edit in a new definition, for computing harmonic numbers. |
6360 First, erase the three lines of the old definition. Then, type | 6361 First, erase the four lines of the old definition. Then, type |
6361 in the new definition (or use Emacs @kbd{M-w} and @kbd{C-y} commands | 6362 in the new definition (or use Emacs @kbd{M-w} and @kbd{C-y} commands |
6362 to copy it from this page of the Info file; you can skip typing | 6363 to copy it from this page of the Info file; you can of course skip |
6363 the comments that begin with @samp{#}). | 6364 typing the comments, which begin with @samp{;;}). |
6364 | 6365 |
6365 @smallexample | 6366 @smallexample |
6366 calc-kbd-push # Save local values (Z `) | 6367 Z` ;; calc-kbd-push (Save local values) |
6367 type "0" # Push a zero | 6368 0 ;; calc digits (Push a zero onto the stack) |
6368 calc-store-into # Store it in variable 1 | 6369 st ;; calc-store-into (Store it in the following variable) |
6369 type "1" | 6370 1 ;; calc quick variable (Quick variable q1) |
6370 type "1" # Initial value for loop | 6371 1 ;; calc digits (Initial value for the loop) |
6371 calc-roll-down # This is the @key{TAB} key; swap initial & final | 6372 TAB ;; calc-roll-down (Swap initial and final) |
6372 calc-kbd-for # Begin "for" loop... | 6373 Z( ;; calc-kbd-for (Begin the "for" loop) |
6373 calc-inv # Take reciprocal | 6374 & ;; calc-inv (Take the reciprocal) |
6374 calc-store-plus # Add to accumulator | 6375 s+ ;; calc-store-plus (Add to the following variable) |
6375 type "1" | 6376 1 ;; calc quick variable (Quick variable q1) |
6376 type "1" # Loop step is 1 | 6377 1 ;; calc digits (The loop step is 1) |
6377 calc-kbd-end-for # End "for" loop | 6378 Z) ;; calc-kbd-end-for (End the "for" loop) |
6378 calc-recall # Now recall final accumulated value | 6379 sr ;; calc-recall (Recall the final accumulated value) |
6379 type "1" | 6380 1 ;; calc quick variable (Quick variable q1) |
6380 calc-kbd-pop # Restore values (Z ') | 6381 Z' ;; calc-kbd-pop (Restore values) |
6381 @end smallexample | 6382 @end smallexample |
6382 | 6383 |
6383 @noindent | 6384 @noindent |
6384 Press @kbd{C-c C-c} to finish editing and return to the Calculator. | 6385 Press @kbd{C-c C-c} to finish editing and return to the Calculator. |
6385 | 6386 |
6390 | 6391 |
6391 20 z h | 6392 20 z h |
6392 @end group | 6393 @end group |
6393 @end smallexample | 6394 @end smallexample |
6394 | 6395 |
6395 If you don't know how to write a particular command in @file{macedit} | 6396 The @file{edmacro} package defines a handy @code{read-kbd-macro} command |
6396 format, you can always write it as keystrokes in a @code{type} command. | 6397 which reads the current region of the current buffer as a sequence of |
6397 There is also a @code{keys} command which interprets the rest of the | 6398 keystroke names, and defines that sequence on the @kbd{X} |
6398 line as standard Emacs keystroke names. In fact, @file{macedit} defines | 6399 (and @kbd{C-x e}) key. Because this is so useful, Calc puts this |
6399 a handy @code{read-kbd-macro} command which reads the current region | 6400 command on the @kbd{M-# m} key. Try reading in this macro in the |
6400 of the current buffer as a sequence of keystroke names, and defines that | 6401 following form: Press @kbd{C-@@} (or @kbd{C-@key{SPC}}) at |
6401 sequence on the @kbd{X} (and @kbd{C-x e}) key. Because this is so | |
6402 useful, Calc puts this command on the @kbd{M-# m} key. Try reading in | |
6403 this macro in the following form: Press @kbd{C-@@} (or @kbd{C-@key{SPC}}) at | |
6404 one end of the text below, then type @kbd{M-# m} at the other. | 6402 one end of the text below, then type @kbd{M-# m} at the other. |
6405 | 6403 |
6406 @example | 6404 @example |
6407 @group | 6405 @group |
6408 Z ` 0 t 1 | 6406 Z ` 0 t 1 |
30825 Once you have bound your keyboard macro to a key, you can use | 30823 Once you have bound your keyboard macro to a key, you can use |
30826 @kbd{Z P} to register it permanently with Emacs. @xref{Creating User Keys}. | 30824 @kbd{Z P} to register it permanently with Emacs. @xref{Creating User Keys}. |
30827 | 30825 |
30828 @cindex Keyboard macros, editing | 30826 @cindex Keyboard macros, editing |
30829 The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has | 30827 The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has |
30830 been defined by a keyboard macro tries to use the @code{edit-kbd-macro} | 30828 been defined by a keyboard macro tries to use the @code{edmacro} package |
30831 command to edit the macro. This command may be found in the | 30829 edit the macro. Type @kbd{C-c C-c} to finish editing and update |
30832 @file{macedit} package, a copy of which comes with Calc. It decomposes | |
30833 the macro definition into full Emacs command names, like @code{calc-pop} | |
30834 and @code{calc-add}. Type @kbd{C-c C-c} to finish editing and update | |
30835 the definition stored on the key, or, to cancel the edit, kill the | 30830 the definition stored on the key, or, to cancel the edit, kill the |
30836 buffer with @kbd{C-x k}. | 30831 buffer with @kbd{C-x k}. |
30837 | 30832 The special characters @code{RET}, @code{LFD}, @code{TAB}, @code{SPC}, |
30838 If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard | 30833 @code{DEL}, and @code{NUL} must be entered as these three character |
30839 macro is edited in spelled-out keystroke form. For example, the editing | 30834 sequences, written in all uppercase, as must the prefixes @code{C-} and |
30840 buffer might contain the nine characters @w{@samp{1 @key{RET} 2 +}}. When you press | 30835 @code{M-}. Spaces and line breaks are ignored. Other characters are |
30841 @kbd{C-c C-c}, the @code{read-kbd-macro} feature of the @file{macedit} | |
30842 package is used to reinterpret these key names. The | |
30843 notations @code{RET}, @code{LFD}, @code{TAB}, @code{SPC}, @code{DEL}, and | |
30844 @code{NUL} must be written in all uppercase, as must the prefixes @code{C-} | |
30845 and @code{M-}. Spaces and line breaks are ignored. Other characters are | |
30846 copied verbatim into the keyboard macro. Basically, the notation is the | 30836 copied verbatim into the keyboard macro. Basically, the notation is the |
30847 same as is used in all of this manual's examples, except that the manual | 30837 same as is used in all of this manual's examples, except that the manual |
30848 takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we take | 30838 takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, |
30849 it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}}, | 30839 we take it for granted that it is clear we really mean |
30850 which is what @code{read-kbd-macro} wants to see. | 30840 @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}}. |
30851 | |
30852 If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro | |
30853 in ``raw'' form; the editing buffer simply contains characters like | |
30854 @samp{1^M2+} (here @samp{^M} represents the carriage-return character). | |
30855 Editing in this mode, you will have to use @kbd{C-q} to enter new | |
30856 control characters into the buffer. | |
30857 | 30841 |
30858 @kindex M-# m | 30842 @kindex M-# m |
30859 @pindex read-kbd-macro | 30843 @pindex read-kbd-macro |
30860 The @kbd{M-# m} (@code{read-kbd-macro}) command reads an Emacs ``region'' | 30844 The @kbd{M-# m} (@code{read-kbd-macro}) command reads an Emacs ``region'' |
30861 of spelled-out keystrokes and defines it as the current keyboard macro. | 30845 of spelled-out keystrokes and defines it as the current keyboard macro. |
30862 It is a convenient way to define a keyboard macro that has been stored | 30846 It is a convenient way to define a keyboard macro that has been stored |
30863 in a file, or to define a macro without executing it at the same time. | 30847 in a file, or to define a macro without executing it at the same time. |
30864 The @kbd{M-# m} command works only if @file{macedit} is present. | |
30865 | 30848 |
30866 @node Conditionals in Macros, Loops in Macros, Naming Keyboard Macros, Keyboard Macros | 30849 @node Conditionals in Macros, Loops in Macros, Naming Keyboard Macros, Keyboard Macros |
30867 @subsection Conditionals in Keyboard Macros | 30850 @subsection Conditionals in Keyboard Macros |
30868 | 30851 |
30869 @noindent | 30852 @noindent |