Merge branch 'master' into comment-cache
[emacs.git] / doc / emacs / m-x.texi
blob0ee4e71470908df9e30915f95881b8a662b7d4b0
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2017 Free Software
3 @c Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node M-x
6 @chapter Running Commands by Name
8   Every Emacs command has a name that you can use to run it.  For
9 convenience, many commands also have key bindings.  You can run those
10 commands by typing the keys, or run them by name.  Most Emacs commands
11 have no key bindings, so the only way to run them is by name.
12 (@xref{Key Bindings}, for how to set up key bindings.)
14   By convention, a command name consists of one or more words,
15 separated by hyphens; for example, @code{auto-fill-mode} or
16 @code{manual-entry}.  Command names mostly use complete English words
17 to make them easier to remember.
19 @kindex M-x
20   To run a command by name, start with @kbd{M-x}, type the command
21 name, then terminate it with @key{RET}.  @kbd{M-x} uses the minibuffer
22 to read the command name.  The string @samp{M-x} appears at the
23 beginning of the minibuffer as a @dfn{prompt} to remind you to enter a
24 command name to be run.  @key{RET} exits the minibuffer and runs the
25 command.  @xref{Minibuffer}, for more information on the minibuffer.
27   You can use completion to enter the command name.  For example,
28 to invoke the command @code{forward-char}, you can type
30 @example
31 M-x forward-char @key{RET}
32 @end example
34 @noindent
37 @example
38 M-x forw @key{TAB} c @key{RET}
39 @end example
41 @noindent
42 Note that @code{forward-char} is the same command that you invoke with
43 the key @kbd{C-f}.  The existence of a key binding does not stop you
44 from running the command by name.
46 @cindex obsolete command
47   When @kbd{M-x} completes on commands, it ignores the commands that
48 are declared @dfn{obsolete}; for these, you will have to type their
49 full name.  Obsolete commands are those for which newer, better
50 alternatives exist, and which are slated for removal in some future
51 Emacs release.
53   To cancel the @kbd{M-x} and not run a command, type @kbd{C-g} instead
54 of entering the command name.  This takes you back to command level.
56   To pass a numeric argument to the command you are invoking with
57 @kbd{M-x}, specify the numeric argument before @kbd{M-x}.  The
58 argument value appears in the prompt while the command name is being
59 read, and finally @kbd{M-x} passes the argument to that command.
61 @vindex suggest-key-bindings
62   When the command you run with @kbd{M-x} has a key binding, Emacs
63 mentions this in the echo area after running the command.  For
64 example, if you type @kbd{M-x forward-word}, the message says that you
65 can run the same command by typing @kbd{M-f}.  You can turn off these
66 messages by setting the variable @code{suggest-key-bindings} to
67 @code{nil}.  The value of @code{suggest-key-bindings} can also be a
68 number, in which case Emacs will show the binding for that many
69 seconds before removing it from display.  The default behavior is to
70 display the binding for 2 seconds.
72 @vindex extended-command-suggest-shorter
73   Commands that don't have key bindings, can still be invoked after
74 typing less than their full name at the @samp{M-x} prompt.  Emacs
75 mentions such shorthands in the echo area if they are significantly
76 shorter than the full command name, and
77 @code{extended-command-suggest-shorter} is non-@code{nil}.  The
78 setting of @code{suggest-key-bindings} affects these hints as well.
80   In this manual, when we speak of running a command by name, we often
81 omit the @key{RET} that terminates the name.  Thus we might say
82 @kbd{M-x auto-fill-mode} rather than @kbd{M-x auto-fill-mode
83 @key{RET}}.  We mention the @key{RET} only for emphasis, such as when
84 the command is followed by arguments.
86 @findex execute-extended-command
87   @kbd{M-x} works by running the command
88 @code{execute-extended-command}, which is responsible for reading the
89 name of another command and invoking it.