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