[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.2 Minor Mode Scopes

Minor modes can be scoped to different objects in a rather arbitrary manner. These scopes are defined by the macro DEFINE-MINOR-MODE-SCOPE. Because minor modes are implemented as mixins, the object returned by a scopes current object function must be a class instance.

Macro: define-minor-mode-scope (designator class &optional filter-type) &body retrieve-current-object

Define a minor mode scope for use with DEFINE-MINOR-MODE. This generates a call to ADD-MINOR-MODE-SCOPE which is evaluated when compiled, loaded, or executed. DESIGNATOR should be a keyword and TYPE should denote a class, while FILTER-TYPE should denote a general type. RETRIEVE-CURRENT-OBJECT should be a thunk body which returns the current object for this scope.

Macro: define-descended-minor-mode-scope designator parent &key class filter-type retrieve-current-object

Define a descended scope which inherits the parents type and functions unless provided.

Function: add-minor-mode-scope designator type current-object-thunk &optional filter-type

Add a list of the TYPE, CURRENT-OBJECT-THUNK, and ALL-OBJECTS-THUNK, under DESIGNATOR in the minor mode scope hash table.

When a minor mode is defined its scope is looked up and validated by the function VALIDATE-SCOPE. This function takes a scope and a list of superclasses, and ensures that the scope can descend from the superclasses scopes. This restricts the valid scopes to ensure that a minor mode scoped to :GROUP cant be a subclass of a minor mode scoped to :WINDOW, for example. However there is a way to override this by explicitly stating that two otherwise incompatible scopes are compatible. This is done by defining methods for the generic function VALIDATE-SUPERSCOPE which dispatch upon the scope designators. Such methods should return at least one value, indicating if the superscope is a valid parent of the scope. If multiple values are returned, the second value must indicate whether the superscope is an invalid parent of the scope. For example:

(defmethod stumpwm:validate-superscope ((c (eql :id1)) (p (eql :id2)))
  "Explicitly allow id1 to descend from id2"
  (values t nil))

(defmethod stumpwm:validate-superscope ((c (eql :id3)) (p (eql :id4)))
  "Explicitly prevent id3 from descending from id4"
  (values nil t))

When defining and using scopes the type specifier is important; it is used to determine what minor modes should be mixed into an object when it is created. For this reason it is important when defining a minor mode or minor mode scope to understand the type hierarchy. It may also be in the programmers best interests to define an accompanying type.

The following scopes are predefined:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on January 28, 2024 using texi2html 1.82.