comparison lisp/behavior-defs.el @ 2546:5d1743698fb3

[xemacs-hg @ 2005-02-03 05:26:39 by ben] behavior ws #3: behavior updates behavior.el: Major update. Add documentation of how it works. behavior-defs.el: Only define the basic behavior groups here. Move the definitions for particular packages to the appropriate package files. mwheel.el: Add define-behavior for mwheel.
author ben
date Thu, 03 Feb 2005 05:26:41 +0000
parents 79940b592197
children 308d34e9f07d
comparison
equal deleted inserted replaced
2545:9caf26dd924f 2546:5d1743698fb3
1 ;;; behavior-defs.el --- definitions of specific behaviors 1 ;;; behavior-defs.el --- definitions of specific behaviors
2 2
3 ;; Copyright (C) 2000, 2001, 2002 Ben Wing. 3 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing.
4 4
5 ;; Author: Ben Wing 5 ;; Author: Ben Wing
6 ;; Maintainer: XEmacs Development Team 6 ;; Maintainer: XEmacs Development Team
7 ;; Keywords: internal, dumped 7 ;; Keywords: internal, dumped
8 8
29 29
30 ;; Created July 2000 by Ben Wing. 30 ;; Created July 2000 by Ben Wing.
31 31
32 ;;; Commentary: 32 ;;; Commentary:
33 33
34 ;; This file will be dumped with XEmacs. 34 ;; This file is dumped with XEmacs.
35 35
36 ;;; Code: 36 ;;; Code:
37 37
38 (require 'behavior) 38 (define-behavior-group 'tty)
39 (define-behavior-group 'toolbars)
40 (define-behavior-group 'menus)
41 (define-behavior-group 'mouse)
42 (define-behavior-group 'editing)
43 (define-behavior-group 'keyboard)
44 (define-behavior-group 'files)
45 (define-behavior-group 'games)
46 (define-behavior-group 'processes)
47 (define-behavior-group 'display)
48 (define-behavior-group 'programming)
49 (define-behavior-group 'international)
50 (define-behavior-group 'buffers-and-windows)
51 (define-behavior-group 'internet)
39 52
40 (define-behavior 'scroll-in-place 53 (define-behavior 'compose-mail
41 "This package provides improved vertical scrolling commands for XEmacs. 54 "Not documented."
42 These new commands offer the following features: 55 :group 'internet
43 56 :commands
44 + When a scrolling command is executed, XEmacs tries to keep point as 57 '(["Send %_Mail..." compose-mail]))
45 close as possible to its original window position (window line and
46 column). This is what \"scroll in place\" means: point stays \"in place\"
47 within the window. (There are times when point must be moved from its
48 original window position in order to execute the scroll; see below.)
49
50 The variable `scroll-in-place', which is true by default, determines
51 whether or not the standard XEmacs scrolling commands (`scroll-down',
52 `scroll-up', `scroll-other-window-down', and `scroll-other-window') use
53 the \"in place\" features listed here. When `scroll-in-place' is `nil'
54 the standard XEmacs scrolling commands essentially just call the
55 original versions of themselves. (Note that even when `scroll-in-place'
56 is `nil' the new versions of `scroll-down' and `scroll-up' have slightly
57 different behavior when a minibuffer window is the selected window. See
58 below.)
59
60 It is possible to turn off (or turn on) \"in place\" scrolling for certain
61 buffers by making buffer-local bindings of the variable `scroll-in-
62 place' for those buffers. The variable `scroll-in-place' is not usually
63 buffer-local, but you can make it so if you desire.
64
65 + Because the improved scrolling commands keep point at its original
66 window position, these scrolling commands are \"reversible.\" The
67 `scroll-up' command undoes the effect of the immediately previous
68 `scroll-down' command (if any) and vice versa. In other words, if you
69 scroll up and then immediately scroll back down, the window config-
70 uration is restored to its exact original state. This allows you to
71 browse through a buffer more easily, as you can always get back to the
72 original configuration.
73
74 Note, however, that the improved scrolling commands are guaranteed to be
75 reversible only if there are no intervening non-scrolling commands.
76 Also, if you give a prefix argument to a scrolling command (in order to
77 specify the number of lines to scroll by), previous scrolling commands
78 may no longer be reversible. More specifically, if the new prefix
79 argument has a different magnitude than the previous scrolling distance,
80 then any previous scrolling commands are not reversible. The new prefix
81 argument takes precedence.
82
83 You might find it useful to think of the scrolling commands as forming
84 \"chains.\" A scrolling command either starts or continues a chain. By
85 issuing a non-scrolling command or by changing the number of lines to be
86 scrolled, you break the chain. (Note that simply changing the scrolling
87 direction won't break the chain; changing the absolute number of lines
88 to be scrolled is what breaks the chain.) Scrolling commands are
89 guaranteed to be reversible only within the current chain. Hopefully
90 that's clear enough.
91
92 + When a scrolling command is given a prefix argument (which specifies the
93 number of lines to scroll by), then that argument becomes the default
94 scrolling distance for all immediately subsequent scrolling commands.
95 This means that you can easily set the scrolling distance for a chain
96 of scrolling commands. Note that a new prefix argument or any non-
97 scrolling command breaks the chain (as described above), and any further
98 scrolling commands will use the usual defaults (or the prefix argument
99 you specify at that time, of course).
100
101 However, there are cases in which one doesn't want the current scrolling
102 command to use the default scrolling distance that was set by the
103 previous scrolling command. For example, suppose that you had special
104 commands that scrolled one line up and one line down. When you invoke
105 one of these commands, the \"in place\" scrolling routines set the default
106 scrolling distance to be just one line. Now suppose that you use one of
107 your special commands and then immediately invoke `scroll-up' (`C-v'),
108 expecting it to scroll by a near windowful of text. You would be
109 disappointed --- because the previous command set the default scrolling
110 distance to be just one line, `scroll-up' just scrolls by one line.
111
112 To solve this problem, \"scroll-in-place\" allows you to divide scrolling
113 commands into separate \"groups.\" Commands in a group can only form
114 chains with (and therefore, inherit defaults from) commands in the same
115 group. (Note that no command can be in more than one group.) If you
116 invoke a scrolling command that is not in the same group as that of the
117 immediately previous scrolling command, then the previous chain is
118 broken and you start a new chain --- with a new set of defaults.
119
120 So to solve the problem described above, you could put your one-line
121 scrolling commands in their own group. Once that is done, the standard
122 scrolling commands will not form chains with your one-line scrolling
123 commands, and therefore will not use the default scrolling distance set
124 by those commands. Problem solved!
125
126 By default, all \"in place\" scrolling commands are in a single group. If
127 you want to partition some commands into separate groups, you must do
128 that yourself *before* any \"in place\" commands are invoked. For more
129 information about grouping commands, see the documentation for the
130 variables `scroll-command-groups' and `scroll-default-command-group'.
131
132 + The improved scrolling commands will avoid displaying empty lines past
133 the end of the buffer when possible. In other words, just as you can't
134 see \"dead space\" before the beginning of the buffer text, the new
135 scrolling commands try to avoid displaying \"dead space\" past the end of
136 the buffer text. This behavior is somewhat configurable; see the
137 documentation for the variable `scroll-allow-blank-lines-past-eob'.
138
139 Dead space will be displayed if it is necessary in order to make a
140 previous scrolling action reversible, however.
141
142 + If the scrolling commands cannot keep point at its initial window
143 position (because a buffer boundary is on screen and the window can't be
144 scrolled as far as necessary to keep point at the right place), point is
145 allowed to temporarily stray from its initial window position. That is,
146 point moves the correct number of window lines, even if it means that it
147 has to stray from its desired window position. This straying is undone
148 when (and if) the scrolling action is reversed.
149
150 + If a scrolling command tries to move point past a buffer boundary, point
151 is instead moved to the boundary (the beginning or the end of the buffer
152 as appropriate) and an appropriate message is displayed. This motion is
153 reversible, of course.
154
155 However, if point was already at the buffer boundary when the scrolling
156 command was invoked, the command signals an appropriate error instead.
157
158 + When a minibuffer window is the selected window, the new versions of
159 `scroll-up' and `scroll-down' either scroll the window in the variable
160 `minibuffer-scroll-window' (which is usually the window of completions)
161 or the `next-window' if there is no `minibuffer-scroll-window'. This is
162 usually much more useful than scrolling the minibuffer itself. (Note
163 that this feature is available even when the variable `scroll-in-place'
164 is `nil'.)
165
166 + When a scrolling command is scrolling a window other than the selected
167 window, it will signal an appropriate buffer boundary error if the
168 window cannot be scrolled (because the appropriate buffer boundary is
169 already visible). This means that an error is signalled even in cases
170 that would be allowed (by \"straying\" point or by moving it to the buffer
171 boundary) if the window were selected.
172
173 (If an error were not signalled in these cases, then there would be many
174 cases in which the last scroll in a particular direction would appear to
175 do nothing because only the point position would change --- the
176 displayed text would stay the same! To avoid these cases the scrolling
177 commands signal boundary errors \"prematurely\" when the window to be
178 scrolled is not selected.)"
179 :short-doc "Keep cursor on same line when scrolling"
180 :require 'scroll-in-place
181 :enable #'turn-on-scroll-in-place
182 :disable #'turn-off-scroll-in-place)
183
184 (define-behavior 'mouse-avoidance
185 "For those who are annoyed by the mouse pointer obscuring text,
186 this mode moves the mouse pointer - either just a little out of
187 the way, or all the way to the corner of the frame.
188
189 Customize `mouse-avoidance-mode' to one of the symbols `banish',
190 `exile', `jump', `animate', `cat-and-mouse', `proteus', or `none'.
191
192 Effects of the different modes:
193 * banish: Move the mouse to the upper-right corner on any keypress.
194 * exile: Move the mouse to the corner only if the cursor gets too close,
195 and allow it to return once the cursor is out of the way.
196 * jump: If the cursor gets too close to the mouse, displace the mouse
197 a random distance & direction.
198 * animate: As `jump', but shows steps along the way for illusion of motion.
199 * cat-and-mouse: Same as `animate'.
200 * proteus: As `animate', but changes the shape of the mouse pointer too.
201
202 Whenever the mouse is moved, the frame is also raised.
203
204 \(see `mouse-avoidance-threshold' for definition of \"too close\",
205 and `mouse-avoidance-nudge-dist' and `mouse-avoidance-nudge-var' for
206 definition of \"random distance\".)"
207 :short-doc "Keep mouse away from cursor"
208 :enable #'(lambda ()
209 (mouse-avoidance-mode 'animate))
210 :disable #'(lambda ()
211 (mouse-avoidance-mode 'none)))
212
213 (define-behavior 'jka-compr
214 "This package implements low-level support for reading, writing,
215 and loading compressed files. It hooks into the low-level file
216 I/O functions (including write-region and insert-file-contents) so
217 that they automatically compress or uncompress a file if the file
218 appears to need it (based on the extension of the file name).
219 Packages like Rmail, VM, GNUS, and Info should be able to work
220 with compressed files without modification."
221 :short-doc "Transparently handle compressed files"
222 :enable #'jka-compr-install
223 :disable #'jka-compr-uninstall)
224
225 (define-behavior 'efs
226 "EFS is a system for transparent file-transfer between remote VMS, CMS,
227 MTS, MVS, Twenex, Explorer (the last two are Lisp machines), TOPS-20,
228 DOS (running the Distinct, Novell, FTP software, NCSA, Microsoft in both
229 unix and DOS mode, Super TCP, and Hellsoft FTP servers), Windows NT
230 \(running the Microsoft or Hummingbird ftp servers), Unix descriptive
231 listings (dl), KA9Q, OS/2 hosts using FTP. This means that you can edit,
232 copy and otherwise manipulate files on any machine you have access to
233 from within Emacs as if it were a local file. EFS works by introducing
234 an extended filename syntax, and overloading functions such as
235 `insert-file-contents' so that accessing a remote file causes
236 appropriate commands to be sent to an FTP process.
237
238 The syntax to use is like this:
239
240 \(for anonymous:) /ftp.xemacs.org:/pub/xemacs/
241 \(for non-anonymous:) /ben@gwyn.tux.org:/etc/mail/xemacs/aliases-xemacs
242
243 You can specify either a file or a directory (in the latter case,
244 Dired will be brought up). All operations in XEmacs on such files
245 should work exactly as on any other files, modulo the additional
246 slowness."
247 :short-doc "Transparent file access over FTP"
248 :require 'efs-auto
249 :enable #'ignore
250 ;; can't :disable
251 )
252
253
254 (define-behavior 'resize-minibuffer
255 "When this behavior is enabled, the minibuffer is dynamically resized to
256 contain the entire region of text put in it as you type.
257
258 The maximum height to which the minibuffer can grow is controlled by the
259 variable `resize-minibuffer-window-max-height'.
260
261 The variable `resize-minibuffer-window-exactly' determines whether the
262 minibuffer window should ever be shrunk to make it no larger than needed to
263 display its contents.
264
265 When using a window system, it is possible for a minibuffer to be the sole
266 window in a frame. Since that window is already its maximum size, the only
267 way to make more text visible at once is to increase the size of the frame.
268 The variable `resize-minibuffer-frame' controls whether this should be
269 done. The variables `resize-minibuffer-frame-max-height' and
270 `resize-minibuffer-frame-exactly' are analogous to their window
271 counterparts."
272 :short-doc "Resize minibuffer automatically"
273 :enable #'(lambda ()
274 (resize-minibuffer-mode 1))
275 :disable #'(lambda ()
276 (resize-minibuffer-mode -1)))
277
278 (define-behavior 'func-menu
279 "Suppose you have a file with a lot of functions in it. Well, this
280 package makes it easy to jump to any of those functions. The names of
281 the functions in the current buffer are automatically put into menubar
282 menu, you select one of the function-names and the point is moved to
283 that very function. The mark is pushed on the mark-ring, so you can
284 easily go back to where you were. Alternatively, you can use enter the
285 name of the desired function via the minibuffer which offers
286 completing read input. In addition, the name of the function before
287 point is optionally displayed in the modeline."
288 :short-doc "Add a menu of defined functions"
289 :require 'func-menu
290 :enable #'(lambda ()
291 (add-hook 'find-file-hooks 'fume-add-menubar-entry)
292 (mapc #'(lambda (buffer)
293 (with-current-buffer buffer
294 (setq fume-display-in-modeline-p t)
295 (fume-add-menubar-entry)))
296 (buffer-list)))
297 :disable #'(lambda ()
298 (remove-hook 'find-file-hooks 'fume-add-menubar-entry)
299 (fset 'widen (symbol-function 'fume-widen))
300 (fset 'narrow-to-region (symbol-function 'narrow-to-region))
301 (mapc #'(lambda (buffer)
302 (with-current-buffer buffer
303 (fume-remove-menubar-entry)
304 (setq fume-display-in-modeline-p nil)
305 (fume-remove-post-command-hook
306 'fume-tickle-modeline)
307 (fume-remove-post-command-hook
308 'fume-maybe-install-modeline-feature)
309 (fume-remove-post-command-hook
310 'fume-rescan-buffer-trigger)))
311 (buffer-list))))
312
313 (define-behavior 'mwheel
314 "This code enables the use of the infamous 'wheel' on the new
315 crop of mice. Under XFree86 and the XSuSE X Servers, the wheel
316 events are sent as button4/button5 events, which are automatically
317 set up to do scrolling in the expected way. The actual way that the
318 scrolling works can be controlled by `mwheel-scroll-amount' and
319 `mwheel-follow-mouse'."
320 :short-doc "Mouse wheel support for X Windows"
321 :enable 'mwheel-install)
322
323 (define-behavior 'recent-files
324 "Recent-files adds the menu \"Recent Files\" (or whatever name you
325 choose, see \"Customization:\" below) to Emacs's menubar. Its
326 entries are the files (and directories) that have recently been
327 opened by Emacs. You can open one of these files again by
328 selecting its entry in the \"Recent Files\" menu. The list of file
329 entries in this menu is preserved from one Emacs session to
330 another. You can prevent Emacs from saving this list by selecting
331 \"Don't save recent-files list on exit\" from the menu. If you have
332 disabled saving, you can re-enable it by selecting \"Save
333 recent-files list on exit\".
334
335 The menu has permanent and non-permanent entries. Permanent
336 entries are marked with an asterisk in front of the filename. The
337 non-permanent entries are hidden in a submenu.
338
339 Each time you open a file in Emacs, it is added as a non-permanent
340 entry to the menu. The value of `recent-files-number-of-entries'
341 determines how many non-permanent entries are held in the
342 menu. When the number of non-permanent entries reaches this value,
343 the least recently added non-permanent entry is removed from the
344 menu when another non-permanent entry is added. It is not removed
345 from the list, though; it may reappear when entries are deleted
346 from the list. The number of entries saved to disk is the value of
347 the variable `recent-files-number-of-saved-entries'.
348
349 Permanent entries are not removed from the menu. You can make a
350 file entry permanent by selecting \"Make <buffer> permanent\" (where
351 <buffer> is the name of the current buffer) when the current
352 buffer holds this file. \"Make <buffer> non-permanent\" makes the
353 file entry of the current buffer non-permanent.
354
355 The command \"Kill buffer <buffer> and delete entry\" is handy when
356 you have accidently opened a file but want to keep neither the
357 buffer nor the entry.
358
359 You can erase the list of non-permanent entries by selecting
360 \"Erase non-permanent entries\" from the menu.
361
362 Customization:
363
364 There are lots of variables to control the behaviour of
365 recent-files. You do not have to change any of them if you like it
366 as it comes out of the box. However, you may want to look at these
367 options to make it behave different.
368
369 `recent-files-number-of-entries'
370 Controls how many non-permanent entries are shown in the
371 recent-files list. The default is 15.
372
373 `recent-files-number-of-saved-entries'
374 Controls how many non-permanent entries are saved to disk when
375 Emacs exits or recent-files-save-the-list is called. The
376 default is 50.
377
378 `recent-files-save-file'
379 The name of the file where the recent-files list is saved
380 between Emacs session. You probably don't need to change this.
381 The default is \".recent-files.el\" in your home directory.
382
383 `recent-files-dont-include'
384 A list of regular expressions for files that should not be
385 included into the recent-files list. This list is empty by
386 default. For instance, a list to exclude all .newsrc
387 files, all auto-save-files, and all files in the /tmp
388 directory (but not the /tmp directory itself) would look
389 like this:
390 (setq recent-files-dont-include
391 '(\"/\\.newsrc\" \"~$\" \"^/tmp/.\"))
392 The default is empty.
393
394 `recent-files-use-full-names'
395 If the value of this variable is non-nil, the full pathnames of
396 the files are shown in the recent-files menu. Otherwise only
397 the filename part (or the last name component if it is a
398 directory) is shown in the menu. The default it t, i.e. show
399 full names.
400
401 `recent-files-filename-replacements'
402 This is a list of pairs of regular expressions and replacement
403 strings. If a filename matches one of the regular expressions,
404 the matching part is replaced by the replacement string for
405 display in the recent-files menu.
406 Example: My home directory is \"/users/mmc/nickel/\". I want to
407 replace it with \"~/\". I also want to replace the directory
408 \"/imports/teleservices/mmc/avc2/\", where I work a lot, with
409 \".../avc2/\". The list then looks like
410 (setq recent-files-filename-replacements
411 '((\"/users/mmc/nickel/\" . \"~/\")
412 (\"/imports/teleservices/mmc/avc2/\" . \".../avc2/\")))
413 Only the first match is replaced. So, if you have several
414 entries in this list that may match a filename simultaneously,
415 put the one you want to match (usually the most special) in
416 front of the others. The default is to replace the home
417 directory with \"~\".
418
419 `recent-files-sort-function'
420 Contains a function symbol to sort the display of filenames in
421 the recent-files menu. Supplied are two functions,
422 'recent-files-dont-sort and 'recent-files-sort-alphabetically.
423 The first, which is the default, preserves the order of \"most
424 recent on top\".
425
426 `recent-files-permanent-submenu'
427 If this variable is non-nil, the permanent entries are put into
428 a separate submenu of the recent-files menu. The default is
429 nil.
430
431 `recent-files-non-permanent-submenu'
432 If this variable is non-nil, the non-permanent entries are put
433 into a separate submenu of the recent-files menu. The default
434 is nil. (You can set both `recent-files-permanent-submenu' and
435 `recent-files-non-permanent-submenu' to t to have both lists in
436 separate submenus.)
437
438 `recent-files-commands-submenu'
439 If this variable is non-nil, the commands if recent-files are
440 placed in a submenu of the recent-files menu. The default is
441 nil.
442
443 `recent-files-commands-submenu-title'
444 If the commands are placed in a submenu, this string is used as
445 the title of the submenu. The default is \"Commands...\".
446
447 `recent-files-actions-on-top'
448 If this variable is non-nil, the \"action\" menu entries (\"Make
449 <buffer> permanent\" etc.) are put on top of the menu. Otherwise
450 they appear below the file entries or submenus. The default is
451 nil.
452
453 `recent-files-permanent-first'
454 If this variable is t, the permanent entries are put first in
455 the recent-files menu, i.e. above the non-permanent entries. If
456 the value is nil, non-permanent entries appear first. If the
457 value is neither t nor nil, the entries are sorted according to
458 recent-files-sort-function. The default is 'sort.
459
460 `recent-files-find-file-command'
461 This variable contains to commandto execute when a file entry
462 is selected from the menu. Usually this will be `find-file',
463 which is the default.
464
465 KNOWN BUG:
466 - recent-files overwrites the recent-files-save-file
467 unconditionally when Emacs exits. If you have two Emacs
468 processes running, the one exiting later will overwrite the
469 file without merging in the new entries from the other Emacs
470 process. This can be avoided by disabling the save on exit from
471 the menu."
472 :short-doc "`Recent Files' menu"
473 :enable 'recent-files-initialize)
474
475 (define-behavior 'filladapt
476 "These functions enhance the default behavior of Emacs' Auto Fill
477 mode and the commands `fill-paragraph', `lisp-fill-paragraph',
478 `fill-region-as-paragraph' and `fill-region'.
479
480 The chief improvement is that the beginning of a line to be
481 filled is examined and, based on information gathered, an
482 appropriate value for fill-prefix is constructed. Also the
483 boundaries of the current paragraph are located. This occurs
484 only if the fill prefix is not already non-nil.
485
486 The net result of this is that blurbs of text that are offset
487 from left margin by asterisks, dashes, and/or spaces, numbered
488 examples, included text from USENET news articles, etc. are
489 generally filled correctly with no fuss."
490 :short-doc "Adaptive (smart) filling"
491 :require 'filladapt
492 :enable #'(lambda ()
493 (setq-default filladapt-mode t)
494 (mapc #'(lambda (buffer)
495 (with-current-buffer buffer
496 (unless filladapt-mode
497 (filladapt-mode 1))))
498 (buffer-list)))
499 :disable #'(lambda ()
500 (setq-default filladapt-mode nil)
501 (mapc #'(lambda (buffer)
502 (with-current-buffer buffer
503 (when filladapt-mode
504 (filladapt-mode -1))))
505 (buffer-list))))