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