home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
vile-src.zip
/
vile-8.1
/
doc
/
modes.doc
< prev
next >
Wrap
Text File
|
1998-05-13
|
7KB
|
234 lines
Major (and minor) modes in Vile
===============================
Goals
-----
This document describes the proposed implementation and use of major
modes in vile. My goal is to extend the notion of the C mode (cmode)
to allow runtime definable major modes.
The C mode is a collection of modes that are useful for editing C
program source:
c-suffixes
c-tabstop
c-shiftwidth
as well as builtin functionality:
autoindention of C statements taking into account curly braces
fence matching for /*...*/ comments and C preprocessor statements
comment formatting
Both the modes and functionality are extensions of other features in
vile. It would be useful to combine modes to support other languages
in a similar fashion. Likewise, the autoindention, etc., could be
parameterized and made reusable to support other languages. For an
initial implementation, I am focusing on the combining of modes,
providing a structure for the parameterization.
One thing that is not clear to many users (and possibly should be
changed) is the manner in which the C mode is attached to a buffer.
It is currently set as a boolean - if active before a buffer is
loaded, then vile checks the file suffix to see if it matches the
c-suffixes mode, and if so, sets the C mode for the buffer. C mode
can be explicitly set by a ":setl cmode", and unset by ":setl
nocmode". In the new scheme,
+ vile will search the list of all active majormodes, first
testing if any match with the majormode's suffixes, then if
any preamble (first line regular expression) matches.
The search is in alphabetic order, by majormode name. The
first match each, of suffixes and preamble terminate the
search, but a match of preamble overrides a match of suffixes.
+ majormodes can be disabled (e.g., ":set nocmode"), as before.
However, there is no global sense of majormode; unsetting a
buffer's local value of a majormode simply makes it not have a
majormode associated with it.
Commands
--------
These are the commands which I think are necessary:
define-majormode {majormode}
define-submode {majormode} {minormode}[={value}]
remove-majormode {majormode}
remove-submode {majormode} {minormode}
The {majormode} is a new symbol.
The {minormode} can be any one of the existing buffer modes, except for
a {majormode}.
Example
-------
define-majormode c
; Declares a mode 'c', and corresponding symbol 'cmode'
define-submode c suffixes=\\.\\(\\([Cchisyl]\\)\\|CC\\|cc|cpp\\|cxx\\|hxx\\|scm\\)$
; Specifies the filename suffixes which control whether a newly-loaded
; buffer is set to 'c' mode.
define-submode c tabstops=4
define-submode c shiftwidth=4
; Defines the 'c' tabstops and shiftwidth. If no "define-submode"
; command is given, no separate symbol is defined.
As an example, to define a new major mode for perl programming, you might
include the following in your .vilerc file:
define-majormode perl
define-submode perl preamble "^#.*perl\\>"
define-submode perl suffixes "\\.pl$"
define-submode perl shiftwidth 4
The "define-majormode" command
------------------------------
This takes a single argument, a majormode name. To follow existing
convention, the string "mode" is automatically appended to the given
name. Associated modes are defined or modified with the define-submode
command. Vile maintains a list of majormodes. Only one majormode can
be associated with a buffer (none need be associated). After
definition, a majormode can be set or unset just like any other buffer
mode:
define-majormode c
; defines "cmode"
set cmode
; sets the default mode for new buffers
setl cmode
; sets the mode for the current buffer
setl nocmode
; clear c mode (existing implementation)
unsetl cmode
; clear c mode (not currently implemented)
The restriction to a single majormode is because mode values are
internally represented as structures with a pointer. The pointer
denotes which value (currently local or global) is used. The
majormode implementation adds a level to this, e.g.,
value -> self (local)
value -> global (global)
value -> major (majormode)
When a majormode is defined, an array of the existing minor mode values
is allocated, all pointing to the global modes. The define-submode
command modifies these to make them local pointers. When a buffer is
associated with a majormode, all of its buffer mode values are pointed
to the majormode's values. (To keep the bookkeeping straight, modifying
a global buffer mode must also modify the copies of non-local buffer
mode values).
The "define-submode" command
----------------------------
This command sets local values of buffer modes for the given majormode,
e.g.,
define-submode c autoindent
The majormode name is required. Any number of modes can be modified
in a single command.
The following are keywords that aren't minor modes, but are recognized
solely by the define-submode command:
suffixes
The filename suffix which is tested to trigger
association with a majormode (e.g., c-suffixes)
Note that since the default value for the c-suffixes mode
is a regular expression that will match some other file
types (C++ files, for instance), if you define a new major
mode for one of those suffixes you may want to reset
c-suffixes to something less inclusive.
preamble
Regular expression, matched against the beginning of a
file (the first line) used to trigger association with
a majormode (e.g., "^!#.*\/perl[^a-z]").
fences
"fence-" followed by any of the following keywords with a
regular expression: if, elif, else, fi,
comments
To support C-style comments, with the '%' going between
"/* and "*/", use "fence-" followed any of the following
keywords with a regular expression: begin, end.
indent
The keyword "cstyle", or any of the following keywords
with a regular expression: begin, end, if, then, else,
elif, endif.
Other features which should be controlled by majormodes include limiting
the scope of the entab and detab commands.
The "remove-majormode" command"
-------------------------------
This command has two forms:
remove-majormode {majormode}
This removes the definition of the majormode. Buffers
that were associated with the mode revert to no
majormode.
or
remove-majormode {majormode} {name}
This removes the value of {name} from {majormode},
leaving it set to the global value, if any.
The "remove-submode" command"
-----------------------------
Remove the special association of a submode from a majormode.
Example
-------
The builtin C/C++ majormode description is equivalent to
define-mode c
set csuf "\\.\\(\\([Cchisyl]\\)\\|CC\\|cc|cpp\\|cxx\\|hxx\\|scm\\)$"
set c-comment-prefix="^\\s*\\(\\s*[#*>]\\)\\+"
set c-comments="^\\s*/\\?\\(\\s*[#*>]\\)\\+/\\?\\s*$"
set c-fence-begin="/\\*"
set c-fence-end="\\*/"
set c-fence-if="^\\s*#\\s*if"
set c-fence-elif="^\\s*#\\s*elif\\>"
set c-fence-else="^\\s*#\\s*else\\>"
set c-fence-fi="^\\s*#\\s*endif\\>"
Note that the following are equivalent once you have defined the majormode "c":
set cts=8
set c-tabstop=8
define-submode c tabstop=8
-------------------------------
$Header: /usr/build/vile/vile/doc/RCS/modes.doc,v 1.1 1998/05/13 10:20:30 tom Exp $
-------------------------------