annotate lisp/behavior.el @ 5760:995257d0c590

Added tag r21-5-latest-beta for changeset 6c2aa9851f5e
author Stephen J. Turnbull <stephen@xemacs.org>
date Tue, 27 Aug 2013 01:33:34 +0900
parents 66d2f63df75f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
1 ;;; behavior.el --- consistent interface onto packages
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
2
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
3 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
4
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
5 ;; Author: Ben Wing
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
7 ;; Keywords: internal, dumped
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
8
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
9 ;; This file is part of XEmacs.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
10
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
11 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
12 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
13 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
14 ;; option) any later version.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
15
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
19 ;; for more details.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
20
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5271
diff changeset
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
23
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
24 ;;; Synched up with: Not in FSF.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
25
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
26 ;;; Authorship:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
27
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
28 ;; Created July 2000 by Ben Wing.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
29
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
30 ;;; Commentary:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
31
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
32 ;; This file is dumped with XEmacs.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
33
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
34 ;; This file is part of the "Behaviors" project and is a work in progress.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
35 ;; The purpose of the project is to provide (a) a consistent interface (at
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
36 ;; the API level) onto the functionality provided by packages, and (b) an
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
37 ;; easy-to-use user interface for this functionality, something that
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
38 ;; *really works*.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
39 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
40 ;; First, what characteristics do/should packages have? (NOTE: In this
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
41 ;; discussion below, `package' and `behavior' are being used more or less
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
42 ;; interchangeably. Eventually this will get resolved.)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
43
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
44 ;; 1) A file, or one or more file, containing the code of the package. In
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
45 ;; addition, a "head" file in the case that the package needs to be
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
46 ;; loaded in order to get its functionality (e.g. "load-to-enable"
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
47 ;; packages -- an abomination that is tolerated only with severe
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
48 ;; displeasure).
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
49 ;; 2) A Lisp name -- a fairly short symbol (2-3 words max), uncapitalized,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
50 ;; without use of excessive abbreviation and with words set off by
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
51 ;; dashes. This should be the same as the name of the topmost custom
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
52 ;; group associated with the package (see next item), and preferably the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
53 ;; same as the common prefix used for variables defined by your package
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
54 ;; and the name of the head file of the package.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
55 ;; 3) Associated custom group listing the settings associated with the package.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
56 ;; 4) Enable and disable methods for turning on or off the functionality of
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
57 ;; the package, if it's amenable to such a model. Most packages are of two
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
58 ;; types:
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
59 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
60 ;; (a) They add some functionality to XEmacs, which is incorporated
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
61 ;; into and makes changes to the normal functionality of XEmacs. Once the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
62 ;; package is enabled, the user doesn't have to do anything specific for
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
63 ;; the package to do its thing -- it happens automatically if the user is
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
64 ;; using the area whose behavior has been changed. These include packages
5750
66d2f63df75f Correct some spelling and formatting in behavior.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5666
diff changeset
65 ;; such as `avoid' (which makes the mouse pointer move when the cursor
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
66 ;; gets too close), EFS (which adds the ability to treat an FTP site as
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
67 ;; part of the local file system), the packages that supply the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
68 ;; mode-specific handling for various files, etc
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
69 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
70 ;; (b) They provide functionality in the form of specific command to be
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
71 ;; invoked. This can be as simple as the `hippie-expand' command (tries
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
72 ;; lots of different expansion methods for the text before point, to
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
73 ;; try and get a result) and as complicated as GNUS or VM.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
74 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
75 ;; Some packages might provide both -- you can enable them and they
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
76 ;; incorporate some functionality into the XEmacs base, but while
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
77 ;; they're enabled they provide certain commands. #### We need some
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
78 ;; thought here, and case-by-case analysis, to determine if this really
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
79 ;; makes sense -- can the enable/disable be removed and whatever needs
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
80 ;; to happen incorporated as part of the command? can the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
81 ;; enable/disable just added to the commands?
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
82 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
83 ;; 5) Packages of type (b) just above will have a list of commands that can be
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
84 ;; run. They should be in standard menubar format -- i.e. just like a
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
85 ;; submenu, but without the initial string indidicating the name of the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
86 ;; menu.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
87 ;; 6) Short doc string, for use in a menu item. *NOT* necessarily the same
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
88 ;; as the documentation for the Custom group, which is often too long.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
89 ;; 7) Long documentation.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
90 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
91 ;; Good package etiquette:
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
92 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
93 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
94 ;; -- Never mess with the menu yourself, or try to "cheat" by putting yourself
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
95 ;; high up in the hierarchy, e.g. at the top-level or directly off a
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
96 ;; top-level group that expects to contain only groups of groups, not
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
97 ;; end-level groups.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
98 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
99 ;; -- Never use the `override-behavior' commands or the like for specifying
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
100 ;; (in an overriding fashion) the exact appearance of the hierarchies.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
101 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
102 ;; -- For type (a), with enable/disable methods:
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
103 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
104 ;; (a) Loading the file should NOT DO ANYTHING. Not enable, not add hooks,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
105 ;; nothing.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
106 ;; (b) Both enable and disable hooks must exist. The disable hook must
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
107 ;; completely reset the environment to how it was before the package
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
108 ;; was enabled. This includes restoring the prior bindings for
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
109 ;; modified key bindings. #### We need some helper function to assist
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
110 ;; with remembering the old key bindings and putting them back only
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
111 ;; when new key bindings haven't been made -- but recognize when those
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
112 ;; new key bondings were attached as a result of loading another
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
113 ;; package, so that after any order of loading and unloading a series
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
114 ;; of packages, the original bindings will eventually occur. (Something
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
115 ;; like `advice' for key definitions.) Replacement of functions should
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
116 ;; happen through `advice'.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
117 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
118 ;; We recognize that many packages out there don't follow these precepts at
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
119 ;; all. Many or most of them are install-only, often happening
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
120 ;; automatically when the file is loaded. Converting these will be a step
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
121 ;; at a time: First, redo the latter type so that the initialization code
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
122 ;; is put into a function and not run automatically upon load. Next step,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
123 ;; try to provide some sort of disable. Third step, work on making sure
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
124 ;; that disable removes *everything* and enable puts it all back. Fourth
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
125 ;; step, work on properly advising keys and functions.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
126 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
127
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
128 ;; Comparison/Integration with Custom:
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
129
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
130 ;; Custom only handles variable settings, and has no concept of standard
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
131 ;; enable/disable methods for a package, a standard way of specifying
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
132 ;; package documentation, or a list of commands associated with a package.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
133 ;; Also, its groups do not always map very well onto packages and the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
134 ;; resulting hierarchy is too big, confusing, difficult-to-navigate, and
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
135 ;; incoherent. More generally it does not address at all the basic problem
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
136 ;; that a hierarchy created in a decentralized fashion -- and by a large
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
137 ;; number of authors, some more competent than others -- will inevitably be
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
138 ;; incoherent when put together.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
139 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
140
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
141 ;; In general, ease-of-use was not the overarching goal of Custom. The
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
142 ;; primary goal of Custom seems to have been to provide a consistent interface
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
143 ;; and get all the packages to use it. Ease-of-use -- or even following
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
144 ;; established user-interface standards -- has taken a far-distant second, and
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
145 ;; appears in many respects to be an afterthought that never had any serious
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
146 ;; effort investigated into it.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
147 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
148 ;; The eventual intent of this project is to integrate with custom. The final
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
149 ;; intent of integration is that this project subsumes Custom completely,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
150 ;; making Custom the unified, user-friendly means of controlling XEmacs that
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
151 ;; has never properly existed. However, that will take a lot of work. For
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
152 ;; the meantime, the plan is to develop the Behavior subsystem independent of
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
153 ;; Custom, with ease-of-use as the primary goal, and get it to the point where
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
154 ;; it encompasses most packages out there, has stabilized its interface, and
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
155 ;; works well. At that point, we will consider integration with Custom. (Note
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
156 ;; that the hard part of the Behavior work is not actually behaviorizing the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
157 ;; packages, but developing the interface itself.)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
158 ;;
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
159 ;; As for integrating with Custom -- ideally that would mean simply extending
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
160 ;; defgroup, but that is not really possible given that backward-compatibility
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
161 ;; would not work -- existing versions of `defgroup' give an error when
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
162 ;; presented with an unknown keyword. In practice, then, this might mean that
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
163 ;; a separate `define-behavior' command (or `defpackage', or the like) will
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
164 ;; still exist.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
165
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
166 ;;; Code:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
167
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
168 ;; Hash table mapping behavior names to property lists, with entries for
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
169 ;; :group, :custom-group, :short-doc, :require, :enable, :disable,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
170 ;; and :commands.
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
171 (defconst behavior-hash-table (make-hash-table))
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
172 ;; Hash table mapping groups to property lists (entries for :group, :children,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
173 ;; :short-doc).
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
174 (defconst behavior-group-hash-table (make-hash-table))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
175 ;; Hash table with override information for groups.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
176 ;; :short-doc).
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
177 (defconst behavior-override-hash-table (make-hash-table))
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
178
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
179 (defvar within-behavior-enabling-disabling nil)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
180
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
181 (defgroup behaviors nil
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
182 "Behaviors -- high-level functionality interface.")
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
183
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
184 ;; List of enabled behaviors.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
185 (defcustom enabled-behavior-list nil
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
186 "List of currently enabled behaviors.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
187 Normally, don't set it directly; use `enable-behavior' or `disable-behavior'."
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
188 :initialize #'set-default
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
189 :set #'(lambda (sym val)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
190 (if within-behavior-enabling-disabling
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
191 (set sym val)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
192 (let* ((old-val enabled-behavior-list)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
193 (disable-list (set-difference old-val val))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
194 (enable-list (set-difference val old-val)))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
195 (dolist (b disable-list)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
196 (disable-behavior b t))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
197 (dolist (b enable-list)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
198 (enable-behavior b t))
897
7da79fbe37bb [xemacs-hg @ 2002-07-02 19:09:22 by stephent]
stephent
parents: 800
diff changeset
199 (assert (equal (sort (copy-sequence enabled-behavior-list) 'string-lessp)
7da79fbe37bb [xemacs-hg @ 2002-07-02 19:09:22 by stephent]
stephent
parents: 800
diff changeset
200 (sort (copy-sequence val) 'string-lessp))))))
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
201 :type '(repeat (symbol :tag "Behavior"))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
202 :group 'behaviors)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
203
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
204
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
205 (defvar behavior-history nil
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
206 "History of entered behaviors.")
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
207
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
208 (defun behavior-group-p (group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
209 "Non-nil if GROUP is the name of a valid behavior group."
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
210 (not (null (gethash group behavior-group-hash-table))))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
211
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
212 (defun check-behavior-group (group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
213 "Verify that GROUP is a valid behavior group, or nil.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
214 Return GROUP if so."
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
215 (or (behavior-group-p group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
216 (error 'invalid-argument "Invalid behavior group" group))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
217 group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
218
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
219 (defun* define-behavior (name doc-string &key
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
220 group custom-group
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
221 (short-doc
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
222 (capitalize-string-as-title
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
223 (replace-in-string (symbol-name name) "-" " ")))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
224 require enable disable commands
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
225 &allow-other-keys)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
226 ;; We allow other keys to allow for the possibility of extensions by
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
227 ;; later versions of XEmacs. Packages should be able to support those
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
228 ;; extensions without worrying about causing problems with older versions
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
229 ;; of XEmacs.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
230 "Define a behavior named NAME.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
231 DOC-STRING must be specified, a description of what the behavior does
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
232 when it's enabled and how to further control it (typically through
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
233 custom variables). Accepted keywords are
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
234
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
235 :group Symbol naming the behavior group this behavior is within.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
236 :custom-group Symbol naming the custom group containing the options that
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
237 can be set in association with this behavior. If not specified,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
238 the custom group with the same name as the behavior will be
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
239 used, if it exists.
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
240 :short-doc A \"pretty\" version of the name, for use in menus. If omitted
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
241 a prettified name will be generated.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
242 :require A single symbol or a list of such symbols, which need to be
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
243 present at enable time, or will be loaded using `require'.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
244 :enable A function of no variables, which turns the behavior on.
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
245 :disable A function of no variables, which turns the behavior off.
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
246 :commands A list of interactive commands that can be invoked in
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
247 conjunction with the behavior. These will appear in a submenu
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
248 along with the rest of the items for the behavior.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
249
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
250 Behaviors are assumed to be global, and to take effect immediately; if
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
251 the underlying package is per-buffer, it may have to scan all existing
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
252 buffers and frob them. When a behavior is disabled, it should completely
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
253 go away *everywhere*, as if it were never invoked at all.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
254
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
255 The :disable keyword can be missing, although this is considered bad
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
256 practice. In such a case, attempting to disable the behavior will signal
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
257 an error unless you use the `force' option.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
258
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
259 The :enable keyword can be missing. This is useful for behaviors that
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
260 are really a series of related commands without anything semantically
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
261 corresponding to \"turning on\" or \"turning off\" the behavior.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
262
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
263 A behavior with no :enable and no :command is possible. This might be
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
264 used, for example, by a behavior that encapsulates a series of related
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
265 Lisp functions. Such behaviors may be handled specially, e.g. not
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
266 displayed in the menus or displayed in a separate location, since they
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
267 have no user-invocable behavior."
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
268 (let ((entry (list :group (check-behavior-group group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
269 :custom-group custom-group
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
270 :short-doc short-doc :require require
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
271 :enable enable :disable disable
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
272 :commands commands)))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
273 (puthash name entry behavior-hash-table))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
274 ;; update the children list of the group we're in (maybe nil).
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
275 (unless (member name (getf (gethash group behavior-group-hash-table)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
276 :children))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
277 (push name (getf (gethash group behavior-group-hash-table) :children))))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
278
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
279 (defun* override-behavior (name &key
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
280 short-doc
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
281 group
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
282 include
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
283 demote-others)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
284 "Override the default properties of a behavior group NAME.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
285 Normally, groups are created and assigned properties by individual packages.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
286 The resulting hierarchy may not make much sense globally. This function
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
287 allows the hierarchy and appearance of a group to be specified globally,
5750
66d2f63df75f Correct some spelling and formatting in behavior.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5666
diff changeset
288 and will take precendence over the properties assigned by
66d2f63df75f Correct some spelling and formatting in behavior.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5666
diff changeset
289 `define-behavior-group'. This allows a global organization to be imposed on
66d2f63df75f Correct some spelling and formatting in behavior.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5666
diff changeset
290 groups, while still allowing for graceful handling of new or unknown groups.
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
291
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
292 NAME can be a symbol specifying a group name, or a list of
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
293 \(PARENT [...] NAME), where a path from a particular parent is explicitly
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
294 given. (This latter form allows the same name to be assigned to more than one
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
295 group.)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
296
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
297 Accepted keywords are
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
298
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
299 :short-doc A \"pretty\" version of the name, for use in menus.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
300 :group Parent group, if any. Should not be given if the parents are
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
301 explicitly specified in NAME.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
302 :include A list of behaviors that are specifically included in this
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
303 group, in addition to those that are included by the behaviors
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
304 themselves.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
305 :demote-others If non-nil, exclude all behaviors not specified in the :include
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
306 list and put them instead (i.e. \"demote\" them) to another group,
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
307 usually a subgroup."
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
308 (let ((entry (list :group (check-behavior-group group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
309 :short-doc short-doc
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
310 :include include
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
311 :demote-others demote-others)))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
312 (puthash name entry behavior-override-hash-table)))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
313
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
314 (defun* define-behavior-group (name &key
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
315 (short-doc
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
316 (capitalize-string-as-title
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
317 (replace-in-string (symbol-name name) "-"
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
318 " ")))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
319 group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
320 "Define a behavior group NAME.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
321
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
322 NAME can be a symbol specifying a group name, or a list of
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
323 \(PARENT [...] NAME), where a path from a particular parent is explicitly
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
324 given. (This latter form allows the same name to be assigned to more than one
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
325 group.)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
326
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
327 Accepted keywords are
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
328
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
329 :short-doc A \"pretty\" version of the name, for use in menus. If omitted
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
330 a prettified name will be generated.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
331 :group Parent group, if any. Should not be given if the parents are
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
332 explicitly specified in NAME."
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
333 (let ((entry (list :group (check-behavior-group group)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
334 :short-doc short-doc)))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
335 (puthash name entry behavior-group-hash-table))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
336 ;; update the children list of the parent (maybe nil).
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
337 (push name (getf (gethash group behavior-group-hash-table) :children)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
338
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
339 (defun read-behavior (prompt &optional must-match initial-contents history
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
340 default-value)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
341 "Return a behavior symbol from the minibuffer, prompting with string PROMPT.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
342 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
343 in the minibuffer before reading.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
344 Third arg HISTORY, if non-nil, specifies a history list. (It defaults to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
345 `behavior-history'.)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
346 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
347 for history command, and as the value to return if the user enters the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
348 empty string."
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
349 (let ((result
5666
daf5accfe973 Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
350 (completing-read prompt behavior-hash-table nil must-match
daf5accfe973 Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
351 initial-contents (or history 'behavior-history)
daf5accfe973 Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
352 default-value)))
daf5accfe973 Use #'test-completion, minibuf.el, instead of implementing same.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
353 (if (stringp result)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
354 (intern result)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
355 result)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
356
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
357 (defun behavior-enabled-p (behavior)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
358 "Non-nil if BEHAVIOR (a symbol) if currently enabled."
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
359 (memq behavior enabled-behavior-list))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
360
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
361 (defun enable-behavior (behavior &optional force)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
362 "Enable the specified behavior."
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
363 (interactive (list (read-behavior "Enable Behavior: " t) current-prefix-arg))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
364 (let ((plist (gethash behavior behavior-hash-table)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
365 (or plist (error 'invalid-argument "Not a behavior" behavior))
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
366 (or force (not (memq behavior enabled-behavior-list))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
367 (error 'invalid-change "Behavior already enabled" behavior))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
368 (let ((require (getf plist :require))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
369 (enable (getf plist :enable)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
370 (cond ((listp require)
5524
e05d98bf9644 Style and indentation corrections, behavior.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
371 (mapc 'require require))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
372 ((symbolp require)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
373 (require require))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
374 (t (error 'invalid-argument "Invalid :require spec" require)))
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
375 (message "Enabling behavior %s..." behavior)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
376 (if enable (funcall enable))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
377 (message "Enabling behavior %s...done" behavior)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
378 (let ((within-behavior-enabling-disabling t))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
379 (customize-set-variable 'enabled-behavior-list
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
380 (cons behavior enabled-behavior-list))))))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
381
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
382 (defun disable-behavior (behavior &optional force)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
383 "Disable the specified behavior."
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
384 (interactive (list (read-behavior "Disable Behavior: " t)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
385 current-prefix-arg))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
386 (let ((plist (gethash behavior behavior-hash-table)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
387 (or plist (error 'invalid-argument "Not a behavior" behavior))
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
388 (or force (memq behavior enabled-behavior-list)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
389 (error 'invalid-change "Behavior not enabled" behavior))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
390 (let ((require (getf plist :require))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
391 (disable (getf plist :disable)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
392 (cond ((listp require)
5524
e05d98bf9644 Style and indentation corrections, behavior.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5402
diff changeset
393 (mapc 'require require))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
394 ((symbolp require)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
395 (require require))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
396 (t (error 'invalid-argument "Invalid :require spec" require)))
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
397 (message "Disabling behavior %s..." behavior)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
398 (if disable (funcall disable))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
399 (message "Disabling behavior %s...done" behavior)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
400 (let ((within-behavior-enabling-disabling t))
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 502
diff changeset
401 (customize-set-variable 'enabled-behavior-list
5652
cc6f0266bc36 Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents: 5645
diff changeset
402 (delete* behavior enabled-behavior-list))))))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
403
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
404 (defun compute-behavior-group-children (group hash)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
405 "Compute the actual children for GROUP and its subgroups.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
406 This takes into account the override information specified."
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
407 (let* ((group-plist (gethash group behavior-group-hash-table))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
408 (override (gethash group behavior-override-hash-table))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
409 (children (getf group-plist :children)))
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
410 )
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
411 )
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
412
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
413 (defun behavior-menu-filter (menu)
5645
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
414 (labels
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
415 ((behavior-menu-filter-1 (menu group)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
416 (submenu-generate-accelerator-spec
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
417 (let* ((enable
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
418 (menu-split-long-menu
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
419 (menu-sort-menu
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
420 (let ((group-plist (gethash group
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
421 behavior-group-hash-table)))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
422 (loop for behavior in (getf group-plist :children)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
423 nconc (if (behavior-group-p behavior)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
424 (list
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
425 (cons (getf
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
426 (gethash behavior
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
427 behavior-group-hash-table)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
428 :short-doc)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
429 (behavior-menu-filter-1
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
430 menu behavior)))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
431 (let* ((plist (gethash behavior
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
432 behavior-hash-table))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
433 (commands (getf plist :commands)))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
434 (nconc
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
435 (if (getf plist :enable)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
436 `([,(format "%s (%s) [toggle]"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
437 (getf plist :short-doc)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
438 behavior)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
439 (if (memq ',behavior
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
440 enabled-behavior-list)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
441 (disable-behavior ',behavior)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
442 (enable-behavior ',behavior))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
443 :active ,(if (getf plist :disable)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
444 t
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
445 (not
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
446 (memq
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
447 ',behavior
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
448 enabled-behavior-list)))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
449 :style toggle
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
450 :selected (memq
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
451 ',behavior
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
452 enabled-behavior-list)]))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
453 (cond ((null commands) nil)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
454 ((and (eq (length commands) 1)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
455 (vectorp (elt commands 0)))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
456 (let ((comm (copy-sequence
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
457 (elt commands 0))))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
458 (setf (elt comm 0)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
459 (format "%s (%s)"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
460 (elt comm 0)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
461 behavior))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
462 (list comm)))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
463 (t (list
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
464 (cons (format "%s (%s) Commands"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
465 (getf plist
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
466 :short-doc)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
467 behavior)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
468 commands)))))))))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
469 ))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
470 )
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
471 )
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
472 enable)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
473 '(?p))))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
474 (append
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
475 `(("%_Package Utilities"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
476 ("%_Set Download Site"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
477 ("%_Official Releases"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
478 :filter ,#'(lambda (&rest junk)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
479 (menu-split-long-menu
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
480 (submenu-generate-accelerator-spec
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
481 (package-ui-download-menu)))))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
482 ("%_Pre-Releases"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
483 :filter ,#'(lambda (&rest junk)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
484 (menu-split-long-menu
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
485 (submenu-generate-accelerator-spec
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
486 (package-ui-pre-release-download-menu)))))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
487 ("%_Site Releases"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
488 :filter ,#'(lambda (&rest junk)
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
489 (menu-split-long-menu
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
490 (submenu-generate-accelerator-spec
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
491 (package-ui-site-release-download-menu))))))
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
492 "--:shadowEtchedIn"
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
493 ["%_Update Package Index" package-get-update-base]
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
494 ["%_List and Install" pui-list-packages]
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
495 ["U%_pdate Installed Packages" package-get-update-all]
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
496 ["%_Help" (Info-goto-node "(xemacs)Packages")])
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
497 "----")
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
498 (behavior-menu-filter-1 menu nil))))
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
499
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
500 ;; Initialize top-level group.
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
501 (puthash nil '(:children nil :short-doc "Root") behavior-group-hash-table)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1346
diff changeset
502
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
503 (provide 'behavior)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents:
diff changeset
504
5645
5d3bb1100832 Remove some utility functions from the global namespace, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents: 5524
diff changeset
505 ;;; behavior.el ends here