view man/new-users-guide/custom1.texi @ 800:a5954632b187

[xemacs-hg @ 2002-03-31 08:27:14 by ben] more fixes, first crack at finishing behavior implementation TODO.ben-mule-21-5: Update. configure.in: Fix for new error-checking types. make-mswin-unicode.pl: Don't be fucked up by CRLF. Output code to force errors when nonintercepted Windows calls issued. behavior.el, dumped-lisp.el, menubar-items.el: Add support for saving using custom. Load into a dumped XEmacs. Correct :title to :short-doc in accordance with behavior-defs.el. Add a submenu under Options for turning on/off behaviors. cl-macs.el: Properly document `loop'. Fix a minor bug in keymap iteration and add support for bit-vector iteration. lisp-mode.el: Rearrange and add items for macro expanding. menubar-items.el: Document connection between these two functions. window.el: Port stuff from GNU 21.1. config.inc.samp, xemacs.mak: Separate out and add new variable for controlling error-checking. s/windowsnt.h: Use new ERROR_CHECK_ALL; not related to DEBUG_XEMACS. alloc.c, backtrace.h, buffer.c, buffer.h, bytecode.c, callproc.c, casetab.c, charset.h, chartab.c, cmdloop.c, config.h.in, console-msw.c, console-stream.c, console-tty.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dired-msw.c, dired.c, dumper.c, editfns.c, eldap.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, file-coding.h, fileio.c, frame-msw.c, frame.c, frame.h, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, insdel.c, intl-auto-encap-win32.c, intl-auto-encap-win32.h, intl-encap-win32.c, intl-win32.c, keymap.c, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-x.c, menubar.c, mule-coding.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, opaque.c, print.c, process-nt.c, process-unix.c, process.c, rangetab.c, redisplay-msw.c, redisplay-output.c, redisplay.c, regex.c, scrollbar-msw.c, select-msw.c, signal.c, specifier.c, specifier.h, symbols.c, sysdep.c, syswindows.h, text.c, text.h, toolbar-msw.c, tooltalk.c, ui-gtk.c, unicode.c, window.c: Redo error-checking macros: ERROR_CHECK_TYPECHECK -> ERROR_CHECK_TYPES, ERROR_CHECK_CHARBPOS -> ERROR_CHECK_TEXT, add ERROR_CHECK_DISPLAY, ERROR_CHECK_STRUCTURES. Document these in config.h.in. Fix code to follow docs. Fix *_checking_assert() in accordance with new names. Attempt to fix periodic redisplay crash freeing display line structures. Add first implementation of sledgehammer redisplay check. Redo print_*() to use write_fmt_string(), write_fmt_string_lisp(). Fix bug in md5 handling. Rename character-to-unicode to char-to-unicode; same for unicode-to-char{acter}. Move chartab documentation to `make-char-table'. Some header cleanup. Clean up remaining places where nonintercepted Windows calls are being used. automated/mule-tests.el: Fix for new Unicode support.
author ben
date Sun, 31 Mar 2002 08:30:17 +0000
parents 0784d089fdc9
children 47c30044fc4e
line wrap: on
line source

@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 a @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