diff options
| author | Richard M. Stallman | 1994-05-01 09:17:11 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-05-01 09:17:11 +0000 |
| commit | 87b2d5ff029e93b27ab4887608788fd3d2b8c7e7 (patch) | |
| tree | 91e94898df59821a1134e69a0fd9d7212d4b52fe | |
| parent | 4fe1de1272b657e687889dbf1f47d954b1d14278 (diff) | |
| download | emacs-87b2d5ff029e93b27ab4887608788fd3d2b8c7e7.tar.gz emacs-87b2d5ff029e93b27ab4887608788fd3d2b8c7e7.zip | |
*** empty log message ***
| -rw-r--r-- | lispref/edebug.texi | 330 | ||||
| -rw-r--r-- | lispref/keymaps.texi | 823 |
2 files changed, 524 insertions, 629 deletions
diff --git a/lispref/edebug.texi b/lispref/edebug.texi index c36ac42768e..991ea0a5391 100644 --- a/lispref/edebug.texi +++ b/lispref/edebug.texi | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | @c , Bugs and Todo List, Top, Top | 8 | @c , Bugs and Todo List, Top, Top |
| 9 | 9 | ||
| 10 | @node Edebug, Bugs and Todo List, Top, Top | 10 | @node Edebug,, Compilation Errors, Debugging |
| 11 | @section Edebug | 11 | @section Edebug |
| 12 | @cindex Edebug mode | 12 | @cindex Edebug mode |
| 13 | 13 | ||
| @@ -152,12 +152,7 @@ display a list of all Edebug commands. | |||
| 152 | 152 | ||
| 153 | In order to use Edebug to debug Lisp code, you must first | 153 | In order to use Edebug to debug Lisp code, you must first |
| 154 | @dfn{instrument} the code. Instrumenting code inserts additional code | 154 | @dfn{instrument} the code. Instrumenting code inserts additional code |
| 155 | into it, code which invokes Edebug at the proper places. | 155 | into it, to invoke Edebug at the proper places. |
| 156 | |||
| 157 | Once a function is instrumented, any call to the function activates | ||
| 158 | Edebug. This may or may not stop execution, depending on the Edebug | ||
| 159 | execution mode in use. Some Edebug modes only update the display to | ||
| 160 | indicate the progress of the evaluation without stopping execution. | ||
| 161 | 156 | ||
| 162 | @kindex C-M-x | 157 | @kindex C-M-x |
| 163 | @findex eval-defun (Edebug) | 158 | @findex eval-defun (Edebug) |
| @@ -217,7 +212,7 @@ must tell it; @xref{Instrumenting Macro Calls}, for details. | |||
| 217 | @findex eval-expression (Edebug) | 212 | @findex eval-expression (Edebug) |
| 218 | To remove instrumentation from a definition, simply reevaluate its | 213 | To remove instrumentation from a definition, simply reevaluate its |
| 219 | definition in a way that does not instrument. There are two ways of | 214 | definition in a way that does not instrument. There are two ways of |
| 220 | evaluating forms without instrumenting them: from a file with | 215 | evaluating forms that never instrument them: from a file with |
| 221 | @code{load}, and from the minibuffer with @code{eval-expression} | 216 | @code{load}, and from the minibuffer with @code{eval-expression} |
| 222 | (@kbd{M-ESC}). | 217 | (@kbd{M-ESC}). |
| 223 | 218 | ||
| @@ -233,7 +228,7 @@ inside of Edebug. | |||
| 233 | @cindex Edebug execution modes | 228 | @cindex Edebug execution modes |
| 234 | Edebug supports several execution modes for running the program you are | 229 | Edebug supports several execution modes for running the program you are |
| 235 | debugging. We call these alternatives @dfn{Edebug execution modes}; do | 230 | debugging. We call these alternatives @dfn{Edebug execution modes}; do |
| 236 | not confuse them with major or minor modes. The current Edebug mode | 231 | not confuse them with major or minor modes. The current Edebug execution mode |
| 237 | determines how far Edebug continues execution before stopping---whether | 232 | determines how far Edebug continues execution before stopping---whether |
| 238 | it stops at each stop point, or continues to the next breakpoint, for | 233 | it stops at each stop point, or continues to the next breakpoint, for |
| 239 | example---and how much Edebug displays the progress of the evaluation | 234 | example---and how much Edebug displays the progress of the evaluation |
| @@ -281,13 +276,13 @@ can still stop the program by typing @kbd{S}, or any editing command. | |||
| 281 | @end table | 276 | @end table |
| 282 | 277 | ||
| 283 | In general, the execution modes earlier in the above list run the | 278 | In general, the execution modes earlier in the above list run the |
| 284 | program more slowly or stop sooner. | 279 | program more slowly or stop sooner than the modes later in the list. |
| 285 | 280 | ||
| 286 | While executing or tracing, you can interrupt the execution by typing | 281 | While executing or tracing, you can interrupt the execution by typing |
| 287 | any Edebug command. Edebug stops the program at the next stop point and | 282 | any Edebug command. Edebug stops the program at the next stop point and |
| 288 | then executes the command that you typed. For example, typing @kbd{t} | 283 | then executes the command you typed. For example, typing @kbd{t} during |
| 289 | during execution switches to trace mode at the next stop point. You can | 284 | execution switches to trace mode at the next stop point. You can use |
| 290 | use @kbd{S} to stop execution without doing anything else. | 285 | @kbd{S} to stop execution without doing anything else. |
| 291 | 286 | ||
| 292 | If your function happens to read input, a character you type intending | 287 | If your function happens to read input, a character you type intending |
| 293 | to interrupt execution may be read by the function instead. You can | 288 | to interrupt execution may be read by the function instead. You can |
| @@ -362,17 +357,17 @@ move point there, and then type @kbd{f}. | |||
| 362 | 357 | ||
| 363 | The @kbd{o} command continues ``out of'' an expression. It places a | 358 | The @kbd{o} command continues ``out of'' an expression. It places a |
| 364 | temporary breakpoint at the end of the sexp containing point. If the | 359 | temporary breakpoint at the end of the sexp containing point. If the |
| 365 | containing sexp is a function definition itself, it continues until just | 360 | containing sexp is a function definition itself, @kbd{o} continues until |
| 366 | before the last sexp in the definition. If that is where you are now, | 361 | just before the last sexp in the definition. If that is where you are |
| 367 | it returns from the function and then stops. In other words, this | 362 | now, it returns from the function and then stops. In other words, this |
| 368 | command does not exit the currently executing function unless you are | 363 | command does not exit the currently executing function unless you are |
| 369 | positioned after the last sexp. | 364 | positioned after the last sexp. |
| 370 | 365 | ||
| 371 | The @kbd{i} command steps into the function or macro called by the list | 366 | The @kbd{i} command steps into the function or macro called by the list |
| 372 | form after point. Note that the form need not be the one about to be | 367 | form after point, and stops at its first stop point. Note that the form |
| 373 | evaluated. But if the form is a function call about to be evaluated, | 368 | need not be the one about to be evaluated. But if the form is a |
| 374 | remember to use this command before any of the arguments are evaluated, | 369 | function call about to be evaluated, remember to use this command before |
| 375 | since otherwise it will be too late. | 370 | any of the arguments are evaluated, since otherwise it will be too late. |
| 376 | 371 | ||
| 377 | The @kbd{i} command instruments the function or macro it's supposed to | 372 | The @kbd{i} command instruments the function or macro it's supposed to |
| 378 | step into, if it isn't instrumented already. This is convenient, but keep | 373 | step into, if it isn't instrumented already. This is convenient, but keep |
| @@ -418,7 +413,7 @@ The backtrace buffer is killed automatically when you continue | |||
| 418 | execution. | 413 | execution. |
| 419 | @end table | 414 | @end table |
| 420 | 415 | ||
| 421 | >From the Edebug recursive edit, you may invoke commands that activate | 416 | From the Edebug recursive edit, you may invoke commands that activate |
| 422 | Edebug again recursively. Any time Edebug is active, you can quit to | 417 | Edebug again recursively. Any time Edebug is active, you can quit to |
| 423 | the top level with @kbd{q} or abort one recursive edit level with | 418 | the top level with @kbd{q} or abort one recursive edit level with |
| 424 | @kbd{C-]}. You can display a backtrace of all the | 419 | @kbd{C-]}. You can display a backtrace of all the |
| @@ -485,9 +480,10 @@ Edebug always stops or pauses at a breakpoint except when the Edebug | |||
| 485 | mode is Go-nonstop. In that mode, it ignores breakpoints entirely. | 480 | mode is Go-nonstop. In that mode, it ignores breakpoints entirely. |
| 486 | 481 | ||
| 487 | To find out where your breakpoints are, use the @kbd{B} command, which | 482 | To find out where your breakpoints are, use the @kbd{B} command, which |
| 488 | moves point to the next breakpoint in the definition following point, or | 483 | moves point to the next breakpoint following point, within the same |
| 489 | to the first breakpoint if there are no following breakpoints. This | 484 | function, or to the first breakpoint if there are no following |
| 490 | command does not continue execution---it just moves point in the buffer. | 485 | breakpoints. This command does not continue execution---it just moves |
| 486 | point in the buffer. | ||
| 491 | 487 | ||
| 492 | @menu | 488 | @menu |
| 493 | * Global Break Condition:: Breaking on an event. | 489 | * Global Break Condition:: Breaking on an event. |
| @@ -561,31 +557,24 @@ occurred. For an unbound variable error, the last known stop point | |||
| 561 | might be quite distant from the offending variable reference. In that | 557 | might be quite distant from the offending variable reference. In that |
| 562 | case you might want to display a full backtrace (@pxref{Edebug Misc}). | 558 | case you might want to display a full backtrace (@pxref{Edebug Misc}). |
| 563 | 559 | ||
| 560 | @c Edebug should be changed for the following: -- dan | ||
| 564 | If you change @code{debug-on-error} or @code{debug-on-quit} while | 561 | If you change @code{debug-on-error} or @code{debug-on-quit} while |
| 565 | Edebug is active, these changes will be forgotten when Edebug becomes | 562 | Edebug is active, these changes will be forgotten when Edebug becomes |
| 566 | inactive. Furthermore, during Edebug's recursive edit, these variables | 563 | inactive. Furthermore, during Edebug's recursive edit, these variables |
| 567 | are bound to the values they had outside of Edebug. | 564 | are bound to the values they had outside of Edebug. |
| 568 | 565 | ||
| 569 | @ignore @c I don't want to document something that works only partly -- rms. | ||
| 570 | Edebug can also trap signals even if they are handled. If | ||
| 571 | @code{debug-on-error} is a list of signal names, Edebug will stop when | ||
| 572 | any of these errors are signaled. Edebug shows you the last known stop | ||
| 573 | point just as for unhandled errors. After you continue execution, the | ||
| 574 | error is signaled again (but without being caught by Edebug). Edebug | ||
| 575 | can only trap errors that are handled if they are signaled in Lisp code | ||
| 576 | (not subroutines) since it does so by temporarily replacing the | ||
| 577 | @code{signal} function. | ||
| 578 | @end ignore | ||
| 579 | |||
| 580 | @node Edebug Views | 566 | @node Edebug Views |
| 581 | @subsection Edebug Views | 567 | @subsection Edebug Views |
| 582 | 568 | ||
| 583 | These Edebug commands let you view aspects of the buffer and window | 569 | These Edebug commands let you view aspects of the buffer and window |
| 584 | status that obtained before entry to Edebug. | 570 | status that obtained before entry to Edebug. The outside window |
| 571 | configuration is the collection of windows and contents that were in | ||
| 572 | effect outside of Edebug. | ||
| 585 | 573 | ||
| 586 | @table @kbd | 574 | @table @kbd |
| 587 | @item v | 575 | @item v |
| 588 | View the outside window configuration (@code{edebug-view-outside}). | 576 | Temporarily view the outside window configuration |
| 577 | (@code{edebug-view-outside}). | ||
| 589 | 578 | ||
| 590 | @item p | 579 | @item p |
| 591 | Temporarily display the outside current buffer with point at its outside | 580 | Temporarily display the outside current buffer with point at its outside |
| @@ -599,18 +588,13 @@ displaying the same buffer, that window will be used instead to display | |||
| 599 | the current definition in the future. | 588 | the current definition in the future. |
| 600 | 589 | ||
| 601 | @item W | 590 | @item W |
| 602 | Forget the saved outside window configuration---so that the current | 591 | @c Its function is not simply to forget the saved configuration -- dan |
| 603 | window configuration will remain unchanged when you next exit Edebug (by | 592 | Toggle whether Edebug saves and restores the outside window |
| 604 | continuing the program). Also toggle the @code{edebug-save-windows} | 593 | configuration (@code{edebug-toggle-save-windows}). |
| 605 | variable. | 594 | |
| 606 | @ignore @c This text is implementation-oriented and doesn't emphasize | 595 | With a prefix argument, @code{W} only toggles saving and restoring of |
| 607 | what users really want to know. | 596 | the selected window. To specify a window that is not displaying the |
| 608 | Toggle the @code{edebug-save-windows} variable which indicates whether | 597 | source code buffer, you must use @kbd{C-x X W} from the global keymap. |
| 609 | the outside window configuration is saved and restored | ||
| 610 | (@code{edebug-toggle-save-windows}). Also, each time it is toggled on, | ||
| 611 | make the outside window configuration the same as the current window | ||
| 612 | configuration. | ||
| 613 | @end ignore | ||
| 614 | @end table | 598 | @end table |
| 615 | 599 | ||
| 616 | You can view the outside window configuration with @kbd{v} or just | 600 | You can view the outside window configuration with @kbd{v} or just |
| @@ -618,18 +602,13 @@ bounce to the point in the current buffer with @kbd{p}, even if | |||
| 618 | it is not normally displayed. After moving point, you may wish to jump | 602 | it is not normally displayed. After moving point, you may wish to jump |
| 619 | back to the stop point with @kbd{w} from a source code buffer. | 603 | back to the stop point with @kbd{w} from a source code buffer. |
| 620 | 604 | ||
| 621 | @ignore I don't understand this -- rms | 605 | Each time you use @kbd{W} to turn saving @emph{off}, Edebug forgets the |
| 622 | If you type @kbd{W} twice, Edebug continues saving and restoring an | 606 | saved outside window configuration---so that even if you turn saving |
| 623 | outside window configuration, but updates it to match the current | 607 | back @emph{on}, the current window configuration remains unchanged when |
| 624 | configuration. You can use this to add another buffer to be displayed | 608 | you next exit Edebug (by continuing the program). However, the |
| 625 | whenever Edebug is active. However, the automatic redisplay of | 609 | automatic redisplay of @samp{*edebug*} and @samp{*edebug-trace*} may |
| 626 | @samp{*edebug*} and @samp{*edebug-trace*} may conflict with the buffers | 610 | conflict with the buffers you wish to see unless you have enough windows |
| 627 | you wish to see unless you have enough windows open. | 611 | open. |
| 628 | |||
| 629 | With a prefix argument, @code{W} only toggles saving and restoring of | ||
| 630 | the selected window. To specify a window that is not displaying the | ||
| 631 | source code buffer, you must use @kbd{C-x X W} from the global keymap. | ||
| 632 | @end ignore | ||
| 633 | 612 | ||
| 634 | @node Edebug Eval | 613 | @node Edebug Eval |
| 635 | @subsection Evaluation | 614 | @subsection Evaluation |
| @@ -690,7 +669,7 @@ Evaluate the expression before point, in the context outside of Edebug | |||
| 690 | (@code{edebug-eval-last-sexp}). | 669 | (@code{edebug-eval-last-sexp}). |
| 691 | 670 | ||
| 692 | @item C-c C-u | 671 | @item C-c C-u |
| 693 | Build a new evaluation list from contents of the buffer | 672 | Build a new evaluation list from the contents of the buffer |
| 694 | (@code{edebug-update-eval-list}). | 673 | (@code{edebug-update-eval-list}). |
| 695 | 674 | ||
| 696 | @item C-c C-d | 675 | @item C-c C-d |
| @@ -717,17 +696,18 @@ more Lisp expressions. Groups are separated by comment lines. | |||
| 717 | 696 | ||
| 718 | The command @kbd{C-c C-u} (@code{edebug-update-eval-list}) rebuilds the | 697 | The command @kbd{C-c C-u} (@code{edebug-update-eval-list}) rebuilds the |
| 719 | evaluation list, scanning the buffer and using the first expression of | 698 | evaluation list, scanning the buffer and using the first expression of |
| 720 | each group. | 699 | each group. (The idea is that the second expression of the group is the |
| 700 | value previously computed and displayed.) | ||
| 721 | 701 | ||
| 722 | Be careful not to add expressions that execute instrumented code since | 702 | Be careful not to add expressions that execute instrumented code since |
| 723 | that would cause an infinite loop. | 703 | that would cause an infinite loop. |
| 724 | @c There ought to be a way to fix this. | 704 | @c There ought to be a way to fix this. |
| 725 | 705 | ||
| 726 | Redisplaying the evaluation list works by inserting each expression in | 706 | Each entry to Edebug redisplays the evaluation list by inserting each |
| 727 | the buffer, followed by its current value. It also inserts comment | 707 | expression in the buffer, followed by its current value. It also |
| 728 | lines so that each expression becomes its own group. Thus, if you type | 708 | inserts comment lines so that each expression becomes its own group. |
| 729 | @kbd{C-c C-u} again without changing the buffer text, the evaluation | 709 | Thus, if you type @kbd{C-c C-u} again without changing the buffer text, |
| 730 | list is effectively unchanged. | 710 | the evaluation list is effectively unchanged. |
| 731 | 711 | ||
| 732 | If an error occurs during an evaluation from the evaluation list, the | 712 | If an error occurs during an evaluation from the evaluation list, the |
| 733 | error message is displayed in a string as if it were the result. | 713 | error message is displayed in a string as if it were the result. |
| @@ -817,7 +797,7 @@ for details. | |||
| 817 | @subsection Trace Buffer | 797 | @subsection Trace Buffer |
| 818 | @cindex trace buffer | 798 | @cindex trace buffer |
| 819 | 799 | ||
| 820 | Edebug can record an execution trace in a buffer named | 800 | Edebug can record an execution trace, storing it in a buffer named |
| 821 | @samp{*edebug-trace*}. This is a log of function calls and returns, | 801 | @samp{*edebug-trace*}. This is a log of function calls and returns, |
| 822 | showing the function names and their arguments and values. To enable | 802 | showing the function names and their arguments and values. To enable |
| 823 | trace recording, set @code{edebug-trace} to a non-@code{nil} value. | 803 | trace recording, set @code{edebug-trace} to a non-@code{nil} value. |
| @@ -851,7 +831,7 @@ to put in the trace buffer. All the arguments are evaluated. | |||
| 851 | @defun edebug-trace format-string &rest format-args | 831 | @defun edebug-trace format-string &rest format-args |
| 852 | This function inserts text in the trace buffer. It computes the text | 832 | This function inserts text in the trace buffer. It computes the text |
| 853 | with @code{(apply 'format @var{format-string} @var{format-args})}. | 833 | with @code{(apply 'format @var{format-string} @var{format-args})}. |
| 854 | It also inserts a newline to separate entries. | 834 | It also appends a newline to separate entries. |
| 855 | @end defun | 835 | @end defun |
| 856 | 836 | ||
| 857 | @code{edebug-tracing} and @code{edebug-trace} insert lines in the trace | 837 | @code{edebug-tracing} and @code{edebug-trace} insert lines in the trace |
| @@ -860,11 +840,6 @@ buffer even if Edebug is not active. | |||
| 860 | Adding text to the trace buffer also scrolls its window to show the | 840 | Adding text to the trace buffer also scrolls its window to show the |
| 861 | last lines inserted. | 841 | last lines inserted. |
| 862 | 842 | ||
| 863 | @ignore @c too vague | ||
| 864 | There may be some display problems if you use | ||
| 865 | tracing along with the evaluation list. | ||
| 866 | @end ignore | ||
| 867 | |||
| 868 | @node Coverage Testing | 843 | @node Coverage Testing |
| 869 | @subsection Coverage Testing | 844 | @subsection Coverage Testing |
| 870 | 845 | ||
| @@ -883,9 +858,9 @@ displays both the frequency data and the coverage data (if recorded). | |||
| 883 | This command displays the frequency count data for each line of the | 858 | This command displays the frequency count data for each line of the |
| 884 | current definition. | 859 | current definition. |
| 885 | 860 | ||
| 886 | The frequency counts appear comment lines after each line of code, and | 861 | The frequency counts appear as comment lines after each line of code, and |
| 887 | you can undo all insertions with one @code{undo} command. The counts | 862 | you can undo all insertions with one @code{undo} command. The counts |
| 888 | are appear under the @kbd{(} before an expression or the @kbd{)} after | 863 | appear under the @kbd{(} before an expression or the @kbd{)} after |
| 889 | an expression, or on the last character of a symbol. Values do not appear if | 864 | an expression, or on the last character of a symbol. Values do not appear if |
| 890 | they are equal to the previous count on the same line. | 865 | they are equal to the previous count on the same line. |
| 891 | 866 | ||
| @@ -913,10 +888,10 @@ the breakpoint is reached, the frequency data looks like this: | |||
| 913 | ;# 0 | 888 | ;# 0 |
| 914 | @end example | 889 | @end example |
| 915 | 890 | ||
| 916 | The comment lines show that @code{fac} has been called 6 times. The | 891 | The comment lines show that @code{fac} was called 6 times. The |
| 917 | first @code{if} statement has returned 5 times with the same result each | 892 | first @code{if} statement returned 5 times with the same result each |
| 918 | time; the same is true of the condition on the second @code{if}. | 893 | time; the same is true of the condition on the second @code{if}. |
| 919 | The recursive call of @code{fac} has not returned at all. | 894 | The recursive call of @code{fac} did not return at all. |
| 920 | 895 | ||
| 921 | 896 | ||
| 922 | @node The Outside Context | 897 | @node The Outside Context |
| @@ -929,10 +904,6 @@ buffer, by temporarily restoring the outside context. This section | |||
| 929 | explains precisely what context Edebug restores, and how Edebug fails to | 904 | explains precisely what context Edebug restores, and how Edebug fails to |
| 930 | be completely transparent. | 905 | be completely transparent. |
| 931 | 906 | ||
| 932 | @c This can be fixed and should be | ||
| 933 | The same mechanism that avoids masking certain variable's outside values | ||
| 934 | also currently makes it impossible to set these variables within Edebug. | ||
| 935 | |||
| 936 | @menu | 907 | @menu |
| 937 | * Checking Whether to Stop:: When Edebug decides what to do. | 908 | * Checking Whether to Stop:: When Edebug decides what to do. |
| 938 | * Edebug Display Update:: When Edebug updates the display. | 909 | * Edebug Display Update:: When Edebug updates the display. |
| @@ -942,8 +913,9 @@ also currently makes it impossible to set these variables within Edebug. | |||
| 942 | @node Checking Whether to Stop | 913 | @node Checking Whether to Stop |
| 943 | @subsubsection Checking Whether to Stop | 914 | @subsubsection Checking Whether to Stop |
| 944 | 915 | ||
| 945 | Whenever Edebug is entered just to think about whether to take some | 916 | Whenever Edebug is entered, it needs to save and restore certain data |
| 946 | action, it needs to save and restore certain data. | 917 | before even deciding whether to make trace information or stop the |
| 918 | program. | ||
| 947 | 919 | ||
| 948 | @itemize @bullet | 920 | @itemize @bullet |
| 949 | @item | 921 | @item |
| @@ -962,11 +934,12 @@ Edebug is active, @code{executing-macro} is bound to | |||
| 962 | @node Edebug Display Update | 934 | @node Edebug Display Update |
| 963 | @subsubsection Edebug Display Update | 935 | @subsubsection Edebug Display Update |
| 964 | 936 | ||
| 937 | @c This paragraph is not filled, because LaLiberte's conversion script | ||
| 938 | @c needs an xref to be on just one line. | ||
| 965 | When Edebug needs to display something (e.g., in trace mode), it saves | 939 | When Edebug needs to display something (e.g., in trace mode), it saves |
| 966 | the current window configuration from ``outside'' Edebug (@pxref{Window | 940 | the current window configuration from ``outside'' Edebug |
| 967 | Configurations,,, elisp, GNU Emacs Lisp Reference Manual}). When | 941 | (@pxref{Window Configurations}). When you exit Edebug (by continuing |
| 968 | you exit Edebug (by continuing the program), it restores the previous | 942 | the program), it restores the previous window configuration. |
| 969 | window configuration. | ||
| 970 | 943 | ||
| 971 | Emacs redisplays only when it pauses. Usually, when you continue | 944 | Emacs redisplays only when it pauses. Usually, when you continue |
| 972 | execution, the program comes back into Edebug at a breakpoint or after | 945 | execution, the program comes back into Edebug at a breakpoint or after |
| @@ -1000,7 +973,6 @@ The window start and horizontal scrolling of the source code buffer are | |||
| 1000 | not restored, however, so that the display remains coherent within Edebug. | 973 | not restored, however, so that the display remains coherent within Edebug. |
| 1001 | 974 | ||
| 1002 | @item | 975 | @item |
| 1003 | @vindex edebug-save-displayed-buffer-points | ||
| 1004 | The value of point in each displayed buffer is saved and restored if | 976 | The value of point in each displayed buffer is saved and restored if |
| 1005 | @code{edebug-save-displayed-buffer-points} is non-@code{nil}. | 977 | @code{edebug-save-displayed-buffer-points} is non-@code{nil}. |
| 1006 | 978 | ||
| @@ -1035,6 +1007,11 @@ The key sequence returned by @code{this-command-keys} is changed by | |||
| 1035 | executing commands within Edebug and there is no way to reset | 1007 | executing commands within Edebug and there is no way to reset |
| 1036 | the key sequence from Lisp. | 1008 | the key sequence from Lisp. |
| 1037 | 1009 | ||
| 1010 | Edebug cannot save and restore the value of | ||
| 1011 | @code{unread-command-events}. Entering Edebug while this variable has a | ||
| 1012 | nontrivial value can interfere with execution of the program you are | ||
| 1013 | debugging. | ||
| 1014 | |||
| 1038 | @item | 1015 | @item |
| 1039 | Complex commands executed while in Edebug are added to the variable | 1016 | Complex commands executed while in Edebug are added to the variable |
| 1040 | @code{command-history}. In rare cases this can alter execution. | 1017 | @code{command-history}. In rare cases this can alter execution. |
| @@ -1064,7 +1041,7 @@ way to tell which subexpressions of the macro call are forms to be | |||
| 1064 | evaluated. (Evaluation may occur explicitly in the macro body, or when | 1041 | evaluated. (Evaluation may occur explicitly in the macro body, or when |
| 1065 | the resulting expansion is evaluated, or any time later.) You must | 1042 | the resulting expansion is evaluated, or any time later.) You must |
| 1066 | explain the format of calls to each macro to enable Edebug to handle it. | 1043 | explain the format of calls to each macro to enable Edebug to handle it. |
| 1067 | To do this, use @code{def-edebug-form-spec} to define the format of | 1044 | To do this, use @code{def-edebug-spec} to define the format of |
| 1068 | calls to a given macro. | 1045 | calls to a given macro. |
| 1069 | 1046 | ||
| 1070 | @deffn Macro def-edebug-spec macro specification | 1047 | @deffn Macro def-edebug-spec macro specification |
| @@ -1114,7 +1091,6 @@ described in the following sections. | |||
| 1114 | @menu | 1091 | @menu |
| 1115 | * Specification List:: How to specify complex patterns of evaluation. | 1092 | * Specification List:: How to specify complex patterns of evaluation. |
| 1116 | * Backtracking:: What Edebug does when matching fails. | 1093 | * Backtracking:: What Edebug does when matching fails. |
| 1117 | @c * Debugging Backquote:: Debugging Backquote | ||
| 1118 | * Specification Examples:: To help understand specifications. | 1094 | * Specification Examples:: To help understand specifications. |
| 1119 | @end menu | 1095 | @end menu |
| 1120 | 1096 | ||
| @@ -1150,7 +1126,9 @@ their meanings: | |||
| 1150 | 1126 | ||
| 1151 | @table @code | 1127 | @table @code |
| 1152 | @item sexp | 1128 | @item sexp |
| 1153 | A single unevaluated Lisp object object. | 1129 | A single Lisp object, not unevaluated. |
| 1130 | @c "unevaluated expression" is not meaningful, because | ||
| 1131 | @c an expression is a Lisp object intended for evaluation. | ||
| 1154 | 1132 | ||
| 1155 | @item form | 1133 | @item form |
| 1156 | A single evaluated expression, which is instrumented. | 1134 | A single evaluated expression, which is instrumented. |
| @@ -1246,16 +1224,8 @@ Otherwise, the symbol should be a predicate. The predicate is called | |||
| 1246 | with the argument and the specification fails if the predicate returns | 1224 | with the argument and the specification fails if the predicate returns |
| 1247 | @code{nil}. In either case, that argument is not instrumented. | 1225 | @code{nil}. In either case, that argument is not instrumented. |
| 1248 | 1226 | ||
| 1249 | @findex keywordp | ||
| 1250 | @findex lambda-list-keywordp | ||
| 1251 | Some suitable predicates include @code{symbolp}, @code{integerp}, | 1227 | Some suitable predicates include @code{symbolp}, @code{integerp}, |
| 1252 | @code{stringp}, @code{vectorp}, and @code{atom}. | 1228 | @code{stringp}, @code{vectorp}, and @code{atom}. |
| 1253 | @ignore | ||
| 1254 | , @code{keywordp}, and | ||
| 1255 | @code{lambda-list-keywordp}. The last two, defined in @file{edebug.el}, | ||
| 1256 | test whether the argument is a symbol starting with @samp{@code{:}} and | ||
| 1257 | @samp{@code{&}} respectively. | ||
| 1258 | @end ignore | ||
| 1259 | 1229 | ||
| 1260 | @item [@var{elements}@dots{}] | 1230 | @item [@var{elements}@dots{}] |
| 1261 | @cindex [@dots{}] (Edebug) | 1231 | @cindex [@dots{}] (Edebug) |
| @@ -1267,12 +1237,6 @@ The argument should be a symbol named @var{string}. This specification | |||
| 1267 | is equivalent to the quoted symbol, @code{'@var{symbol}}, where the name | 1237 | is equivalent to the quoted symbol, @code{'@var{symbol}}, where the name |
| 1268 | of @var{symbol} is the @var{string}, but the string form is preferred. | 1238 | of @var{symbol} is the @var{string}, but the string form is preferred. |
| 1269 | 1239 | ||
| 1270 | @ignore | ||
| 1271 | @item '@var{symbol} @r{or} (quote @var{symbol}) | ||
| 1272 | The argument should be the symbol @var{symbol}. But use a string | ||
| 1273 | specification instead. | ||
| 1274 | @end ignore | ||
| 1275 | |||
| 1276 | @item (vector @var{elements}@dots{}) | 1240 | @item (vector @var{elements}@dots{}) |
| 1277 | The argument should be a vector whose elements must match the | 1241 | The argument should be a vector whose elements must match the |
| 1278 | @var{elements} in the specification. See the backquote example below. | 1242 | @var{elements} in the specification. See the backquote example below. |
| @@ -1291,9 +1255,9 @@ This is useful in recursive specifications such as in the backquote | |||
| 1291 | example below. Also see the description of a @code{nil} specification | 1255 | example below. Also see the description of a @code{nil} specification |
| 1292 | above for terminating such recursion. | 1256 | above for terminating such recursion. |
| 1293 | 1257 | ||
| 1294 | Note that a sublist specification of the form @code{(specs . nil)} | 1258 | Note that a sublist specification written as @code{(specs . nil)} |
| 1295 | means the same as @code{(specs)}, and @code{(specs . | 1259 | is equivalent to @code{(specs)}, and @code{(specs . |
| 1296 | (sublist-elements@dots{}))} means the same as @code{(specs | 1260 | (sublist-elements@dots{}))} is equivalent to @code{(specs |
| 1297 | sublist-elements@dots{})}. | 1261 | sublist-elements@dots{})}. |
| 1298 | @end table | 1262 | @end table |
| 1299 | 1263 | ||
| @@ -1319,12 +1283,11 @@ than once. | |||
| 1319 | @item arg | 1283 | @item arg |
| 1320 | The argument, a symbol, is the name of an argument of the defining form. | 1284 | The argument, a symbol, is the name of an argument of the defining form. |
| 1321 | However, lambda list keywords (symbols starting with @samp{@code{&}}) | 1285 | However, lambda list keywords (symbols starting with @samp{@code{&}}) |
| 1322 | are not allowed. See @code{lambda-list} and the example below. | 1286 | are not allowed. |
| 1323 | 1287 | ||
| 1324 | @item lambda-list | 1288 | @item lambda-list |
| 1325 | @cindex lambda-list (Edebug) | 1289 | @cindex lambda-list (Edebug) |
| 1326 | This matches a lambda list---the argument list of a lambda expression. | 1290 | This matches a lambda list---the argument list of a lambda expression. |
| 1327 | The argument should be a list of symbols. | ||
| 1328 | 1291 | ||
| 1329 | @item def-body | 1292 | @item def-body |
| 1330 | The argument is the body of code in a definition. This is like | 1293 | The argument is the body of code in a definition. This is like |
| @@ -1380,94 +1343,6 @@ Third, backtracking may be explicitly disabled by using the | |||
| 1380 | @code{gate} specification. This is useful when you know that | 1343 | @code{gate} specification. This is useful when you know that |
| 1381 | no higher alternatives may apply. | 1344 | no higher alternatives may apply. |
| 1382 | 1345 | ||
| 1383 | @ignore | ||
| 1384 | @node Debugging Backquote | ||
| 1385 | @subsubsection Debugging Backquote | ||
| 1386 | |||
| 1387 | @findex ` (Edebug) | ||
| 1388 | @cindex backquote (Edebug) | ||
| 1389 | Backquote (@kbd{`}) is a macro that results in an expression that may or | ||
| 1390 | may not be evaluated. It is often used to simplify the definition of a | ||
| 1391 | macro to return an expression to be evaluated, but Edebug cannot know | ||
| 1392 | whether the resyult of backquote will be used in any other way. | ||
| 1393 | |||
| 1394 | The forms inside unquotes (@code{,} and @code{,@@}) are evaluated, and | ||
| 1395 | Edebug instruments them. | ||
| 1396 | |||
| 1397 | Edebug supports nested backquotes, but there is a limit on the support | ||
| 1398 | of quotes inside of backquotes. Forms quoted with @code{'} are not | ||
| 1399 | normally evaluated, but if the quoted form appears immediately within | ||
| 1400 | @code{,} and @code{,@@} forms, Edebug treats this as a backquoted form | ||
| 1401 | at the next higher level (even if there is not a next higher level; this | ||
| 1402 | is difficult to fix). | ||
| 1403 | |||
| 1404 | @findex edebug-` | ||
| 1405 | If the backquoted forms are code to be evaluated, you can have Edebug | ||
| 1406 | instrument them by using @code{edebug-`} instead of the regular | ||
| 1407 | @code{`}. Unquoting forms can be used inside @code{edebug-`} anywhere a | ||
| 1408 | form is normally allowed. But @code{(, @var{form})} may be used in two | ||
| 1409 | other places specially recognized by Edebug: wherever a predicate | ||
| 1410 | specification would match, and at the head of a list form where the | ||
| 1411 | function name normally appears. The @var{form} inside a spliced | ||
| 1412 | unquote, @code{(,@@ @var{form})}, will be instrumented, but the unquote | ||
| 1413 | form itself will not be instrumented since this would interfere with the | ||
| 1414 | splicing. | ||
| 1415 | |||
| 1416 | There is one other complication with using @code{edebug-`}. If the | ||
| 1417 | @code{edebug-`} call is in a macro and the macro may be called from code | ||
| 1418 | that is also instrumented, and if unquoted forms contain any macro | ||
| 1419 | arguments bound to instrumented forms, then you should modify the | ||
| 1420 | specification for the macro as follows: the specifications for those | ||
| 1421 | arguments must use @code{def-form} instead of @code{form}. (This is to | ||
| 1422 | reestablish the Edebugging context for those external forms.) | ||
| 1423 | |||
| 1424 | For example, the @code{for} macro (@pxref{Problems with Macros,,, elisp, | ||
| 1425 | Emacs Lisp Reference Manual}) is shown here but with @code{edebug-`} | ||
| 1426 | substituted for regular @code{`}. | ||
| 1427 | |||
| 1428 | @example | ||
| 1429 | (defmacro inc (var) | ||
| 1430 | (list 'setq var (list '1+ var))) | ||
| 1431 | |||
| 1432 | (defmacro for (var from init to final do &rest body) | ||
| 1433 | (let ((tempvar (make-symbol "max"))) | ||
| 1434 | (edebug-` (let (((, var) (, init)) | ||
| 1435 | ((, tempvar) (, final))) | ||
| 1436 | (while (<= (, var) (, tempvar)) | ||
| 1437 | (,@ body) | ||
| 1438 | (inc (, var))))))) | ||
| 1439 | @end example | ||
| 1440 | |||
| 1441 | Here is the corresponding modified Edebug specification and a | ||
| 1442 | call of the macro: | ||
| 1443 | |||
| 1444 | @example | ||
| 1445 | (def-edebug-spec for | ||
| 1446 | (symbolp "from" def-form "to" def-form "do" &rest def-form)) | ||
| 1447 | |||
| 1448 | (let ((n 5)) | ||
| 1449 | (for i from n to (* n (+ n 1)) do | ||
| 1450 | (message "%s" i))) | ||
| 1451 | @end example | ||
| 1452 | |||
| 1453 | After instrumenting the @code{for} macro and the macro call, Edebug | ||
| 1454 | first steps to the beginning of the macro call, then into the macro | ||
| 1455 | body, then through each of the unquoted expressions in the backquote | ||
| 1456 | showing the expressions that will be embedded. Then when the macro | ||
| 1457 | expansion is evaluated, Edebug will step through the @code{let} form and | ||
| 1458 | each time it gets to an unquoted form, it will jump back to an argument | ||
| 1459 | of the macro call to step through that expression. Finally stepping | ||
| 1460 | will continue after the macro call. Even more convoluted execution | ||
| 1461 | paths may result when using anonymous functions. | ||
| 1462 | |||
| 1463 | @vindex edebug-unwrap-results | ||
| 1464 | When the result of an expression is an instrumented expression, it is | ||
| 1465 | difficult to see the expression inside the instrumentation. So | ||
| 1466 | you may want to set the option @code{edebug-unwrap-results} to a | ||
| 1467 | non-@code{nil} value while debugging such expressions, but it would slow | ||
| 1468 | Edebug down to always do this. | ||
| 1469 | |||
| 1470 | @end ignore | ||
| 1471 | @node Specification Examples | 1346 | @node Specification Examples |
| 1472 | @subsubsection Specification Examples | 1347 | @subsubsection Specification Examples |
| 1473 | 1348 | ||
| @@ -1492,11 +1367,11 @@ specifications. It is necessary to handle interactive forms specially | |||
| 1492 | since an expression argument it is actually evaluated outside of the | 1367 | since an expression argument it is actually evaluated outside of the |
| 1493 | function body. | 1368 | function body. |
| 1494 | 1369 | ||
| 1495 | @example | 1370 | @smallexample |
| 1496 | (def-edebug-spec defmacro defun) ; @r{Indirect ref to @code{defun} spec} | 1371 | (def-edebug-spec defmacro defun) ; @r{Indirect ref to @code{defun} spec.} |
| 1497 | (def-edebug-spec defun | 1372 | (def-edebug-spec defun |
| 1498 | (&define name lambda-list | 1373 | (&define name lambda-list |
| 1499 | [&optional stringp] ; @r{Match the doc string, if present.} | 1374 | [&optional stringp] ; @r{Match the doc string, if present.} |
| 1500 | [&optional ("interactive" interactive)] | 1375 | [&optional ("interactive" interactive)] |
| 1501 | def-body)) | 1376 | def-body)) |
| 1502 | 1377 | ||
| @@ -1508,7 +1383,7 @@ function body. | |||
| 1508 | 1383 | ||
| 1509 | (def-edebug-spec interactive | 1384 | (def-edebug-spec interactive |
| 1510 | (&optional &or stringp def-form)) ; @r{Notice: @code{def-form}} | 1385 | (&optional &or stringp def-form)) ; @r{Notice: @code{def-form}} |
| 1511 | @end example | 1386 | @end smallexample |
| 1512 | 1387 | ||
| 1513 | The specification for backquote below illustrates how to match | 1388 | The specification for backquote below illustrates how to match |
| 1514 | dotted lists and use @code{nil} to terminate recursion. It also | 1389 | dotted lists and use @code{nil} to terminate recursion. It also |
| @@ -1516,15 +1391,15 @@ illustrates how components of a vector may be matched. (The actual | |||
| 1516 | specification defined by Edebug does not support dotted lists because | 1391 | specification defined by Edebug does not support dotted lists because |
| 1517 | doing so causes very deep recursion that could fail.) | 1392 | doing so causes very deep recursion that could fail.) |
| 1518 | 1393 | ||
| 1519 | @example | 1394 | @smallexample |
| 1520 | (def-edebug-spec ` (backquote-form)) ;; alias just for clarity | 1395 | (def-edebug-spec ` (backquote-form)) ; @r{Alias just for clarity.} |
| 1521 | 1396 | ||
| 1522 | (def-edebug-spec backquote-form | 1397 | (def-edebug-spec backquote-form |
| 1523 | (&or ([&or "," ",@@"] &or ("quote" backquote-form) form) | 1398 | (&or ([&or "," ",@@"] &or ("quote" backquote-form) form) |
| 1524 | (backquote-form . [&or nil backquote-form]) | 1399 | (backquote-form . [&or nil backquote-form]) |
| 1525 | (vector &rest backquote-form) | 1400 | (vector &rest backquote-form) |
| 1526 | sexp)) | 1401 | sexp)) |
| 1527 | @end example | 1402 | @end smallexample |
| 1528 | 1403 | ||
| 1529 | 1404 | ||
| 1530 | @node Edebug Options | 1405 | @node Edebug Options |
| @@ -1544,18 +1419,21 @@ but only when you also use Edebug. | |||
| 1544 | @defopt edebug-all-defs | 1419 | @defopt edebug-all-defs |
| 1545 | If this is non-@code{nil}, normal evaluation of defining forms such as | 1420 | If this is non-@code{nil}, normal evaluation of defining forms such as |
| 1546 | @code{defun} and @code{defmacro} instruments them for Edebug. This | 1421 | @code{defun} and @code{defmacro} instruments them for Edebug. This |
| 1547 | applies to @code{eval-defun}, @code{eval-region}, and | 1422 | applies to @code{eval-defun}, @code{eval-region}, @code{eval-buffer}, |
| 1548 | @code{eval-current-buffer}. @xref{Instrumenting}. | 1423 | and @code{eval-current-buffer}. |
| 1424 | |||
| 1425 | Use the command @kbd{M-x edebug-all-defs} to toggle the value of this | ||
| 1426 | option. @xref{Instrumenting}. | ||
| 1549 | @end defopt | 1427 | @end defopt |
| 1550 | 1428 | ||
| 1551 | @defopt edebug-all-forms | 1429 | @defopt edebug-all-forms |
| 1552 | If this is non-@code{nil}, the commands @code{eval-defun}, @code{eval-region}, | 1430 | If this is non-@code{nil}, the commands @code{eval-defun}, |
| 1553 | and @code{eval-current-buffer} instrument all forms, even those that | 1431 | @code{eval-region}, @code{eval-buffer}, and @code{eval-current-buffer} |
| 1554 | don't define anything. | 1432 | instrument all forms, even those that don't define anything. |
| 1433 | This doesn't apply to loading or evaluations in the minibuffer. | ||
| 1555 | 1434 | ||
| 1556 | Use the command @kbd{M-x edebug-all-forms} to toggle the value of this | 1435 | Use the command @kbd{M-x edebug-all-forms} to toggle the value of this |
| 1557 | option. | 1436 | option. @xref{Instrumenting}. |
| 1558 | @xref{Instrumenting}. | ||
| 1559 | @end defopt | 1437 | @end defopt |
| 1560 | 1438 | ||
| 1561 | @defopt edebug-save-windows | 1439 | @defopt edebug-save-windows |
| @@ -1572,12 +1450,13 @@ interactively. @xref{Edebug Display Update}. | |||
| 1572 | @end defopt | 1450 | @end defopt |
| 1573 | 1451 | ||
| 1574 | @defopt edebug-save-displayed-buffer-points | 1452 | @defopt edebug-save-displayed-buffer-points |
| 1575 | If non-@code{nil}, Edebug saves and restores point in all buffers. | 1453 | If this is non-@code{nil}, Edebug saves and restores point in all |
| 1454 | displayed buffers. | ||
| 1576 | 1455 | ||
| 1577 | Saving and restoring point in other buffers is necessary if you are | 1456 | Saving and restoring point in other buffers is necessary if you are |
| 1578 | debugging code that changes the point of a buffer which is displayed in | 1457 | debugging code that changes the point of a buffer which is displayed in |
| 1579 | a non-selected window. If Edebug or the user then selects the window, | 1458 | a non-selected window. If Edebug or the user then selects the window, |
| 1580 | the buffer's point will change to the window's point. | 1459 | point in that buffer will move to the window's value of point. |
| 1581 | 1460 | ||
| 1582 | Saving and restoring point in all buffers is expensive, since it | 1461 | Saving and restoring point in all buffers is expensive, since it |
| 1583 | requires selecting each window twice, so enable this only if you need | 1462 | requires selecting each window twice, so enable this only if you need |
| @@ -1603,8 +1482,7 @@ function entry or exit per line, indented by the recursion level. | |||
| 1603 | 1482 | ||
| 1604 | The default value is @code{nil}. | 1483 | The default value is @code{nil}. |
| 1605 | 1484 | ||
| 1606 | Also see @code{edebug-tracing}. | 1485 | Also see @code{edebug-tracing}, in @xref{Trace Buffer}. |
| 1607 | @xref{Tracing}. | ||
| 1608 | @end defopt | 1486 | @end defopt |
| 1609 | 1487 | ||
| 1610 | @defopt edebug-test-coverage | 1488 | @defopt edebug-test-coverage |
| @@ -1657,20 +1535,12 @@ Errors}. | |||
| 1657 | 1535 | ||
| 1658 | If you change the values of @code{edebug-on-error} or | 1536 | If you change the values of @code{edebug-on-error} or |
| 1659 | @code{edebug-on-quit} while Edebug is active, their values won't be used | 1537 | @code{edebug-on-quit} while Edebug is active, their values won't be used |
| 1660 | until the @emph{next} time Edebug is invoked at a deeper command level. | 1538 | until the @emph{next} time Edebug is invoked via a new command. |
| 1661 | 1539 | @c Not necessarily a deeper command level. | |
| 1662 | @ignore | 1540 | @c A new command is not precisely true, but that is close enough -- dan |
| 1663 | @defopt edebug-unwrap-results | ||
| 1664 | Non-@code{nil} if Edebug should unwrap results of expressions. This is | ||
| 1665 | useful when debugging macros where the results of expressions are | ||
| 1666 | instrumented expressions. But don't do this when results might be | ||
| 1667 | circular, or an infinite loop will result. @xref{Debugging Backquote}. | ||
| 1668 | @end defopt | ||
| 1669 | @end ignore | ||
| 1670 | 1541 | ||
| 1671 | @defopt edebug-global-break-condition | 1542 | @defopt edebug-global-break-condition |
| 1672 | If non-@code{nil}, an expression to test for at every stop point. | 1543 | If non-@code{nil}, an expression to test for at every stop point. |
| 1673 | If the result is non-nil, then break. Errors are ignored. | 1544 | If the result is non-nil, then break. Errors are ignored. |
| 1674 | @xref{Global Break Condition}. | 1545 | @xref{Global Break Condition}. |
| 1675 | @end defopt | 1546 | @end defopt |
| 1676 | |||
diff --git a/lispref/keymaps.texi b/lispref/keymaps.texi index 298397e55ac..02bada65bce 100644 --- a/lispref/keymaps.texi +++ b/lispref/keymaps.texi | |||
| @@ -21,7 +21,6 @@ is found. The whole process is called @dfn{key lookup}. | |||
| 21 | * Inheritance and Keymaps:: How one keymap can inherit the bindings | 21 | * Inheritance and Keymaps:: How one keymap can inherit the bindings |
| 22 | of another keymap. | 22 | of another keymap. |
| 23 | * Prefix Keys:: Defining a key with a keymap as its definition. | 23 | * Prefix Keys:: Defining a key with a keymap as its definition. |
| 24 | * Menu Keymaps:: A keymap can define a menu. | ||
| 25 | * Active Keymaps:: Each buffer has a local keymap | 24 | * Active Keymaps:: Each buffer has a local keymap |
| 26 | to override the standard (global) bindings. | 25 | to override the standard (global) bindings. |
| 27 | A minor mode can also override them. | 26 | A minor mode can also override them. |
| @@ -30,6 +29,7 @@ is found. The whole process is called @dfn{key lookup}. | |||
| 30 | * Changing Key Bindings:: Redefining a key in a keymap. | 29 | * Changing Key Bindings:: Redefining a key in a keymap. |
| 31 | * Key Binding Commands:: Interactive interfaces for redefining keys. | 30 | * Key Binding Commands:: Interactive interfaces for redefining keys. |
| 32 | * Scanning Keymaps:: Looking through all keymaps, for printing help. | 31 | * Scanning Keymaps:: Looking through all keymaps, for printing help. |
| 32 | * Menu Keymaps:: A keymap can define a menu. | ||
| 33 | @end menu | 33 | @end menu |
| 34 | 34 | ||
| 35 | @node Keymap Terminology | 35 | @node Keymap Terminology |
| @@ -62,7 +62,7 @@ used up. | |||
| 62 | 62 | ||
| 63 | If the binding of a key sequence is a keymap, we call the key sequence | 63 | If the binding of a key sequence is a keymap, we call the key sequence |
| 64 | a @dfn{prefix key}. Otherwise, we call it a @dfn{complete key} (because | 64 | a @dfn{prefix key}. Otherwise, we call it a @dfn{complete key} (because |
| 65 | no more characters can be added to it). If the binding is @code{nil}, | 65 | no more events can be added to it). If the binding is @code{nil}, |
| 66 | we call the key @dfn{undefined}. Examples of prefix keys are @kbd{C-c}, | 66 | we call the key @dfn{undefined}. Examples of prefix keys are @kbd{C-c}, |
| 67 | @kbd{C-x}, and @kbd{C-x 4}. Examples of defined complete keys are | 67 | @kbd{C-x}, and @kbd{C-x 4}. Examples of defined complete keys are |
| 68 | @kbd{X}, @key{RET}, and @kbd{C-x 4 C-f}. Examples of undefined complete | 68 | @kbd{X}, @key{RET}, and @kbd{C-x 4 C-f}. Examples of undefined complete |
| @@ -87,7 +87,7 @@ prefix keys for its well-formedness. | |||
| 87 | use for finding key bindings. These are the @dfn{global map}, which is | 87 | use for finding key bindings. These are the @dfn{global map}, which is |
| 88 | shared by all buffers; the @dfn{local keymap}, which is usually | 88 | shared by all buffers; the @dfn{local keymap}, which is usually |
| 89 | associated with a specific major mode; and zero or more @dfn{minor mode | 89 | associated with a specific major mode; and zero or more @dfn{minor mode |
| 90 | keymaps} which belong to currently enabled minor modes. (Not all minor | 90 | keymaps}, which belong to currently enabled minor modes. (Not all minor |
| 91 | modes have keymaps.) The local keymap bindings shadow (i.e., take | 91 | modes have keymaps.) The local keymap bindings shadow (i.e., take |
| 92 | precedence over) the corresponding global bindings. The minor mode | 92 | precedence over) the corresponding global bindings. The minor mode |
| 93 | keymaps shadow both local and global keymaps. @xref{Active Keymaps}, | 93 | keymaps shadow both local and global keymaps. @xref{Active Keymaps}, |
| @@ -105,11 +105,13 @@ remaining elements of the list define the key bindings of the keymap. | |||
| 105 | Use the function @code{keymapp} (see below) to test whether an object is | 105 | Use the function @code{keymapp} (see below) to test whether an object is |
| 106 | a keymap. | 106 | a keymap. |
| 107 | 107 | ||
| 108 | An ordinary element is a cons cell of the form @code{(@var{type} .@: | 108 | Each ordinary binding applies to events of a particular @dfn{event |
| 109 | @var{binding})}. This specifies one binding which applies to events of | 109 | type}, which is always a character or a symbol. @xref{Classifying |
| 110 | type @var{type}. Each ordinary binding applies to events of a | 110 | Events}. |
| 111 | particular @dfn{event type}, which is always a character or a symbol. | 111 | |
| 112 | @xref{Classifying Events}. | 112 | An ordinary element of a keymap is a cons cell of the form |
| 113 | @code{(@var{type} .@: @var{binding})}. This specifies one binding, for | ||
| 114 | events of type @var{type}. | ||
| 113 | 115 | ||
| 114 | @cindex default key binding | 116 | @cindex default key binding |
| 115 | @c Emacs 19 feature | 117 | @c Emacs 19 feature |
| @@ -122,7 +124,7 @@ keymap. | |||
| 122 | 124 | ||
| 123 | If an element of a keymap is a vector, the vector counts as bindings | 125 | If an element of a keymap is a vector, the vector counts as bindings |
| 124 | for all the @sc{ASCII} characters; vector element @var{n} is the binding | 126 | for all the @sc{ASCII} characters; vector element @var{n} is the binding |
| 125 | for the character with code @var{n}. This is a more compact way to | 127 | for the character with code @var{n}. This is a compact way to |
| 126 | record lots of bindings. A keymap with such a vector is called a | 128 | record lots of bindings. A keymap with such a vector is called a |
| 127 | @dfn{full keymap}. Other keymaps are called @dfn{sparse keymaps}. | 129 | @dfn{full keymap}. Other keymaps are called @dfn{sparse keymaps}. |
| 128 | 130 | ||
| @@ -184,7 +186,7 @@ lisp-mode-map | |||
| 184 | 186 | ||
| 185 | @defun keymapp object | 187 | @defun keymapp object |
| 186 | This function returns @code{t} if @var{object} is a keymap, @code{nil} | 188 | This function returns @code{t} if @var{object} is a keymap, @code{nil} |
| 187 | otherwise. Practically speaking, this function tests for a list whose | 189 | otherwise. More precisely, this function tests for a list whose |
| 188 | @sc{car} is @code{keymap}. | 190 | @sc{car} is @code{keymap}. |
| 189 | 191 | ||
| 190 | @example | 192 | @example |
| @@ -206,8 +208,8 @@ otherwise. Practically speaking, this function tests for a list whose | |||
| 206 | Here we describe the functions for creating keymaps. | 208 | Here we describe the functions for creating keymaps. |
| 207 | 209 | ||
| 208 | @defun make-keymap &optional prompt | 210 | @defun make-keymap &optional prompt |
| 209 | This function creates and returns a new full keymap (i.e., one which | 211 | This function creates and returns a new full keymap (i.e., one |
| 210 | contains a vector of length 128 for defining all the @sc{ASCII} | 212 | containing a vector of length 128 for defining all the @sc{ASCII} |
| 211 | characters). The new keymap initially binds all @sc{ASCII} characters | 213 | characters). The new keymap initially binds all @sc{ASCII} characters |
| 212 | to @code{nil}, and does not bind any other kind of event. | 214 | to @code{nil}, and does not bind any other kind of event. |
| 213 | 215 | ||
| @@ -237,7 +239,7 @@ specifies a prompt string, as in @code{make-keymap}. | |||
| 237 | @end defun | 239 | @end defun |
| 238 | 240 | ||
| 239 | @defun copy-keymap keymap | 241 | @defun copy-keymap keymap |
| 240 | This function returns a copy of @var{keymap}. Any keymaps which | 242 | This function returns a copy of @var{keymap}. Any keymaps that |
| 241 | appear directly as bindings in @var{keymap} are also copied recursively, | 243 | appear directly as bindings in @var{keymap} are also copied recursively, |
| 242 | and so on to any number of levels. However, recursive copying does not | 244 | and so on to any number of levels. However, recursive copying does not |
| 243 | take place when the definition of a character is a symbol whose function | 245 | take place when the definition of a character is a symbol whose function |
| @@ -303,9 +305,9 @@ from @code{text-mode-map}: | |||
| 303 | @section Prefix Keys | 305 | @section Prefix Keys |
| 304 | @cindex prefix key | 306 | @cindex prefix key |
| 305 | 307 | ||
| 306 | A @dfn{prefix key} has an associated keymap which defines what to do | 308 | A @dfn{prefix key} has an associated keymap that defines what to do |
| 307 | with key sequences that start with the prefix key. For example, | 309 | with key sequences that start with the prefix key. For example, |
| 308 | @kbd{C-x} is a prefix key, and it uses a keymap which is also stored in | 310 | @kbd{C-x} is a prefix key, and it uses a keymap that is also stored in |
| 309 | the variable @code{ctl-x-map}. Here is a list of the standard prefix | 311 | the variable @code{ctl-x-map}. Here is a list of the standard prefix |
| 310 | keys of Emacs and their keymaps: | 312 | keys of Emacs and their keymaps: |
| 311 | 313 | ||
| @@ -333,9 +335,8 @@ describes the main use of the @kbd{C-c} prefix key. | |||
| 333 | @cindex @kbd{C-x} | 335 | @cindex @kbd{C-x} |
| 334 | @vindex ctl-x-map | 336 | @vindex ctl-x-map |
| 335 | @findex Control-X-prefix | 337 | @findex Control-X-prefix |
| 336 | @code{ctl-x-map} is the variable name for the map used for events | 338 | @code{ctl-x-map} is the map used for events that follow @kbd{C-x}. This |
| 337 | that follow @kbd{C-x}. This map is also the function definition of | 339 | map is also the function definition of @code{Control-X-prefix}. |
| 338 | @code{Control-X-prefix}. | ||
| 339 | 340 | ||
| 340 | @item | 341 | @item |
| 341 | @cindex @kbd{C-x 4} | 342 | @cindex @kbd{C-x 4} |
| @@ -346,7 +347,7 @@ that follow @kbd{C-x}. This map is also the function definition of | |||
| 346 | @item | 347 | @item |
| 347 | @cindex @kbd{C-x 5} | 348 | @cindex @kbd{C-x 5} |
| 348 | @vindex ctl-x-5-map | 349 | @vindex ctl-x-5-map |
| 349 | @code{ctl-x-5-map} used is for events that follow @kbd{C-x 5}. | 350 | @code{ctl-x-5-map} is used for events that follow @kbd{C-x 5}. |
| 350 | 351 | ||
| 351 | @c Emacs 19 feature | 352 | @c Emacs 19 feature |
| 352 | @item | 353 | @item |
| @@ -365,9 +366,9 @@ the symbol @code{Control-X-prefix}, whose function definition is the | |||
| 365 | keymap for @kbd{C-x} commands. (The same keymap is also the value of | 366 | keymap for @kbd{C-x} commands. (The same keymap is also the value of |
| 366 | @code{ctl-x-map}.) | 367 | @code{ctl-x-map}.) |
| 367 | 368 | ||
| 368 | Prefix key definitions of this sort can appear in any active keymap. | 369 | Prefix key definitions can appear in any active keymap. The |
| 369 | The definitions of @kbd{C-c}, @kbd{C-x}, @kbd{C-h} and @key{ESC} as | 370 | definitions of @kbd{C-c}, @kbd{C-x}, @kbd{C-h} and @key{ESC} as prefix |
| 370 | prefix keys appear in the global map, so these prefix keys are always | 371 | keys appear in the global map, so these prefix keys are always |
| 371 | available. Major and minor modes can redefine a key as a prefix by | 372 | available. Major and minor modes can redefine a key as a prefix by |
| 372 | putting a prefix key definition for it in the local map or the minor | 373 | putting a prefix key definition for it in the local map or the minor |
| 373 | mode's map. @xref{Active Keymaps}. | 374 | mode's map. @xref{Active Keymaps}. |
| @@ -405,313 +406,16 @@ active keymap. | |||
| 405 | 406 | ||
| 406 | @defun define-prefix-command symbol | 407 | @defun define-prefix-command symbol |
| 407 | @cindex prefix command | 408 | @cindex prefix command |
| 408 | This function defines @var{symbol} as a prefix command: it creates a | 409 | This function defines @var{symbol} as a prefix command: it creates a |
| 409 | full keymap and stores it as @var{symbol}'s function definition. | 410 | full keymap and stores it as @var{symbol}'s function definition. |
| 410 | Storing the symbol as the binding of a key makes the key a prefix key | 411 | Storing the symbol as the binding of a key makes the key a prefix key |
| 411 | which has a name. It also sets @var{symbol} as a variable, to have the | 412 | that has a name. The function also sets @var{symbol} as a variable, to |
| 412 | keymap as its value. The function returns @var{symbol}. | 413 | have the keymap as its value. It returns @var{symbol}. |
| 413 | 414 | ||
| 414 | In Emacs version 18, only the function definition of @var{symbol} was | 415 | In Emacs version 18, only the function definition of @var{symbol} was |
| 415 | set, not the value as a variable. | 416 | set, not the value as a variable. |
| 416 | @end defun | 417 | @end defun |
| 417 | 418 | ||
| 418 | @node Menu Keymaps | ||
| 419 | @section Menu Keymaps | ||
| 420 | @cindex menu keymaps | ||
| 421 | |||
| 422 | @c Emacs 19 feature | ||
| 423 | A keymap can define a menu as well as bindings for keyboard keys and | ||
| 424 | mouse button. Menus are usually actuated with the mouse, but they can | ||
| 425 | work with the keyboard also. | ||
| 426 | |||
| 427 | @menu | ||
| 428 | * Defining Menus:: How to make a keymap that defines a menu. | ||
| 429 | * Mouse Menus:: How users actuate the menu with the mouse. | ||
| 430 | * Keyboard Menus:: How they actuate it with the keyboard. | ||
| 431 | * Menu Example:: Making a simple menu. | ||
| 432 | * Menu Bar:: How to customize the menu bar. | ||
| 433 | * Modifying Menus:: How to add new items to a menu. | ||
| 434 | @end menu | ||
| 435 | |||
| 436 | @node Defining Menus | ||
| 437 | @subsection Defining Menus | ||
| 438 | @cindex defining menus | ||
| 439 | @cindex menu prompt string | ||
| 440 | @cindex prompt string (of menu) | ||
| 441 | |||
| 442 | A keymap is suitable for menu use if it has an @dfn{overall prompt | ||
| 443 | string}, which is a string that appears as an element of the keymap. | ||
| 444 | (@xref{Format of Keymaps}.) The string should describe the purpose of | ||
| 445 | the menu. The easiest way to construct a keymap with a prompt string is | ||
| 446 | to specify the string as an argument when you call @code{make-keymap} or | ||
| 447 | @code{make-sparse-keymap} (@pxref{Creating Keymaps}). | ||
| 448 | |||
| 449 | The individual bindings in the menu keymap should have item | ||
| 450 | strings; these strings become the items displayed in the menu. A | ||
| 451 | binding with a item string looks like this: | ||
| 452 | |||
| 453 | @example | ||
| 454 | (@var{string} . @var{real-binding}) | ||
| 455 | @end example | ||
| 456 | |||
| 457 | The item string for a binding should be short---one or two words. It | ||
| 458 | should describe the action of the command it corresponds to. | ||
| 459 | |||
| 460 | As far as @code{define-key} is concerned, @var{string} is part of the | ||
| 461 | event's binding. However, @code{lookup-key} returns just | ||
| 462 | @var{real-binding}, and only @var{real-binding} is used for executing | ||
| 463 | the key. | ||
| 464 | |||
| 465 | You can also supply a second string, called the help string, as follows: | ||
| 466 | |||
| 467 | @example | ||
| 468 | (@var{string} @var{help-string} . @var{real-binding}) | ||
| 469 | @end example | ||
| 470 | |||
| 471 | Currently Emacs does not actually use @var{help-string}; it knows only | ||
| 472 | how to ignore @var{help-string} in order to extract @var{real-binding}. | ||
| 473 | In the future we hope to make @var{help-string} serve as extended | ||
| 474 | documentation for the menu item, available on request. | ||
| 475 | |||
| 476 | If @var{real-binding} is @code{nil}, then @var{string} appears in the | ||
| 477 | menu but cannot be selected. | ||
| 478 | |||
| 479 | If @var{real-binding} is a symbol, and has a non-@code{nil} | ||
| 480 | @code{menu-enable} property, that property is an expression which | ||
| 481 | controls whether the menu item is enabled. Every time the keymap is | ||
| 482 | used to display a menu, Emacs evaluates the expression, and it enables | ||
| 483 | the menu item only if the expression's value is non-@code{nil}. When a | ||
| 484 | menu item is disabled, it is displayed in a ``fuzzy'' fashion, and | ||
| 485 | cannot be selected with the mouse. | ||
| 486 | |||
| 487 | The order of items in the menu is the same as the order of bindings in | ||
| 488 | the keymap. Since @code{define-key} puts new bindings at the front, you | ||
| 489 | should define the menu items starting at the bottom of the menu and | ||
| 490 | moving to the top, if you care about the order. When you add an item to | ||
| 491 | an existing menu, you can specify its position in the menu using | ||
| 492 | @code{define-key-after} (@pxref{Modifying Menus}). | ||
| 493 | |||
| 494 | You've probably noticed that menu items show the equivalent keyboard key | ||
| 495 | sequence (if any) to invoke the same command. To save time on | ||
| 496 | recalculation, menu display caches this information in a sublist in the | ||
| 497 | binding, like this: | ||
| 498 | |||
| 499 | @c This line is not too long--rms. | ||
| 500 | @example | ||
| 501 | (@var{string} @r{[}@var{help-string}@r{]} (@var{key-binding-data}) . @var{real-binding}) | ||
| 502 | @end example | ||
| 503 | |||
| 504 | Don't put these sublists in the menu item yourself; menu display | ||
| 505 | calculates them automatically. Don't add keyboard equivalents to the | ||
| 506 | item string yourself, for that is redundant. | ||
| 507 | |||
| 508 | @node Mouse Menus | ||
| 509 | @subsection Menus and the Mouse | ||
| 510 | |||
| 511 | The way to make a menu keymap produce a menu is to make it the | ||
| 512 | definition of a prefix key. | ||
| 513 | |||
| 514 | If the prefix key ends with a mouse event, Emacs handles the menu keymap | ||
| 515 | by popping up a visible menu, so that the user can select a choice with | ||
| 516 | the mouse. When the user clicks on a menu item, the event generated is | ||
| 517 | whatever character or symbol has the binding which brought about that | ||
| 518 | menu item. (A menu item may generate a series of events if the menu has | ||
| 519 | multiple levels or comes from the menu bar.) | ||
| 520 | |||
| 521 | It's often best to use a button-down event to trigger the menu. Then | ||
| 522 | the user can select a menu item by releasing the button. | ||
| 523 | |||
| 524 | A single keymap can appear as multiple menu panes, if you explicitly | ||
| 525 | arrange for this. The way to do this is to make a keymap for each pane, | ||
| 526 | then create a binding for each of those maps in the main keymap of the | ||
| 527 | menu. Give each of these bindings a item string that starts with | ||
| 528 | @samp{@@}. The rest of the item string becomes the name of the pane. | ||
| 529 | See the file @file{lisp/mouse.el} for an example of this. Any ordinary | ||
| 530 | bindings with @samp{@@}-less item strings are grouped into one pane, | ||
| 531 | which appears along with the other panes explicitly created for the | ||
| 532 | submaps. | ||
| 533 | |||
| 534 | X toolkit menus don't have panes; instead, they can have submenus. | ||
| 535 | Every nested keymap becomes a submenu, whether the item string starts | ||
| 536 | with @samp{@@} or not. In a toolkit version of Emacs, The only thing | ||
| 537 | special about @samp{@@} at the beginning of an item string is that the | ||
| 538 | @samp{@@} doesn't appear in the menu item. | ||
| 539 | |||
| 540 | You can also get multiple panes from separate keymaps. The full | ||
| 541 | definition of a prefix key always comes from merging the definitions | ||
| 542 | supplied by the various active keymaps (minor mode, local, and | ||
| 543 | global). When more than one of these keymaps is a menu, each of them | ||
| 544 | makes a separate pane or panes. @xref{Active Keymaps}. | ||
| 545 | |||
| 546 | In toolkit versions of Emacs, menus don't have panes, so submenus are | ||
| 547 | used to represent the separate keymaps. Each keymap's contribution | ||
| 548 | becomes one submenu. | ||
| 549 | |||
| 550 | A Lisp program can explicitly pop up a menu and receive the user's | ||
| 551 | choice. You can use keymaps for this also. @xref{Pop-Up Menus}. | ||
| 552 | |||
| 553 | @node Keyboard Menus | ||
| 554 | @subsection Menus and the Keyboard | ||
| 555 | |||
| 556 | When a prefix key ending with a keyboard event (a character or function | ||
| 557 | key) has a definition that is a menu keymap, the user can use the | ||
| 558 | keyboard to choose a menu item. | ||
| 559 | |||
| 560 | Emacs displays the menu alternatives (the item strings of the | ||
| 561 | bindings) in the echo area. If they don't all fit at once, the user can | ||
| 562 | type @key{SPC} to see the next line of alternatives. Successive uses of | ||
| 563 | @key{SPC} eventually get to the end of the menu and then cycle around to | ||
| 564 | the beginning. | ||
| 565 | |||
| 566 | When the user has found the desired alternative from the menu, he or she | ||
| 567 | should type the corresponding character---the one whose binding is that | ||
| 568 | alternative. | ||
| 569 | |||
| 570 | In a menu intended for keyboard use, each menu item must clearly | ||
| 571 | indicate what character to type. The best convention to use is to make | ||
| 572 | the character the first letter of the item string. That is something | ||
| 573 | users will understand without being told. | ||
| 574 | |||
| 575 | This way of using menus in an Emacs-like editor was inspired by the | ||
| 576 | Hierarkey system. | ||
| 577 | |||
| 578 | @defvar menu-prompt-more-char | ||
| 579 | This variable specifies the character to use to ask to see | ||
| 580 | the next line of a menu. Its initial value is 32, the code | ||
| 581 | for @key{SPC}. | ||
| 582 | @end defvar | ||
| 583 | |||
| 584 | @node Menu Example | ||
| 585 | @subsection Menu Example | ||
| 586 | |||
| 587 | Here is a simple example of how to set up a menu for mouse use. | ||
| 588 | |||
| 589 | @example | ||
| 590 | (defvar my-menu-map | ||
| 591 | (make-sparse-keymap "Key Commands <==> Functions")) | ||
| 592 | (fset 'help-for-keys my-menu-map) | ||
| 593 | |||
| 594 | (define-key my-menu-map [bindings] | ||
| 595 | '("List all keystroke commands" . describe-bindings)) | ||
| 596 | (define-key my-menu-map [key] | ||
| 597 | '("Describe key briefly" . describe-key-briefly)) | ||
| 598 | (define-key my-menu-map [key-verbose] | ||
| 599 | '("Describe key verbose" . describe-key)) | ||
| 600 | (define-key my-menu-map [function] | ||
| 601 | '("Describe Lisp function" . describe-function)) | ||
| 602 | (define-key my-menu-map [where-is] | ||
| 603 | '("Where is this command" . where-is)) | ||
| 604 | |||
| 605 | (define-key global-map [C-S-down-mouse-1] 'help-for-keys) | ||
| 606 | @end example | ||
| 607 | |||
| 608 | The symbols used in the key sequences bound in the menu are fictitious | ||
| 609 | ``function keys''; they don't appear on the keyboard, but that doesn't | ||
| 610 | stop you from using them in the menu. Their names were chosen to be | ||
| 611 | mnemonic, because they show up in the output of @code{where-is} and | ||
| 612 | @code{apropos} to identify the corresponding menu items. | ||
| 613 | |||
| 614 | However, if you want the menu to be usable from the keyboard as well, | ||
| 615 | you must bind real @sc{ASCII} characters as well as fictitious function | ||
| 616 | keys. | ||
| 617 | |||
| 618 | @node Menu Bar | ||
| 619 | @subsection The Menu Bar | ||
| 620 | @cindex menu bar | ||
| 621 | |||
| 622 | Most window systems allow each frame to have a @dfn{menu bar}---a | ||
| 623 | permanently displayed menu stretching horizontally across the top of the | ||
| 624 | frame. The items of the menu bar are the subcommands of the fake | ||
| 625 | ``function key'' @code{menu-bar}, as defined by all the active keymaps. | ||
| 626 | |||
| 627 | To add an item to the menu bar, invent a fake ``function key'' of your | ||
| 628 | own (let's call it @var{key}), and make a binding for the key sequence | ||
| 629 | @code{[menu-bar @var{key}]}. Most often, the binding is a menu keymap, | ||
| 630 | so that pressing a button on the menu bar item leads to another menu. | ||
| 631 | |||
| 632 | When more than one active keymap defines the same fake function key | ||
| 633 | for the menu bar, the item appears just once. If the user clicks on | ||
| 634 | that menu bar item, it brings up a single, combined submenu containing | ||
| 635 | all the subcommands of that item---the global subcommands, the local | ||
| 636 | subcommands, and the minor mode subcommands, all together. | ||
| 637 | |||
| 638 | In order for a frame to display a menu bar, its @code{menu-bar-lines} | ||
| 639 | parameter must be greater than zero. Emacs uses just one line for the | ||
| 640 | menu bar itself; if you specify more than one line, the other lines | ||
| 641 | serve to separate the menu bar from the windows in the frame. We | ||
| 642 | recommend you try 1 or 2 as the value of @code{menu-bar-lines}. @xref{X | ||
| 643 | Frame Parameters}. | ||
| 644 | |||
| 645 | Here's an example of setting up a menu bar item: | ||
| 646 | |||
| 647 | @smallexample | ||
| 648 | (modify-frame-parameters (selected-frame) '((menu-bar-lines . 2))) | ||
| 649 | |||
| 650 | ;; @r{Make a menu keymap (with a prompt string)} | ||
| 651 | ;; @r{and make it the menu bar item's definition.} | ||
| 652 | (define-key global-map [menu-bar words] | ||
| 653 | (cons "Words" (make-sparse-keymap "Words"))) | ||
| 654 | |||
| 655 | @group | ||
| 656 | ;; @r{Define specific subcommands in the item's menu.} | ||
| 657 | (define-key global-map | ||
| 658 | [menu-bar words forward] | ||
| 659 | '("Forward word" . forward-word)) | ||
| 660 | @end group | ||
| 661 | @group | ||
| 662 | (define-key global-map | ||
| 663 | [menu-bar words backward] | ||
| 664 | '("Backward word" . backward-word)) | ||
| 665 | @end group | ||
| 666 | @end smallexample | ||
| 667 | |||
| 668 | A local keymap can cancel a menu bar item made by the global keymap by | ||
| 669 | rebinding the same fake function key with @code{undefined} as the | ||
| 670 | binding. For example, this is how Dired suppresses the @samp{Edit} menu | ||
| 671 | bar item: | ||
| 672 | |||
| 673 | @example | ||
| 674 | (define-key dired-mode-map [menu-bar edit] 'undefined) | ||
| 675 | @end example | ||
| 676 | |||
| 677 | @noindent | ||
| 678 | @code{edit} is the fake function key used by the global map for the | ||
| 679 | @samp{Edit} menu bar item. The main reason to suppress a global | ||
| 680 | menu bar item is to regain space for mode-specific items. | ||
| 681 | |||
| 682 | @defvar menu-bar-final-items | ||
| 683 | Normally the menu bar shows global items followed by items defined by the | ||
| 684 | local maps. | ||
| 685 | |||
| 686 | This variable holds a list of fake function keys for items to display at | ||
| 687 | the end of the menu bar rather than in normal sequence. The default | ||
| 688 | value is @code{(help)}; thus, the @samp{Help} menu item normally appears | ||
| 689 | at the end of the menu bar, following local menu items. | ||
| 690 | @end defvar | ||
| 691 | |||
| 692 | @node Modifying Menus | ||
| 693 | @subsection Modifying Menus | ||
| 694 | |||
| 695 | When you insert a new item in an existing menu, you probably want to | ||
| 696 | put it in a particular place among the menu's existing items. If you | ||
| 697 | use @code{define-key} to add the item, it normally goes at the front of | ||
| 698 | the menu. To put it elsewhere, use @code{define-key-after}: | ||
| 699 | |||
| 700 | @defun define-key-after map key binding after | ||
| 701 | Define a binding in @var{map} for @var{key}, with value @var{binding}, | ||
| 702 | just like @code{define-key}, but position the binding in @var{map} after | ||
| 703 | the binding for the key @var{after}. For example, | ||
| 704 | |||
| 705 | @example | ||
| 706 | (define-key-after my-menu [drink] | ||
| 707 | '("Drink" . drink-command) [eat]) | ||
| 708 | @end example | ||
| 709 | |||
| 710 | @noindent | ||
| 711 | makes a binding for the fake function key @key{drink} and puts it | ||
| 712 | right after the binding for @key{eat}. | ||
| 713 | @end defun | ||
| 714 | |||
| 715 | @node Active Keymaps | 419 | @node Active Keymaps |
| 716 | @section Active Keymaps | 420 | @section Active Keymaps |
| 717 | @cindex active keymap | 421 | @cindex active keymap |
| @@ -756,10 +460,9 @@ map. | |||
| 756 | 460 | ||
| 757 | @cindex major mode keymap | 461 | @cindex major mode keymap |
| 758 | Since every buffer that uses the same major mode normally uses the | 462 | Since every buffer that uses the same major mode normally uses the |
| 759 | very same local keymap, it may appear as if the keymap is local to the | 463 | same local keymap, you can think of the keymap as local to the mode. A |
| 760 | mode. A change to the local keymap of a buffer (using | 464 | change to the local keymap of a buffer (using @code{local-set-key}, for |
| 761 | @code{local-set-key}, for example) will be seen also in the other | 465 | example) is seen also in the other buffers that share that keymap. |
| 762 | buffers that share that keymap. | ||
| 763 | 466 | ||
| 764 | The local keymaps that are used for Lisp mode, C mode, and several | 467 | The local keymaps that are used for Lisp mode, C mode, and several |
| 765 | other major modes exist even if they have not yet been used. These | 468 | other major modes exist even if they have not yet been used. These |
| @@ -774,7 +477,7 @@ and exit commands. @xref{Intro to Minibuffers}. | |||
| 774 | @xref{Standard Keymaps}, for a list of standard keymaps. | 477 | @xref{Standard Keymaps}, for a list of standard keymaps. |
| 775 | 478 | ||
| 776 | @defvar global-map | 479 | @defvar global-map |
| 777 | This variable contains the default global keymap that maps Emacs | 480 | This variable contains the default global keymap that maps Emacs |
| 778 | keyboard input to commands. The global keymap is normally this keymap. | 481 | keyboard input to commands. The global keymap is normally this keymap. |
| 779 | The default global keymap is a full keymap that binds | 482 | The default global keymap is a full keymap that binds |
| 780 | @code{self-insert-command} to all of the printing characters. | 483 | @code{self-insert-command} to all of the printing characters. |
| @@ -785,7 +488,7 @@ out with. | |||
| 785 | @end defvar | 488 | @end defvar |
| 786 | 489 | ||
| 787 | @defun current-global-map | 490 | @defun current-global-map |
| 788 | This function returns the current global keymap. This is the | 491 | This function returns the current global keymap. This is the |
| 789 | same as the value of @code{global-map} unless you change one or the | 492 | same as the value of @code{global-map} unless you change one or the |
| 790 | other. | 493 | other. |
| 791 | 494 | ||
| @@ -799,7 +502,7 @@ other. | |||
| 799 | @end defun | 502 | @end defun |
| 800 | 503 | ||
| 801 | @defun current-local-map | 504 | @defun current-local-map |
| 802 | This function returns the current buffer's local keymap, or @code{nil} | 505 | This function returns the current buffer's local keymap, or @code{nil} |
| 803 | if it has none. In the following example, the keymap for the | 506 | if it has none. In the following example, the keymap for the |
| 804 | @samp{*scratch*} buffer (using Lisp Interaction mode) is a sparse keymap | 507 | @samp{*scratch*} buffer (using Lisp Interaction mode) is a sparse keymap |
| 805 | in which the entry for @key{ESC}, @sc{ASCII} code 27, is another sparse | 508 | in which the entry for @key{ESC}, @sc{ASCII} code 27, is another sparse |
| @@ -826,14 +529,14 @@ This function returns a list of the keymaps of currently enabled minor modes. | |||
| 826 | @end defun | 529 | @end defun |
| 827 | 530 | ||
| 828 | @defun use-global-map keymap | 531 | @defun use-global-map keymap |
| 829 | This function makes @var{keymap} the new current global keymap. It | 532 | This function makes @var{keymap} the new current global keymap. It |
| 830 | returns @code{nil}. | 533 | returns @code{nil}. |
| 831 | 534 | ||
| 832 | It is very unusual to change the global keymap. | 535 | It is very unusual to change the global keymap. |
| 833 | @end defun | 536 | @end defun |
| 834 | 537 | ||
| 835 | @defun use-local-map keymap | 538 | @defun use-local-map keymap |
| 836 | This function makes @var{keymap} the new local keymap of the current | 539 | This function makes @var{keymap} the new local keymap of the current |
| 837 | buffer. If @var{keymap} is @code{nil}, then the buffer has no local | 540 | buffer. If @var{keymap} is @code{nil}, then the buffer has no local |
| 838 | keymap. @code{use-local-map} returns @code{nil}. Most major mode | 541 | keymap. @code{use-local-map} returns @code{nil}. Most major mode |
| 839 | commands use this function. | 542 | commands use this function. |
| @@ -850,7 +553,7 @@ like this: | |||
| 850 | @end example | 553 | @end example |
| 851 | 554 | ||
| 852 | The keymap @var{keymap} is active whenever @var{variable} has a | 555 | The keymap @var{keymap} is active whenever @var{variable} has a |
| 853 | non-@code{nil} value. Typically @var{variable} is the variable which | 556 | non-@code{nil} value. Typically @var{variable} is the variable that |
| 854 | enables or disables a minor mode. @xref{Keymaps and Minor Modes}. | 557 | enables or disables a minor mode. @xref{Keymaps and Minor Modes}. |
| 855 | 558 | ||
| 856 | Note that elements of @code{minor-mode-map-alist} do not have the same | 559 | Note that elements of @code{minor-mode-map-alist} do not have the same |
| @@ -873,10 +576,10 @@ minor modes. | |||
| 873 | @end defvar | 576 | @end defvar |
| 874 | 577 | ||
| 875 | @defvar overriding-local-map | 578 | @defvar overriding-local-map |
| 876 | If non-@code{nil}, a keymap to use instead of the buffer's local keymap | 579 | If non-@code{nil}, this variable holds a keymap to use instead of the |
| 877 | and instead of all the minor mode keymaps. This keymap, if any, | 580 | buffer's local keymap and instead of all the minor mode keymaps. This |
| 878 | overrides all other maps that would have been active, except for the | 581 | keymap, if any, overrides all other maps that would have been active, |
| 879 | current global map. | 582 | except for the current global map. |
| 880 | @end defvar | 583 | @end defvar |
| 881 | 584 | ||
| 882 | @node Key Lookup | 585 | @node Key Lookup |
| @@ -888,7 +591,7 @@ current global map. | |||
| 888 | sequence from a given keymap. Actual execution of the binding is not | 591 | sequence from a given keymap. Actual execution of the binding is not |
| 889 | part of key lookup. | 592 | part of key lookup. |
| 890 | 593 | ||
| 891 | Key lookup uses just the event types of each event in the key | 594 | Key lookup uses just the event type of each event in the key |
| 892 | sequence; the rest of the event is ignored. In fact, a key sequence | 595 | sequence; the rest of the event is ignored. In fact, a key sequence |
| 893 | used for key lookup may designate mouse events with just their types | 596 | used for key lookup may designate mouse events with just their types |
| 894 | (symbols) instead of with entire mouse events (lists). @xref{Input | 597 | (symbols) instead of with entire mouse events (lists). @xref{Input |
| @@ -930,7 +633,7 @@ event of the key sequence is looked up in @var{keymap}. | |||
| 930 | @item @var{command} | 633 | @item @var{command} |
| 931 | @cindex command in keymap | 634 | @cindex command in keymap |
| 932 | The events used so far in the lookup form a complete key, | 635 | The events used so far in the lookup form a complete key, |
| 933 | and @var{command} is its binding. | 636 | and @var{command} is its binding. @xref{What Is a Function}. |
| 934 | 637 | ||
| 935 | @item @var{string} | 638 | @item @var{string} |
| 936 | @itemx @var{vector} | 639 | @itemx @var{vector} |
| @@ -975,16 +678,16 @@ binding of @kbd{Meta-@key{SPC}}, whatever that may be.'' | |||
| 975 | @cindex symbol in keymap | 678 | @cindex symbol in keymap |
| 976 | The function definition of @var{symbol} is used in place of | 679 | The function definition of @var{symbol} is used in place of |
| 977 | @var{symbol}. If that too is a symbol, then this process is repeated, | 680 | @var{symbol}. If that too is a symbol, then this process is repeated, |
| 978 | any number of times. Ultimately this should lead to an object which is | 681 | any number of times. Ultimately this should lead to an object that is |
| 979 | a keymap, a command or a keyboard macro. A list is allowed if it is a | 682 | a keymap, a command or a keyboard macro. A list is allowed if it is a |
| 980 | keymap or a command, but indirect entries are not understood when found | 683 | keymap or a command, but indirect entries are not understood when found |
| 981 | via symbols. | 684 | via symbols. |
| 982 | 685 | ||
| 983 | Note that keymaps and keyboard macros (strings and vectors) are not | 686 | Note that keymaps and keyboard macros (strings and vectors) are not |
| 984 | valid functions, so a symbol with a keymap, string or vector as its | 687 | valid functions, so a symbol with a keymap, string, or vector as its |
| 985 | function definition is also invalid as a function. It is, however, | 688 | function definition is invalid as a function. It is, however, valid as |
| 986 | valid as a key binding. If the definition is a keyboard macro, then the | 689 | a key binding. If the definition is a keyboard macro, then the symbol |
| 987 | symbol is also valid as an argument to @code{command-execute} | 690 | is also valid as an argument to @code{command-execute} |
| 988 | (@pxref{Interactive Call}). | 691 | (@pxref{Interactive Call}). |
| 989 | 692 | ||
| 990 | @cindex @code{undefined} in keymap | 693 | @cindex @code{undefined} in keymap |
| @@ -1007,7 +710,7 @@ binding is not executable as a command. | |||
| 1007 | @end table | 710 | @end table |
| 1008 | 711 | ||
| 1009 | In short, a keymap entry may be a keymap, a command, a keyboard macro, | 712 | In short, a keymap entry may be a keymap, a command, a keyboard macro, |
| 1010 | a symbol which leads to one of them, or an indirection or @code{nil}. | 713 | a symbol that leads to one of them, or an indirection or @code{nil}. |
| 1011 | Here is an example of a sparse keymap with two characters bound to | 714 | Here is an example of a sparse keymap with two characters bound to |
| 1012 | commands and one bound to another keymap. This map is the normal value | 715 | commands and one bound to another keymap. This map is the normal value |
| 1013 | of @code{emacs-lisp-mode-map}. Note that 9 is the code for @key{TAB}, | 716 | of @code{emacs-lisp-mode-map}. Note that 9 is the code for @key{TAB}, |
| @@ -1039,7 +742,8 @@ If @var{accept-defaults} is non-@code{nil}, then @code{lookup-key} | |||
| 1039 | considers default bindings as well as bindings for the specific events | 742 | considers default bindings as well as bindings for the specific events |
| 1040 | in @var{key}. Otherwise, @code{lookup-key} reports only bindings for | 743 | in @var{key}. Otherwise, @code{lookup-key} reports only bindings for |
| 1041 | the specific sequence @var{key}, ignoring default bindings except when | 744 | the specific sequence @var{key}, ignoring default bindings except when |
| 1042 | an element of @var{key} is @code{t}. | 745 | you explicitly ask about them. (To do this, supply @code{t} as an |
| 746 | element of @var{key}; see @ref{Format of Keymaps}.) | ||
| 1043 | 747 | ||
| 1044 | All the other functions described in this chapter that look up keys use | 748 | All the other functions described in this chapter that look up keys use |
| 1045 | @code{lookup-key}. | 749 | @code{lookup-key}. |
| @@ -1090,7 +794,7 @@ keymaps, trying all the active keymaps. The result is @code{nil} if | |||
| 1090 | 794 | ||
| 1091 | @c Emacs 19 feature | 795 | @c Emacs 19 feature |
| 1092 | The argument @var{accept-defaults} controls checking for default | 796 | The argument @var{accept-defaults} controls checking for default |
| 1093 | bindings, as in @code{lookup-key}. | 797 | bindings, as in @code{lookup-key} (above). |
| 1094 | 798 | ||
| 1095 | An error is signaled if @var{key} is not a string or a vector. | 799 | An error is signaled if @var{key} is not a string or a vector. |
| 1096 | 800 | ||
| @@ -1124,8 +828,8 @@ as in @code{lookup-key} (above). | |||
| 1124 | @defun minor-mode-key-binding key &optional accept-defaults | 828 | @defun minor-mode-key-binding key &optional accept-defaults |
| 1125 | This function returns a list of all the active minor mode bindings of | 829 | This function returns a list of all the active minor mode bindings of |
| 1126 | @var{key}. More precisely, it returns an alist of pairs | 830 | @var{key}. More precisely, it returns an alist of pairs |
| 1127 | @code{(@var{modename} . @var{binding})}, where @var{modename} is the the | 831 | @code{(@var{modename} . @var{binding})}, where @var{modename} is the |
| 1128 | variable which enables the minor mode, and @var{binding} is @var{key}'s | 832 | variable that enables the minor mode, and @var{binding} is @var{key}'s |
| 1129 | binding in that mode. If @var{key} has no minor-mode bindings, the | 833 | binding in that mode. If @var{key} has no minor-mode bindings, the |
| 1130 | value is @code{nil}. | 834 | value is @code{nil}. |
| 1131 | 835 | ||
| @@ -1187,48 +891,27 @@ meta-prefix-char ; @r{The default value.} | |||
| 1187 | @cindex rebinding | 891 | @cindex rebinding |
| 1188 | 892 | ||
| 1189 | The way to rebind a key is to change its entry in a keymap. If you | 893 | The way to rebind a key is to change its entry in a keymap. If you |
| 1190 | change the global keymap, the change is effective in all buffers (except | 894 | change a binding in the global keymap, the change is effective in all |
| 1191 | those that override the global binding with a local one). If you change | 895 | buffers (though it has no direct effect in buffers that shadow the |
| 1192 | the current buffer's local map, that usually affects all buffers using | 896 | global binding with a local one). If you change the current buffer's |
| 1193 | the same major mode. The @code{global-set-key} and @code{local-set-key} | 897 | local map, that usually affects all buffers using the same major mode. |
| 1194 | functions are convenient interfaces for these operations. Or you can | 898 | The @code{global-set-key} and @code{local-set-key} functions are |
| 1195 | use @code{define-key} and specify explicitly which map to change. | 899 | convenient interfaces for these operations (@pxref{Key Binding |
| 1196 | 900 | Commands}). You can also use @code{define-key}, a more general | |
| 1197 | People often use @code{global-set-key} in their @file{.emacs} file for | 901 | function; then you must specify explicitly the map to change. |
| 1198 | simple customization. For example, | ||
| 1199 | |||
| 1200 | @smallexample | ||
| 1201 | (global-set-key "\C-x\C-\\" 'next-line) | ||
| 1202 | @end smallexample | ||
| 1203 | |||
| 1204 | @noindent | ||
| 1205 | or | ||
| 1206 | |||
| 1207 | @smallexample | ||
| 1208 | (global-set-key [?\C-x ?\C-\\] 'next-line) | ||
| 1209 | @end smallexample | ||
| 1210 | |||
| 1211 | @noindent | ||
| 1212 | redefines @kbd{C-x C-\} to move down a line. | ||
| 1213 | |||
| 1214 | @smallexample | ||
| 1215 | (global-set-key [M-mouse-1] 'mouse-set-point) | ||
| 1216 | @end smallexample | ||
| 1217 | |||
| 1218 | @noindent | ||
| 1219 | redefines the first (leftmost) mouse button, typed with the Meta key, to | ||
| 1220 | set point where you click. | ||
| 1221 | 902 | ||
| 1222 | @cindex meta character key constants | 903 | @cindex meta character key constants |
| 1223 | @cindex control character key constants | 904 | @cindex control character key constants |
| 1224 | In writing the key sequence to rebind, it is useful to use the special | 905 | In writing the key sequence to rebind, it is good to use the special |
| 1225 | escape sequences for control and meta characters (@pxref{String Type}). | 906 | escape sequences for control and meta characters (@pxref{String Type}). |
| 1226 | The syntax @samp{\C-} means that the following character is a control | 907 | The syntax @samp{\C-} means that the following character is a control |
| 1227 | character and @samp{\M-} means that the following character is a meta | 908 | character and @samp{\M-} means that the following character is a meta |
| 1228 | character. Thus, the string @code{"\M-x"} is read as containing a | 909 | character. Thus, the string @code{"\M-x"} is read as containing a |
| 1229 | single @kbd{M-x}, @code{"\C-f"} is read as containing a single | 910 | single @kbd{M-x}, @code{"\C-f"} is read as containing a single |
| 1230 | @kbd{C-f}, and @code{"\M-\C-x"} and @code{"\C-\M-x"} are both read as | 911 | @kbd{C-f}, and @code{"\M-\C-x"} and @code{"\C-\M-x"} are both read as |
| 1231 | containing a single @kbd{C-M-x}. | 912 | containing a single @kbd{C-M-x}. You can also use this escape syntax in |
| 913 | vectors, as well as others that aren't allowed in strings; one example | ||
| 914 | is @samp{[?\C-\H-x home]}. @xref{Character Type}. | ||
| 1232 | 915 | ||
| 1233 | For the functions below, an error is signaled if @var{keymap} is not a | 916 | For the functions below, an error is signaled if @var{keymap} is not a |
| 1234 | keymap or if @var{key} is not a string or vector representing a key | 917 | keymap or if @var{key} is not a string or vector representing a key |
| @@ -1236,7 +919,7 @@ sequence. You can use event types (symbols) as shorthand for events | |||
| 1236 | that are lists. | 919 | that are lists. |
| 1237 | 920 | ||
| 1238 | @defun define-key keymap key binding | 921 | @defun define-key keymap key binding |
| 1239 | This function sets the binding for @var{key} in @var{keymap}. (If | 922 | This function sets the binding for @var{key} in @var{keymap}. (If |
| 1240 | @var{key} is more than one event long, the change is actually made | 923 | @var{key} is more than one event long, the change is actually made |
| 1241 | in another keymap reached from @var{keymap}.) The argument | 924 | in another keymap reached from @var{keymap}.) The argument |
| 1242 | @var{binding} can be any Lisp object, but only certain types are | 925 | @var{binding} can be any Lisp object, but only certain types are |
| @@ -1245,7 +928,7 @@ The value returned by @code{define-key} is @var{binding}. | |||
| 1245 | 928 | ||
| 1246 | @cindex invalid prefix key error | 929 | @cindex invalid prefix key error |
| 1247 | @cindex key sequence error | 930 | @cindex key sequence error |
| 1248 | Every prefix of @var{key} must be a prefix key (i.e., bound to a | 931 | Every prefix of @var{key} must be a prefix key (i.e., bound to a |
| 1249 | keymap) or undefined; otherwise an error is signaled. | 932 | keymap) or undefined; otherwise an error is signaled. |
| 1250 | 933 | ||
| 1251 | If some prefix of @var{key} is undefined, then @code{define-key} defines | 934 | If some prefix of @var{key} is undefined, then @code{define-key} defines |
| @@ -1253,7 +936,8 @@ it as a prefix key so that the rest of @var{key} may be defined as | |||
| 1253 | specified. | 936 | specified. |
| 1254 | @end defun | 937 | @end defun |
| 1255 | 938 | ||
| 1256 | This example creates a sparse keymap and makes a number of bindings: | 939 | Here is an example that creates a sparse keymap and makes a number of |
| 940 | bindings in it: | ||
| 1257 | 941 | ||
| 1258 | @smallexample | 942 | @smallexample |
| 1259 | @group | 943 | @group |
| @@ -1425,8 +1109,33 @@ Dired mode is set up: | |||
| 1425 | This section describes some convenient interactive interfaces for | 1109 | This section describes some convenient interactive interfaces for |
| 1426 | changing key bindings. They work by calling @code{define-key}. | 1110 | changing key bindings. They work by calling @code{define-key}. |
| 1427 | 1111 | ||
| 1112 | People often use @code{global-set-key} in their @file{.emacs} file for | ||
| 1113 | simple customization. For example, | ||
| 1114 | |||
| 1115 | @smallexample | ||
| 1116 | (global-set-key "\C-x\C-\\" 'next-line) | ||
| 1117 | @end smallexample | ||
| 1118 | |||
| 1119 | @noindent | ||
| 1120 | or | ||
| 1121 | |||
| 1122 | @smallexample | ||
| 1123 | (global-set-key [?\C-x ?\C-\\] 'next-line) | ||
| 1124 | @end smallexample | ||
| 1125 | |||
| 1126 | @noindent | ||
| 1127 | redefines @kbd{C-x C-\} to move down a line. | ||
| 1128 | |||
| 1129 | @smallexample | ||
| 1130 | (global-set-key [M-mouse-1] 'mouse-set-point) | ||
| 1131 | @end smallexample | ||
| 1132 | |||
| 1133 | @noindent | ||
| 1134 | redefines the first (leftmost) mouse button, typed with the Meta key, to | ||
| 1135 | set point where you click. | ||
| 1136 | |||
| 1428 | @deffn Command global-set-key key definition | 1137 | @deffn Command global-set-key key definition |
| 1429 | This function sets the binding of @var{key} in the current global map | 1138 | This function sets the binding of @var{key} in the current global map |
| 1430 | to @var{definition}. | 1139 | to @var{definition}. |
| 1431 | 1140 | ||
| 1432 | @smallexample | 1141 | @smallexample |
| @@ -1440,11 +1149,11 @@ to @var{definition}. | |||
| 1440 | 1149 | ||
| 1441 | @deffn Command global-unset-key key | 1150 | @deffn Command global-unset-key key |
| 1442 | @cindex unbinding keys | 1151 | @cindex unbinding keys |
| 1443 | This function removes the binding of @var{key} from the current | 1152 | This function removes the binding of @var{key} from the current |
| 1444 | global map. | 1153 | global map. |
| 1445 | 1154 | ||
| 1446 | One use of this function is in preparation for defining a longer key | 1155 | One use of this function is in preparation for defining a longer key |
| 1447 | which uses it implicitly as a prefix---which would not be allowed if | 1156 | that uses @var{key} as a prefix---which would not be allowed if |
| 1448 | @var{key} has a non-prefix binding. For example: | 1157 | @var{key} has a non-prefix binding. For example: |
| 1449 | 1158 | ||
| 1450 | @smallexample | 1159 | @smallexample |
| @@ -1470,7 +1179,7 @@ This function is implemented simply using @code{define-key}: | |||
| 1470 | @end deffn | 1179 | @end deffn |
| 1471 | 1180 | ||
| 1472 | @deffn Command local-set-key key definition | 1181 | @deffn Command local-set-key key definition |
| 1473 | This function sets the binding of @var{key} in the current local | 1182 | This function sets the binding of @var{key} in the current local |
| 1474 | keymap to @var{definition}. | 1183 | keymap to @var{definition}. |
| 1475 | 1184 | ||
| 1476 | @smallexample | 1185 | @smallexample |
| @@ -1483,7 +1192,7 @@ keymap to @var{definition}. | |||
| 1483 | @end deffn | 1192 | @end deffn |
| 1484 | 1193 | ||
| 1485 | @deffn Command local-unset-key key | 1194 | @deffn Command local-unset-key key |
| 1486 | This function removes the binding of @var{key} from the current | 1195 | This function removes the binding of @var{key} from the current |
| 1487 | local map. | 1196 | local map. |
| 1488 | 1197 | ||
| 1489 | @smallexample | 1198 | @smallexample |
| @@ -1543,9 +1252,10 @@ definition is the sparse keymap @code{(keymap (83 .@: center-paragraph) | |||
| 1543 | 1252 | ||
| 1544 | In the following example, @kbd{C-h} is a prefix key that uses a sparse | 1253 | In the following example, @kbd{C-h} is a prefix key that uses a sparse |
| 1545 | keymap starting with @code{(keymap (118 . describe-variable)@dots{})}. | 1254 | keymap starting with @code{(keymap (118 . describe-variable)@dots{})}. |
| 1546 | Another prefix, @kbd{C-x 4}, uses a keymap which happens to be | 1255 | Another prefix, @kbd{C-x 4}, uses a keymap which is also the value of |
| 1547 | @code{ctl-x-4-map}. The event @code{mode-line} is one of several dummy | 1256 | the variable @code{ctl-x-4-map}. The event @code{mode-line} is one of |
| 1548 | events used as prefixes for mouse actions in special parts of a window. | 1257 | several dummy events used as prefixes for mouse actions in special parts |
| 1258 | of a window. | ||
| 1549 | 1259 | ||
| 1550 | @smallexample | 1260 | @smallexample |
| 1551 | @group | 1261 | @group |
| @@ -1601,8 +1311,8 @@ entirely of @sc{ASCII} characters (or meta variants of @sc{ASCII} | |||
| 1601 | characters) are preferred to all other key sequences. | 1311 | characters) are preferred to all other key sequences. |
| 1602 | 1312 | ||
| 1603 | If @var{noindirect} is non-@code{nil}, @code{where-is-internal} doesn't | 1313 | If @var{noindirect} is non-@code{nil}, @code{where-is-internal} doesn't |
| 1604 | follow indirections to other keymaps or slots. This makes it possible | 1314 | follow indirect keymap bindings. This makes it possible to search for |
| 1605 | to search for an indirect definition itself. | 1315 | an indirect definition itself. |
| 1606 | 1316 | ||
| 1607 | This function is used by @code{where-is} (@pxref{Help, , Help, emacs, | 1317 | This function is used by @code{where-is} (@pxref{Help, , Help, emacs, |
| 1608 | The GNU Emacs Manual}). | 1318 | The GNU Emacs Manual}). |
| @@ -1616,10 +1326,13 @@ The GNU Emacs Manual}). | |||
| 1616 | @end defun | 1326 | @end defun |
| 1617 | 1327 | ||
| 1618 | @deffn Command describe-bindings prefix | 1328 | @deffn Command describe-bindings prefix |
| 1619 | This function creates a listing of all defined keys, and their | 1329 | This function creates a listing of all defined keys and their |
| 1620 | definitions. It writes the listing in a buffer named @samp{*Help*} and | 1330 | definitions. It writes the listing in a buffer named @samp{*Help*} and |
| 1621 | displays it in a window. | 1331 | displays it in a window. |
| 1622 | 1332 | ||
| 1333 | If @var{prefix} is non-@code{nil}, it should be a prefix key; then the | ||
| 1334 | listing includes only keys that start with @var{prefix}. | ||
| 1335 | |||
| 1623 | The listing describes meta characters as @key{ESC} followed by the | 1336 | The listing describes meta characters as @key{ESC} followed by the |
| 1624 | corresponding non-meta character. | 1337 | corresponding non-meta character. |
| 1625 | 1338 | ||
| @@ -1632,7 +1345,319 @@ For example, in the default global map, the characters @samp{@key{SPC} | |||
| 1632 | @kbd{~} is @sc{ASCII} 126, and the characters between them include all | 1345 | @kbd{~} is @sc{ASCII} 126, and the characters between them include all |
| 1633 | the normal printing characters, (e.g., letters, digits, punctuation, | 1346 | the normal printing characters, (e.g., letters, digits, punctuation, |
| 1634 | etc.@:); all these characters are bound to @code{self-insert-command}. | 1347 | etc.@:); all these characters are bound to @code{self-insert-command}. |
| 1635 | |||
| 1636 | If @var{prefix} is non-@code{nil}, it should be a prefix key; then the | ||
| 1637 | listing includes only keys that start with @var{prefix}. | ||
| 1638 | @end deffn | 1348 | @end deffn |
| 1349 | |||
| 1350 | @node Menu Keymaps | ||
| 1351 | @section Menu Keymaps | ||
| 1352 | @cindex menu keymaps | ||
| 1353 | |||
| 1354 | @c Emacs 19 feature | ||
| 1355 | A keymap can define a menu as well as bindings for keyboard keys and | ||
| 1356 | mouse button. Menus are usually actuated with the mouse, but they can | ||
| 1357 | work with the keyboard also. | ||
| 1358 | |||
| 1359 | @menu | ||
| 1360 | * Defining Menus:: How to make a keymap that defines a menu. | ||
| 1361 | * Mouse Menus:: How users actuate the menu with the mouse. | ||
| 1362 | * Keyboard Menus:: How they actuate it with the keyboard. | ||
| 1363 | * Menu Example:: Making a simple menu. | ||
| 1364 | * Menu Bar:: How to customize the menu bar. | ||
| 1365 | * Modifying Menus:: How to add new items to a menu. | ||
| 1366 | @end menu | ||
| 1367 | |||
| 1368 | @node Defining Menus | ||
| 1369 | @subsection Defining Menus | ||
| 1370 | @cindex defining menus | ||
| 1371 | @cindex menu prompt string | ||
| 1372 | @cindex prompt string (of menu) | ||
| 1373 | |||
| 1374 | A keymap is suitable for menu use if it has an @dfn{overall prompt | ||
| 1375 | string}, which is a string that appears as an element of the keymap. | ||
| 1376 | (@xref{Format of Keymaps}.) The string should describe the purpose of | ||
| 1377 | the menu. The easiest way to construct a keymap with a prompt string is | ||
| 1378 | to specify the string as an argument when you call @code{make-keymap} or | ||
| 1379 | @code{make-sparse-keymap} (@pxref{Creating Keymaps}). | ||
| 1380 | |||
| 1381 | The individual bindings in the menu keymap should have item | ||
| 1382 | strings; these strings become the items displayed in the menu. A | ||
| 1383 | binding with an item string looks like this: | ||
| 1384 | |||
| 1385 | @example | ||
| 1386 | (@var{string} . @var{real-binding}) | ||
| 1387 | @end example | ||
| 1388 | |||
| 1389 | The item string for a binding should be short---one or two words. It | ||
| 1390 | should describe the action of the command it corresponds to. | ||
| 1391 | |||
| 1392 | As far as @code{define-key} is concerned, @var{string} is part of the | ||
| 1393 | event's binding. However, @code{lookup-key} returns just | ||
| 1394 | @var{real-binding}, and only @var{real-binding} is used for executing | ||
| 1395 | the key. | ||
| 1396 | |||
| 1397 | You can also supply a second string, called the help string, as follows: | ||
| 1398 | |||
| 1399 | @example | ||
| 1400 | (@var{string} @var{help-string} . @var{real-binding}) | ||
| 1401 | @end example | ||
| 1402 | |||
| 1403 | Currently Emacs does not actually use @var{help-string}; it knows only | ||
| 1404 | how to ignore @var{help-string} in order to extract @var{real-binding}. | ||
| 1405 | In the future we hope to make @var{help-string} serve as extended | ||
| 1406 | documentation for the menu item, available on request. | ||
| 1407 | |||
| 1408 | If @var{real-binding} is @code{nil}, then @var{string} appears in the | ||
| 1409 | menu but cannot be selected. | ||
| 1410 | |||
| 1411 | If @var{real-binding} is a symbol and has a non-@code{nil} | ||
| 1412 | @code{menu-enable} property, that property is an expression that | ||
| 1413 | controls whether the menu item is enabled. Every time the keymap is | ||
| 1414 | used to display a menu, Emacs evaluates the expression, and it enables | ||
| 1415 | the menu item only if the expression's value is non-@code{nil}. When a | ||
| 1416 | menu item is disabled, it is displayed in a ``fuzzy'' fashion, and | ||
| 1417 | cannot be selected with the mouse. | ||
| 1418 | |||
| 1419 | The order of items in the menu is the same as the order of bindings in | ||
| 1420 | the keymap. Since @code{define-key} puts new bindings at the front, you | ||
| 1421 | should define the menu items starting at the bottom of the menu and | ||
| 1422 | moving to the top, if you care about the order. When you add an item to | ||
| 1423 | an existing menu, you can specify its position in the menu using | ||
| 1424 | @code{define-key-after} (@pxref{Modifying Menus}). | ||
| 1425 | |||
| 1426 | You've probably noticed that menu items show the equivalent keyboard key | ||
| 1427 | sequence (if any) to invoke the same command. To save time on | ||
| 1428 | recalculation, menu display caches this information in a sublist in the | ||
| 1429 | binding, like this: | ||
| 1430 | |||
| 1431 | @c This line is not too long--rms. | ||
| 1432 | @example | ||
| 1433 | (@var{string} @r{[}@var{help-string}@r{]} (@var{key-binding-data}) . @var{real-binding}) | ||
| 1434 | @end example | ||
| 1435 | |||
| 1436 | Don't put these sublists in the menu item yourself; menu display | ||
| 1437 | calculates them automatically. Don't add keyboard equivalents to the | ||
| 1438 | item strings in a mouse menu, since that is redundant. | ||
| 1439 | |||
| 1440 | @node Mouse Menus | ||
| 1441 | @subsection Menus and the Mouse | ||
| 1442 | |||
| 1443 | The way to make a menu keymap produce a menu is to make it the | ||
| 1444 | definition of a prefix key. | ||
| 1445 | |||
| 1446 | If the prefix key ends with a mouse event, Emacs handles the menu keymap | ||
| 1447 | by popping up a visible menu, so that the user can select a choice with | ||
| 1448 | the mouse. When the user clicks on a menu item, the event generated is | ||
| 1449 | whatever character or symbol has the binding that brought about that | ||
| 1450 | menu item. (A menu item may generate a series of events if the menu has | ||
| 1451 | multiple levels or comes from the menu bar.) | ||
| 1452 | |||
| 1453 | It's often best to use a button-down event to trigger the menu. Then | ||
| 1454 | the user can select a menu item by releasing the button. | ||
| 1455 | |||
| 1456 | A single keymap can appear as multiple menu panes, if you explicitly | ||
| 1457 | arrange for this. The way to do this is to make a keymap for each pane, | ||
| 1458 | then create a binding for each of those maps in the main keymap of the | ||
| 1459 | menu. Give each of these bindings an item string that starts with | ||
| 1460 | @samp{@@}. The rest of the item string becomes the name of the pane. | ||
| 1461 | See the file @file{lisp/mouse.el} for an example of this. Any ordinary | ||
| 1462 | bindings with @samp{@@}-less item strings are grouped into one pane, | ||
| 1463 | which appears along with the other panes explicitly created for the | ||
| 1464 | submaps. | ||
| 1465 | |||
| 1466 | X toolkit menus don't have panes; instead, they can have submenus. | ||
| 1467 | Every nested keymap becomes a submenu, whether the item string starts | ||
| 1468 | with @samp{@@} or not. In a toolkit version of Emacs, the only thing | ||
| 1469 | special about @samp{@@} at the beginning of an item string is that the | ||
| 1470 | @samp{@@} doesn't appear in the menu item. | ||
| 1471 | |||
| 1472 | You can also get multiple panes from separate keymaps. The full | ||
| 1473 | definition of a prefix key always comes from merging the definitions | ||
| 1474 | supplied by the various active keymaps (minor mode, local, and | ||
| 1475 | global). When more than one of these keymaps is a menu, each of them | ||
| 1476 | makes a separate pane or panes. @xref{Active Keymaps}. | ||
| 1477 | |||
| 1478 | In toolkit versions of Emacs, menus don't have panes, so submenus are | ||
| 1479 | used to represent the separate keymaps. Each keymap's contribution | ||
| 1480 | becomes one submenu. | ||
| 1481 | |||
| 1482 | A Lisp program can explicitly pop up a menu and receive the user's | ||
| 1483 | choice. You can use keymaps for this also. @xref{Pop-Up Menus}. | ||
| 1484 | |||
| 1485 | @node Keyboard Menus | ||
| 1486 | @subsection Menus and the Keyboard | ||
| 1487 | |||
| 1488 | When a prefix key ending with a keyboard event (a character or function | ||
| 1489 | key) has a definition that is a menu keymap, the user can use the | ||
| 1490 | keyboard to choose a menu item. | ||
| 1491 | |||
| 1492 | Emacs displays the menu alternatives (the item strings of the bindings) | ||
| 1493 | in the echo area. If they don't all fit at once, the user can type | ||
| 1494 | @key{SPC} to see the next line of alternatives. Successive uses of | ||
| 1495 | @key{SPC} eventually get to the end of the menu and then cycle around to | ||
| 1496 | the beginning. (The variable @code{menu-prompt-more-char} specifies | ||
| 1497 | which character is used for this; @key{SPC} is the default.) | ||
| 1498 | |||
| 1499 | When the user has found the desired alternative from the menu, he or she | ||
| 1500 | should type the corresponding character---the one whose binding is that | ||
| 1501 | alternative. | ||
| 1502 | |||
| 1503 | In a menu intended for keyboard use, each menu item must clearly | ||
| 1504 | indicate what character to type. The best convention to use is to make | ||
| 1505 | the character the first letter of the item string. That is something | ||
| 1506 | users will understand without being told. | ||
| 1507 | |||
| 1508 | This way of using menus in an Emacs-like editor was inspired by the | ||
| 1509 | Hierarkey system. | ||
| 1510 | |||
| 1511 | @defvar menu-prompt-more-char | ||
| 1512 | This variable specifies the character to use to ask to see | ||
| 1513 | the next line of a menu. Its initial value is 32, the code | ||
| 1514 | for @key{SPC}. | ||
| 1515 | @end defvar | ||
| 1516 | |||
| 1517 | @node Menu Example | ||
| 1518 | @subsection Menu Example | ||
| 1519 | |||
| 1520 | Here is a simple example of how to set up a menu for mouse use. | ||
| 1521 | |||
| 1522 | @example | ||
| 1523 | (defvar my-menu-map | ||
| 1524 | (make-sparse-keymap "Key Commands <==> Functions")) | ||
| 1525 | (fset 'help-for-keys my-menu-map) | ||
| 1526 | |||
| 1527 | (define-key my-menu-map [bindings] | ||
| 1528 | '("List all keystroke commands" . describe-bindings)) | ||
| 1529 | (define-key my-menu-map [key] | ||
| 1530 | '("Describe key briefly" . describe-key-briefly)) | ||
| 1531 | (define-key my-menu-map [key-verbose] | ||
| 1532 | '("Describe key verbose" . describe-key)) | ||
| 1533 | (define-key my-menu-map [function] | ||
| 1534 | '("Describe Lisp function" . describe-function)) | ||
| 1535 | (define-key my-menu-map [where-is] | ||
| 1536 | '("Where is this command" . where-is)) | ||
| 1537 | |||
| 1538 | (define-key global-map [C-S-down-mouse-1] 'help-for-keys) | ||
| 1539 | @end example | ||
| 1540 | |||
| 1541 | The symbols used in the key sequences bound in the menu are fictitious | ||
| 1542 | ``function keys''; they don't appear on the keyboard, but that doesn't | ||
| 1543 | stop you from using them in the menu. Their names were chosen to be | ||
| 1544 | mnemonic, because they show up in the output of @code{where-is} and | ||
| 1545 | @code{apropos} to identify the corresponding menu items. | ||
| 1546 | |||
| 1547 | However, if you want the menu to be usable from the keyboard as well, | ||
| 1548 | you must bind real @sc{ASCII} characters as well as fictitious function | ||
| 1549 | keys. | ||
| 1550 | |||
| 1551 | @node Menu Bar | ||
| 1552 | @subsection The Menu Bar | ||
| 1553 | @cindex menu bar | ||
| 1554 | |||
| 1555 | Most window systems allow each frame to have a @dfn{menu bar}---a | ||
| 1556 | permanently displayed menu stretching horizontally across the top of the | ||
| 1557 | frame. The items of the menu bar are the subcommands of the fake | ||
| 1558 | ``function key'' @code{menu-bar}, as defined by all the active keymaps. | ||
| 1559 | |||
| 1560 | To add an item to the menu bar, invent a fake ``function key'' of your | ||
| 1561 | own (let's call it @var{key}), and make a binding for the key sequence | ||
| 1562 | @code{[menu-bar @var{key}]}. Most often, the binding is a menu keymap, | ||
| 1563 | so that pressing a button on the menu bar item leads to another menu. | ||
| 1564 | |||
| 1565 | When more than one active keymap defines the same fake function key | ||
| 1566 | for the menu bar, the item appears just once. If the user clicks on | ||
| 1567 | that menu bar item, it brings up a single, combined submenu containing | ||
| 1568 | all the subcommands of that item---the global subcommands, the local | ||
| 1569 | subcommands, and the minor mode subcommands, all together. | ||
| 1570 | |||
| 1571 | In order for a frame to display a menu bar, its @code{menu-bar-lines} | ||
| 1572 | parameter must be greater than zero. Emacs uses just one line for the | ||
| 1573 | menu bar itself; if you specify more than one line, the other lines | ||
| 1574 | serve to separate the menu bar from the windows in the frame. We | ||
| 1575 | recommend you try 1 or 2 as the value of @code{menu-bar-lines}. @xref{X | ||
| 1576 | Frame Parameters}. | ||
| 1577 | |||
| 1578 | Here's an example of setting up a menu bar item: | ||
| 1579 | |||
| 1580 | @example | ||
| 1581 | @group | ||
| 1582 | (modify-frame-parameters (selected-frame) | ||
| 1583 | '((menu-bar-lines . 2))) | ||
| 1584 | @end group | ||
| 1585 | |||
| 1586 | @group | ||
| 1587 | ;; @r{Make a menu keymap (with a prompt string)} | ||
| 1588 | ;; @r{and make it the menu bar item's definition.} | ||
| 1589 | (define-key global-map [menu-bar words] | ||
| 1590 | (cons "Words" (make-sparse-keymap "Words"))) | ||
| 1591 | @end group | ||
| 1592 | |||
| 1593 | @group | ||
| 1594 | ;; @r{Define specific subcommands in the item's menu.} | ||
| 1595 | (define-key global-map | ||
| 1596 | [menu-bar words forward] | ||
| 1597 | '("Forward word" . forward-word)) | ||
| 1598 | @end group | ||
| 1599 | @group | ||
| 1600 | (define-key global-map | ||
| 1601 | [menu-bar words backward] | ||
| 1602 | '("Backward word" . backward-word)) | ||
| 1603 | @end group | ||
| 1604 | @end example | ||
| 1605 | |||
| 1606 | A local keymap can cancel a menu bar item made by the global keymap by | ||
| 1607 | rebinding the same fake function key with @code{undefined} as the | ||
| 1608 | binding. For example, this is how Dired suppresses the @samp{Edit} menu | ||
| 1609 | bar item: | ||
| 1610 | |||
| 1611 | @example | ||
| 1612 | (define-key dired-mode-map [menu-bar edit] 'undefined) | ||
| 1613 | @end example | ||
| 1614 | |||
| 1615 | @noindent | ||
| 1616 | @code{edit} is the fake function key used by the global map for the | ||
| 1617 | @samp{Edit} menu bar item. The main reason to suppress a global | ||
| 1618 | menu bar item is to regain space for mode-specific items. | ||
| 1619 | |||
| 1620 | @defvar menu-bar-final-items | ||
| 1621 | Normally the menu bar shows global items followed by items defined by the | ||
| 1622 | local maps. | ||
| 1623 | |||
| 1624 | This variable holds a list of fake function keys for items to display at | ||
| 1625 | the end of the menu bar rather than in normal sequence. The default | ||
| 1626 | value is @code{(help)}; thus, the @samp{Help} menu item normally appears | ||
| 1627 | at the end of the menu bar, following local menu items. | ||
| 1628 | @end defvar | ||
| 1629 | |||
| 1630 | @node Modifying Menus | ||
| 1631 | @subsection Modifying Menus | ||
| 1632 | |||
| 1633 | When you insert a new item in an existing menu, you probably want to | ||
| 1634 | put it in a particular place among the menu's existing items. If you | ||
| 1635 | use @code{define-key} to add the item, it normally goes at the front of | ||
| 1636 | the menu. To put it elsewhere, use @code{define-key-after}: | ||
| 1637 | |||
| 1638 | @defun define-key-after map key binding after | ||
| 1639 | Define a binding in @var{map} for @var{key}, with value @var{binding}, | ||
| 1640 | just like @code{define-key}, but position the binding in @var{map} after | ||
| 1641 | the binding for the event @var{after}. For example, | ||
| 1642 | |||
| 1643 | @example | ||
| 1644 | (define-key-after my-menu [drink] | ||
| 1645 | '("Drink" . drink-command) 'eat) | ||
| 1646 | @end example | ||
| 1647 | |||
| 1648 | @noindent | ||
| 1649 | makes a binding for the fake function key @key{drink} and puts it | ||
| 1650 | right after the binding for @key{eat}. | ||
| 1651 | |||
| 1652 | Here is how to insert an item called @samp{Work} in the @samp{Signals} | ||
| 1653 | menu of Shell mode, after the item @code{break}: | ||
| 1654 | |||
| 1655 | @example | ||
| 1656 | (define-key-after | ||
| 1657 | (lookup-key shell-mode-map [menu-bar signals]) | ||
| 1658 | [work] '("Work" . work-command) 'break) | ||
| 1659 | @end example | ||
| 1660 | |||
| 1661 | Note that @var{key} is a sequence containing just one event type, but | ||
| 1662 | @var{after} is just an event type (not a sequence). | ||
| 1663 | @end defun | ||