0
|
1 @comment node-name, next, previous, up
|
|
2 @node Customization Basics, Help, Edit, Top
|
|
3 @chapter Customize key bindings and menus
|
|
4 @cindex .emacs
|
|
5 @cindex customize
|
|
6 @findex eval-region
|
|
7
|
|
8 When you start Emacs, it reads the file @file{~/.emacs} in your home
|
|
9 directory. You can use this file to initialize and customize Emacs to
|
|
10 your liking. This file should contain lisp-code. You can customize your
|
|
11 @file{.emacs} file to create new
|
|
12 menus, disable menus, change key bindings, enable a minor mode, etc. Any
|
|
13 kind of customization affects
|
|
14 only a particular Emacs job that you do them in. If you want to save
|
|
15 your customizations `permanently' i.e. for future use also, you have to
|
|
16 put it in your @samp{.emacs} file. After you make changes to your
|
|
17 @file{.emacs} file and save it, the changes will be effective only after
|
|
18 you start Emacs again i.e. for a new Emacs process. To try out some of
|
|
19 the examples in this section, highlight that region and evaluate the
|
|
20 region by giving the command @kbd{M-x eval-region}. You will be able to
|
|
21 see the results of your customizations in that Emacs session only
|
|
22 (@pxref{Lisp Eval,,,,XEmacs User's Manual}).
|
|
23
|
|
24 @comment node-name, next, previous, up
|
|
25 @menu
|
|
26 * Customizing key Bindings:: Changing Key Bindings
|
|
27 * Customizing Menus:: Adding, Deleting, Enabling and Disabling Menus
|
|
28 @end menu
|
|
29
|
|
30 @node Customizing key Bindings, Customizing Menus, Customization Basics, Customization Basics
|
|
31 @section Customize key bindings
|
|
32 @cindex key bindings
|
|
33 @cindex keystrokes
|
|
34
|
|
35 Most of Emacs commands use key sequences. @xref{Keystrokes,,,,XEmacs
|
|
36 Manual}, for more information about Keys and Commands. In Emacs, the
|
|
37 keys themselves carry no meaning unless they are bound to a
|
|
38 function. For example, @kbd{C-n} moves the cursor to the next line
|
|
39 because its bound to the function @b{next-line}. Similarly, @kbd{C-p}
|
|
40 moves to the previous line because its bound to the function
|
|
41 @b{previous-line}. The functions themselves define a particular
|
|
42 behavior. You can customize the key @kbd{C-n} to move to the previous
|
|
43 line by binding it to @b{previous-line} and @kbd{C-p} to move to the
|
|
44 next line by binding it to @b{next-line}. To bind keys to globally run
|
|
45 commands you need to use the following syntax in your @b{.emacs} file:
|
|
46
|
|
47 @cindex binding keys
|
|
48 @example
|
|
49 @code{(global-set-key @var{keys} @var{cmd})}
|
|
50 @end example
|
|
51 @noindent
|
|
52 Here, @code{global-set-key} is a function which will bind the
|
|
53 @dfn{keys} to the specified @dfn{cmd}. For example, if you type the
|
|
54 following in your @b{.emacs} file:
|
|
55
|
|
56 @example
|
|
57 (global-set-key "\C-p" 'next-line)
|
|
58 (global-set-key "\C-n" 'previous-line)
|
|
59 @end example
|
|
60
|
|
61 @noindent
|
|
62 then @kbd{C-p} will move to the next line and @kbd{C-n} to the previous
|
|
63 line.
|
|
64
|
|
65 You can also disable a key binding, by using @samp{nil} as the @var{cmd}
|
|
66 in the syntax stated above. Here, @samp{nil} stands for @samp{false}
|
|
67 which means disable a command or turn off a feature. If you want to
|
|
68 enable a command or turn on a particular feature use @samp{t}
|
|
69 which stands for @samp{true}. For example, if you do not wish @kbd{C-x
|
|
70 C-c} to @samp{Exit Emacs} you can type the following expression in your
|
|
71 @file{.emacs} file:
|
|
72
|
|
73 @example
|
|
74 (global-set-key "\C-x\C-c" nil)
|
|
75 @end example
|
|
76
|
|
77 @noindent
|
|
78 You might want to have this statement in your @file{.emacs} file because
|
|
79 its easy to hit this command by mistake and it could be annoying to exit
|
|
80 Emacs unintentionally. There is a @b{Exit Emacs} option in the @b{File
|
|
81 menu} which you might want to use instead. To make a particular key
|
|
82 undefined you can also use:
|
|
83
|
|
84 @example
|
|
85 (global-unset-key "\C-x\C-c")
|
|
86 @end example
|
|
87
|
|
88 @noindent
|
|
89 Now if you use the command @kbd{C-x C-c}, you will get an error saying
|
|
90 that the command is undefined.
|
|
91
|
|
92 Some other customizations you could try are:
|
|
93 @itemize @bullet
|
|
94
|
|
95 @item
|
|
96 @example
|
|
97 (global-set-key 'button3 'beginning-of-buffer)
|
|
98 @end example
|
|
99
|
|
100 @noindent
|
|
101 Now when you press the third button of your mouse, the cursor will be
|
|
102 placed at the @code{beginning-of-buffer}.
|
|
103
|
|
104 @item
|
|
105 @example
|
|
106 (global-set-key 'f1 'goto-line)
|
|
107 @end example
|
|
108
|
|
109 @noindent
|
|
110 If you press the @key{F1} key, you will be prompted for a line
|
|
111 number. After you type the line number and hit @key{RET}, the cursor
|
|
112 will be placed on that line number.
|
|
113
|
|
114 @item
|
|
115 @example
|
|
116 (global-set-key 'f2 'undo)
|
|
117 @end example
|
|
118
|
|
119 Pressing @key{F2} will undo the last command. If you have a @key{undo}
|
|
120 key on your keyboard, try binding that key to the undo command.
|
|
121 @end itemize
|
|
122
|
|
123
|
|
124 Another syntax for customizing key bindings is:
|
|
125 @code{(define-key @var{keymap} @var{keys} @var{def})}
|
|
126 It defines @var{keys} to run @var{def} in the keymap @var{keymap}.
|
|
127
|
|
128 @var{keymap} is a keymap object which records the bindings of keys to
|
|
129 the commands that they run.
|
|
130
|
|
131 @var{keys} is the sequence of keystrokes to bind.
|
|
132
|
|
133 @var{def} is anything that can be a key's definition:
|
|
134
|
|
135 Look at the following two examples:
|
|
136
|
|
137 @example
|
|
138 (define-key global-map "\C-xl" 'make-symbolic-link)
|
|
139 (define-key c-mode-map "\C-xl" 'make-symbolic-link)
|
|
140 @end example
|
|
141
|
|
142 @findex make-symbolic-link
|
|
143 @noindent
|
|
144 Both the examples bind the key @kbd{C-xl} to run the function
|
|
145 @code{make-symbolic-link} (@pxref{Misc File Ops,,,,XEmacs User's
|
|
146 Manual}). However, the second example will bind the key only for C
|
|
147 mode. @xref{Major Modes,,,,XEmacs User's Manual}, for more
|
|
148 information on Major Modes in XEmacs.
|
|
149
|
|
150
|
|
151
|
|
152 @comment node-name, next, previous, up
|
|
153 @node Customizing Menus, , Customizing key Bindings, Customization Basics
|
|
154 @section Customizing Menus
|
|
155 @cindex customize menus
|
|
156 @cindex delete menus
|
|
157 @cindex disable menus
|
|
158 @findex add-menu-item
|
|
159 @cindex add menus
|
|
160
|
|
161 You can customize any of the XEmacs Pull-down-Menus. You can create your
|
|
162 own menu, delete an existing one, enable a menu or disable a menu. For
|
|
163 more information on the default menus available to you, @xref{Pull-down
|
|
164 Menus}.
|
|
165
|
|
166 Some of the functions which are available to you for customization are:
|
|
167 @enumerate
|
|
168
|
|
169 @item add-menu-item: @var{(menu-name item-name function enabled-p
|
|
170 &optional before)}
|
|
171
|
|
172 This function will add a menu item to a menu, creating the menu first if
|
|
173 necessary. If the named item already exists, the menu will remain
|
|
174 unchanged. For example, if you add the following example to your
|
|
175 @file{.emacs} file or evaluate it (@pxref{Customization Basics}),
|
|
176
|
|
177 @example
|
|
178 (add-menu-item '("Edit") "Replace String" replace-string t "Clear")
|
|
179 @end example
|
|
180
|
|
181 @noindent
|
|
182 a sub-menu @b{Replace String} will be created under @b{Edit} menu before the
|
|
183 sub-menu @b{Clear}. The @b{Edit} menu will now look like:
|
|
184
|
|
185 @example
|
|
186 Undo C-x u
|
|
187 Cut cut
|
|
188 Copy copy
|
|
189 Paste paste
|
|
190 Replace String
|
|
191 Clear
|
|
192 Start Macro Recording C-x(
|
|
193 End Macro Recording C-x)
|
|
194 Execute Last Macro C-xe
|
|
195 @end example
|
|
196
|
|
197 @noindent
|
|
198 @b{Replace String} will now execute the function
|
|
199 @code{replace-string}. Select this menu item. Emacs will prompt you for
|
|
200 a string name to be replaced. Type a
|
|
201 string and hit @key{RET}. Now type a new string to replace the old
|
|
202 string and hit @key{RET}. All occurrences of the old string will be
|
|
203 replaced by the new string. In this example,
|
|
204
|
|
205 @samp{Edit} is the @var{menu-name} which identifies the menu into which
|
|
206 the new menu item should be inserted.
|
|
207
|
|
208 @samp{Replace String} is the @var{item-name} which names the menu item
|
|
209 to be added.
|
|
210
|
|
211 @samp{replace-string} is the @var{function} i.e. the command to be
|
|
212 invoked when the menu item "Replace String" is selected.
|
|
213
|
|
214 @samp{t} is the @var{enabled-p} parameter which controls whether the
|
|
215 menu item is selectable or not. This parameter can be either @code{t} (selectable), @code{nil} (not selectable), or a
|
|
216 form to evaluate. This form is evaluated just before the menu is
|
|
217 displayed, and the menu item will be selectable if the form returns
|
|
218 non-@code{nil}.
|
|
219
|
|
220 @samp{Clear} is the @var{&optional before} parameter which is the name
|
|
221 of the menu before which the new menu or sub-menu should be added. The
|
|
222 @var{&optional} string means that this parameter is optional. You do not
|
|
223 need to specify this parameter. If you do not specify this parameter in
|
|
224 the example above, the @b{Replace String} menu item will be added at the
|
|
225 end of the list of sub-menus in the @b{Edit} menu i.e. after @b{Execute
|
|
226 Last Macro}.
|
|
227
|
|
228 If you wish to add a new menu to the menubar, try:
|
|
229
|
|
230 @example
|
|
231 (add-menu-item nil "Bot" 'end-of-buffer t)
|
|
232 @end example
|
|
233
|
|
234 @noindent
|
|
235 This will create a new menu @b{Bot} on the menu bar. Selecting this menu
|
|
236 will take you to the end of the buffer. Using @code{nil} for the
|
|
237 parameter @var{menu-name} will create a new menu. Your menu-bar
|
|
238 will now look like:
|
|
239
|
|
240 @example
|
|
241 File Edit Options Buffers Bot Help
|
|
242 @end example
|
|
243
|
|
244 The following example will illustrate how you can add sub-menus to the
|
|
245 submenus themselves:
|
|
246
|
|
247 @example
|
|
248 (add-menu-item '("File" "Management") "Copy File" 'copy-file t)
|
|
249 (add-menu-item '("File" "Management") "Delete File" 'delete-file t)
|
|
250 (add-menu-item '("File" "Management") "Rename File" 'rename-file t)
|
|
251 @end example
|
|
252 @noindent
|
|
253
|
|
254 This will create a sub-menu @b{Management} under the @b{File}
|
|
255 menu. When you select the submenu @b{Management}, it will contain three
|
|
256 submenus: @b{Copy File}, @b{Delete File} and @b{Rename File}.
|
|
257
|
|
258 @findex delete-menu-item
|
|
259 @cindex deleting menu items
|
|
260 @item delete-menu-item: @var{(menu-path)}
|
|
261 This function will remove the menu item defined by @var{menu-name} from
|
|
262 the menu hierarchy. Look at the following examples and the comments just
|
|
263 above them which specify what the examples do.
|
|
264
|
|
265 @example
|
|
266 ;; deletes the "Replace String" menu item created earlier
|
|
267 (delete-menu-item '("Edit" "Replace String"))
|
|
268
|
|
269 ;; deletes the "Bot" menu created earlier
|
|
270 (delete-menu-item '("Bot"))
|
|
271
|
|
272 ;; deletes the sub-menu "Copy File" created earlier
|
|
273 (delete-menu-item '("File" "File Management" "Copy File"))
|
|
274
|
|
275 ;; deletes the sub-menu "Delete File" created earlier
|
|
276 (delete-menu-item '("File" "Management" "Delete File"))
|
|
277
|
|
278 ;; deletes the sub-menu "Rename File" created earlier
|
|
279 (delete-menu-item '("File" "Management" "Rename File"))
|
|
280 @end example
|
|
281
|
|
282
|
|
283 @findex disable-menu-item
|
|
284 @cindex disabling menu items
|
|
285 @item disable-menu-item: @var{(menu-name)}
|
|
286 Disables the specified menu item. The following example
|
|
287
|
|
288 @example
|
|
289 (disable-menu-item '("File" "Management" "Copy File"))
|
|
290 @end example
|
|
291
|
|
292 @noindent
|
|
293 will make the @b{Copy File} item unselectable. This menu-item would
|
|
294 still be there but it will appear faded which would mean that it cannot
|
|
295 be selected.
|
|
296
|
|
297 @findex enable-menu-item
|
|
298 @cindex enabling menu items
|
|
299 @item enable-menu-item: @var{(menu-name)}
|
|
300 Enables the specified previously disabled menu item.
|
|
301
|
|
302 @example
|
|
303 (enable-menu-item '("File" "Management" "Copy File"))
|
|
304 @end example
|
|
305
|
|
306 @noindent
|
|
307 This will enable the sub-menu @b{Copy File}, which was disabled by the
|
|
308 earlier command.
|
|
309
|
|
310 @findex relabel-menu-items
|
|
311 @cindex relabelling menu items
|
|
312 @item relabel-menu-item: @var{(menu-name new-name)}
|
|
313 Change the string of the menu item specified by @var{menu-name} to
|
|
314 @var{new-name}.
|
|
315
|
|
316 @example
|
|
317 (relabel-menu-item '("File" "Open...") "Open File")
|
|
318 @end example
|
|
319
|
|
320 This example will rename the @b{Open...} menu item from the @b{File}
|
|
321 menu to @b{Open File}.
|
|
322
|
|
323 @end enumerate
|
|
324
|