• Aucun résultat trouvé

ACTIVATING AND DEACTIVATING STYLES

Dans le document 0 () 0 0 (Page 128-135)

O active. commands

OPERATIONS ON STYLES

6.1 ACTIVATING AND DEACTIVATING STYLES

For the bindings in a style to be visible in an interactive session, that style must be "active" in the current buffer. Styles are activated in each buffer at the time the buffer is created; you can later. access and change the active styles in a buffer at any time.

A buffer can have zero or one major style and zero or more minor

Q

styles. There is no inherent difference in style objects that makes

OPERATIONS ON STYLES

them major or minor. The difference arises from the way a style is O activated in a buffer. The difference between major and minor activation becomes significant when the Editor searches for the proper binding of a key sequence, a pointer action, a variable, or an

0

attribute.

In searching for the proper binding for a context-dependent object, the Editor searches the currently active contexts in the following order:

• The current buffer

• The minor styles of the current buffer, if any, beginning with the most recently activated

• The major style, if any, of the current buffer

• The global Editor context

The Editor uses the first binding it encounters in this search for the object in question. If the object is bound in more than one of these contexts, then all but one of the bindings · are inaccessible, or

"shadowed". For instance, if you have "EDT Emulation" active as the major style and "VAX LISP" active as a minor style, the LINEFEED key will invoke "New LISP Line". The binding of that key in "EDT OEmulation" style ("EDT Delete Previous Word") is shadowed.

Further information on context search ·and shadowing can be found in Part II of this manual and in the VAX LISP/VMS Users Guide.

This search order suggests that, in general, your major style should be a general-purpose style that determines a wide range of Editor capabilities -- how the Editor manipulates text, moves the cursor, manages the display, reads in and writes to files, and so on. The two O DIGITAL-provided styles that are suitable for use as major styles are

"EDT Emulation" and "EMACS".

0

A minor style is typically a more limited set of bindings that you use to alter some details of the major style in particular circumstances.

"VAX LISP" style, for instance, enhances either "EDT Emulation" or

"EMACS" to enable you to edit LISP.code. The general-purpose style is activated as the major style so that it is the last style searched for bindings. The special-purpose style (added as a minor style) can add variations to the major style because it shadows the major style.

This section outlines the methods of activating styles in buffers:

• Activating styles in a newly created buffer

• Setting the Editor's default styles

• Accessing and altering_ the styles in an existing buffer

6.1.1 The Styles in a New Buffer

Most buffers are created automatically by the Editor whenever you

O

begin to edit a file or function. You can also make buffers yourself in LISP code. In either case, the new buffer can be created with specified style(s) active.

The function MAKE-BUFFER takes a buffer-name and returns a new buffer and T (or NIL if a buffer of that name already exists). The optional keywords :MAJOR-STYLE and :MINOR-STYLES let you specify the styles that are to be active in the new buffer.

The name argument can be a symbol or a list containing a symbol and' a string argument to the keyword :DISPLAY-NAME.

(This naming convention is the same for all named Editor objects; for further detail, see the discussion of naming Editor commands in Chapter 2.)

The :MAJOR-STYLE argument can be a style specifier or NIL .

• 'The :MINOR-STYLES argument can be a list of style specifiers or NIL.

For example:

(MAKE-BUFFER '(MYBUFFER :DISPLAY-NAME "Mybuffer.lsp") :MAJOR-STYLE "EDT Emulation"

:MINOR-STYLES '("VAX LISP"))

This form creates a buffer named MYBUFFER, with the alternative specifier "Mybuffer.lsp". Its major style is "EDT Emulation" and its one minor style is "VAX LIS~".

0

0

If you do not specify style arguments, the Editor supplies default values. If you want the buffer to have no minor styles (or no major

Q

dstyfle

1), you supply the argument NIL to the appropriate keyword. The _ e au ts, and the techniques of changing them, are presented in the

next section.

6.1.2 The Editor's Default Styles

The Editor supplies default values for the major and minor styles of a newly created buffer unless otherwise specified in the MAKE-BUFFER form. You can access and change these default values.

Note that changing a default value does not affect buffers that already exist. Only buffers that are created after the default has changed will have the new default styles active.

0

0

0

OPERATIONS ON STYLES

6.1.2.1 The Default Major Style - The Editor's default major style is stored as the value of the Editor variable "Default Major Style." In the Editor as provided, this value is "EDT Emulation."

You can use SETF to change the default major style:

(SETF (VARIABLE-VALUE "Default Major Style") "EMACS") Note that only the global value of this variable is used.

6.1.2.2 The Default Minor Style(s) - The Editor's default minor styles are stored as the value of the Editor variable "Default Minor Styles". The possible values are a list of style specifiers or NIL.

In the Editor as provided, this variable is used only globally, and its value is NIL.

You can establish a default minor style by resetting the value of

"Default Minor Styles". If, for instance, you want to retain "EDT Emulation" as the Editor's default major style but add "EMACS" as the default minor style, you could write:

(SETF (VARIABLE-VALUE "Default Minor Styles") '("EMACS"))

O

Note, however, that if you had previously established a default minor style, the form as written would remove that style as the default and replace it with "EMACS". To add "EMACS" without removing the previous default, you could use PUSH.

(PUSH "EMACS" (VARIABLE-VALUE-"Default Minor Styles"))

This form adds "EMACS" to the front of the list o·f default minor styles. The minor styles are activated in a buffer in reverse order

O

to their position in the list. That is, the first style in the list is the last activated and thus the first searched when the Editor conducts a context search. In this example, "EMACS" will shadow other minor styles (as well as the major style) that are active in the same buffer.

You can •ccess and change the entire minor style list if you want to change the order of the elements or add another style somewhere other than to the front of the list. For instance, suppose you have established "VAX LISP" as the default minor style and you now want to add "EMACS". If you added "EMACS" with PUSH, it would shadow "VAX LISP". To have "VAX LISP" shadow "EMACS", you would write:

(SETF (VARIABLE-VALUE "Default Minor Styles") ' ( "VAX LISP" "EMACS"))

Q

This form makes "VAX LISP" the last-activated (and therefore the first-searched) of the minor styles in any buffer that has the default minor s.tyles.

6.1.2.3 Default Minor Style(s) By Type Of Buffer - If a minor style

is a special-purpose style, you may want to have it active only in the

o

buffers where the special capabilities are needed. For instance, "VAX LISP" style is activated automatically in buffers that are associated with LISP objects or with files of the filetype LSP.

If you want to activate a minor style in buffers associated with a LISP object, you reset the value of the Editor variable "Default LISP Object Minor Styles". The value is a list of style specifiers, such as:

(SETF (VARIABLE-VALUE "Default LISP Object Minor Styles") '("My New Style" "VAX LISP"))

This form specifies that 1:wo minor styles, "My New ·style" and "VAX LISP", are to be activated in any buffer that is associated with a

LISP object. These styles will be searched in the order shown; they

Q

will be searched before any styles in the "Default Minor Styles" list.

If you want to activate a minor style in buffers associated with a specified type of file, you reset the value of the Editor ,variable

"Default Filetype Minor Styles". The value is an association list of the form:

((FILETYPE-STRING. MINOR-STYLE-LIST) •.. ) For instance, the initial value of this variable is:

( "LSP" • "VAX LISP")

Again, minor styles specified by this variable are activated after any styles specified by "Default Minor Styles", and are therefore searched first.

6.1.'2.4 Example Of Activating Default Styles - This section illustrates the activation of multiple default styl~s in several buffers. The search order, which is the reverse of the order of activation, is then shown for each buffer.

Suppose you have five styles to work with: "EDT Emulation", "EMACS",

"VAX LISP", and two user-defined styles, "LISP Variation" and

"FORTRAN". One way to set your default activation values is as follows:

0

0.

0

0

0

OPERATIONS ON STYLES

(SETF (VARIABLE-VALUE "Default Major Style") "EDT Emulation") (SETF (VARIABLE-VALUE "Default Minor Styles") '("EMACS")) (SETF (VARIABLE-VALUE "Default LISP Object Minor Styles")

'("VAX LISP"))

(SETF (VARIABLE-VALUE "Default Filetype Minor Styles")

, ( ( 11LSP11 ( "LISP Variation" "VAX LISP"))

( "FOR" . "FORTRAN")))

In buffers that have the default styles, the search order is as follows:

In a buffer named "Myfile.txt":

1. "EMACS"

2. "EDT Emulation"

In a buffer named LISP-FUNCTION:

1. "VAX LISP"

2. "EMACS"

3. "EDT Emulation"

Q

In a buffer named "Myfile.lsp":

0

0

1. "LISP Variation"

2. "VAX LISP"

3. "EMACS"

4. "EDT Emulation"

In a buffer named "Myfile.for":

1. "FORTRAN"

2. "EMACS"

3. "EDT Emulation"

6.1.3 The Styles in an Existing Buffer

You can access and change the styles in a specified buffer at any time.

Note that changing the active style(s) in one buffer has no effect on any other buffer.

6.1.3.1 A Buffer's Major Style - The function BUFFER-MAJOR-STYLE takes a buffer specifier and returns the major style of that buffe(J

(or NIL if the buffer has no major style). You can use SETF with this function to change the major style active in a buffer:

(SETF (BUFFER-MAJOR-STYLE "Mybuffer.txt") "EMACS")

This form deactivates the major .style, if any, of "Mybuffer. txt" and activates "EMACS" instead.

6.1.3.2 A Buffer's Minor Style(s) - You can also access and alter the minor style or styles active in a specified buffer.

To determine whether a specified buffer has minor styles active, you can use the function BUFFER-MINOR-STYLE-LIST. This function takes a ~ buffer object and returns a list of the minor styles active in that~

buffer:

(BUFFER-MINOR-STYLE-LIST (FIND-BUFFER "Mybuffer.txt"))

BUFFER-MINOR-STYLE-LIST is an accessing function only. Because it is not a place form acceptable to SETF, you cannot use it to alter the list of minor styles active in a buffer.

To alter the list, you use the function BUFFER-MINOR-STYLE-ACTIVE() This function takes a buffer specifier and a style specifier. It

returns T if the specified style is active as a minor style in the specified buffer; otherwise NIL. This function can be used with SETF to add or remove a style from the minor style list of the buffer.

For instance, to activate "VAX LISP" as a minor. s~yle in the current buffer, you could write:

(SETF (BUFFER-MINOR-STYLE-ACTIVE (.CURRENT-BUFFER) "VAX LISP") T)

0

This form adds "VAX LISP" to the front of the minor style list for the current buffer. "VAX LISP" will then shadow all other active styles.

This form is the essential action of the DIGITAL-provided command

"Activate Minor Style", which prompts for a style name and activates that style as a minor style in the current buffer.

To deactivate "VAX LISP" you would end the above SETF form with NIL:

(SETF (BUFFER-MINOR-STYLE-ACTIVE (CURRENT-BUFFER) "VAX LISP") NIL)

This form is the essential action of

"Deactivate Minor Style".

the DIGITAL-provided command

0

0

0

0

0

0

OPERATIONS ON STYLES

If you activate a minor style that is already active in the buffer, the style moves to the front of the minor style action actually deactivates and then reactivates the style, the most recently activated (and thus the first-searched).

Dans le document 0 () 0 0 (Page 128-135)