📄 scripts.gml
字号:
.****************************************************************************
.*
.* Open Watcom Project
.*
.* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
.*
.* ========================================================================
.*
.* This file contains Original Code and/or Modifications of Original
.* Code as defined in and that are subject to the Sybase Open Watcom
.* Public License version 1.0 (the 'License'). You may not use this file
.* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
.* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
.* provided with the Original Code and Modifications, and is also
.* available at www.sybase.com/developer/opensource.
.*
.* The Original Code and all software distributed under the License are
.* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
.* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
.* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
.* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
.* NON-INFRINGEMENT. Please see the License for the specific language
.* governing rights and limitations under the License.
.*
.* ========================================================================
.*
.* Description: Root file of VI documentation.
.*
.* Date By Reason
.* ---- -- ------
.* 06-aug-92 Craig Eisler initial draft
.* 02-oct-05 L. Haynes reformatted for hlp, figures
.*
.****************************************************************************/
.chap *refid=scripts 'Editor Script Language'
:cmt. .if &e'&dohelp eq 0 .do begin
:cmt. . .section 'Introduction'
:cmt. .do end
.*
The &edname supports a powerful command language. In a script,
you may use any &cmdline command, along with a number of special commands
explicitly for the script environment.
.np
White space is ignored in a script file, unless a line starts with a
right angle bracket ('>.'). Comments may be imbedded in a script file
by starting the line with pound sign ('#').
.np
A script is invoked using the &cmdline command
.keyref source
:period.
Examples are:
.millust begin
source test2.vi
.millust end
.millust begin
source test.vi parm1 parm2 parm3 parm4
.millust end
.np
A script may be invoked with a set of optional parameters.
These optional parameters are accessed in the script by using
.var %n
:period.
Every occurrence of
.var %n
in the script is replaced by the corresponding parameter.
To access parameter above 9, brackets must surround the number. This
is because:
.millust begin
%10
.millust end
.np
cannot be distinguished from the variable
.var %1
followed by a 0, and
the variable
.var %10
:period.
To remove the ambiguity, brackets are used:
.millust begin
%(10)
.millust end
.np
All parameters can be accessed by using
.var %*
:period.
.np
To allow multiple words
in a single parameter, delimit the sequence by forward slashes ('/') or
double quotes ('"'). For example, the line
.millust begin
source test.vi "a b c" d e
.millust end
.np
would cause the script test.vi to have the following variables defined:
.millust begin
%* = a b c d e
%1 = a b c
%2 = d
%3 = e
.millust end
.np
General variables, both local and global, are also supported in the
editor script language. Any line in a script
that is not one of the script commands
has all the variables on it expanded before the line is processed.
Script commands can manipulate the variables. For more information, see
the section
:HDREF refid='scrvars'.
.if &e'&dohelp eq 0 .do begin
of this chapter.
.do end
.np
There are several useful &cmdline
commands dealing with &edvi scripts, they are:
.*
:DL break.
.*
:DT.compile
:DD.Used to compile a script.
This allows much faster execution of the script
by &edvi.
:period.
:DT.load
:DD.Used to make a script resident in &edvi.
:period.
This allows much faster invocation of the script,
since &edvi does not have to search for it or parse it.
.*
:eDL.
.*
.np
If a system command is spawned from a script (using the exclamation point ('!')
command), then &edvi does not
pause after the system command is finished running. However, if
you set
.keyref pauseonspawnerr 1
:cont.,
then &edvi will pause after a system command is executed from a script
if the system command returned an error.
.*
.* ******************************************************************
.section *refid=scrvars 'Script Variables'
.* ******************************************************************
.*
.np
General variables are supported in a &edvi script.
Variables are preceded by a percent symbol ('%').
Variables with more than one letter must be enclosed by brackets, for
example:
.millust begin
%a - references variable named a.
%(abc) - references variable named abc.
.millust end
.np
The brackets are required to disambiguate single letter variables followed
by text from multiple letter variables.
.np
Both local and global variables are supported. They are distinguished
by the case of the first letter: local variables must begin with
a lower case letter, and global variables begin with an upper case
variable. Example variables:
.millust begin
%A - global variable named A.
%a - local variable named a.
%(AbC) - global variable named AbC.
%(abC) - local variable named abC.
.millust end
.np
Global variables are valid for the life of the editing
session.
.np
Local variables are only valid for the life of the script that they
are used in.
.*
.beglevel
.*
.* ******************************************************************
.section 'Pre-defined Global Variables'
.* ******************************************************************
.*
.np
There are a number of global variables that take on values as the
editor runs, they are:
.*
:DL break.
.*
:DT.%C
:DD.Contains the current column number in the current edit buffer.
:DT.%D
:DD.Drive of current file, based on the actual path.
:DT.%(D1)
:DD.Drive of current file, as typed by the user. This could have no value.
:DT.%E
:DD.File name extension of current file.
:DT.%F
:DD.Current file name (including name and extension).
:DT.%H
:DD.Home directory of a file. This is the directory where the edit command
was issued.
:DT.%N
:DD.Name of the current file, extension removed.
:DT.%M
:DD.Modified status of the current file - set to 1 if the file
has been modified, and a 0 otherwise.
:DT.%(OS)
:DD.What operating system the editor is hosted on. Possible values are:
:UL compact.
:LI.dos (protect and real mode).
:LI.unix (QNX, Linux or other Unix-based systems)
:LI.os2
:LI.os2v2
:LI.nt
:eUL.
:DT.%(OS386)
:DD.This variable is set to 1 is the host operating system is 386
(or higher) based. The possible 386 environments are:
:UL compact.
:LI.dos (protect mode).
:LI.os2v2
:LI.nt
:LI.unix (when running on a 386)
:eUL.
:DT.%P
:DD.Path of current file (no extension, name, or drive) based on the actual
full path to the file.
:DT.%(P1)
:DD.Path of current file (no extension, name, or drive) based on the name
typed by the user. This could have no value.
:DT.%R
:DD.Contains the current row (line number) in the current edit buffer.
:DT.%(SH)
:DD.Height of entire screen in characters.
:DT.%(SW)
:DD.Width of entire screen in characters.
:DT.%(Sysrc)
:DD.Return code from last system command.
.*
:eDL.
.*
.endlevel
.*
.* ******************************************************************
.section 'Hook Scripts'
.* ******************************************************************
.*
.np
&edvi has several hook points where a script,
if defined by the user, is invoked. This allows you to
intercept the editor at key points
to change its behaviour. A script
that is invoked at a hook point
is referred to as a
.keyword hook script
:period.
.np
Each hook script
is identified by a particular global variable. Whenever &edvi
reaches a hook point, it checks if the global variable is defined,
and if it is, the global variables contents are treated like a script
name, and that script is invoked.
.np
The hook points are:
:UL.
:LI.after a new file has been read.
:LI.before a modified file is saved and exited.
:LI.after return is pressed on the &cmdline
:period.
:LI.whenever an unmodified file is modified.
:LI.whenever a selected (highlighted) column range is
chosen (via mouse click or keyboard).
:LI.whenever a selected (highlighted) line range
is chosen (via mouse click or keyboard).
:eUL.
.*
:DL break.
.*
:DT.Read Hook
:DD.The hook script
is called just after a new file has been read into the editor.
.np
The script invoked is the file specified by the global variable
.var %(Rdhook)
:period.
:DT.Write Hook
:DD.The hook script
is called just before a modified file
is to be saved and exited.
.np
The script invoked is the file specified by the global variable
.var %(Wrhook).
:DT.Command Hook
:DD.The hook script
is called after the return is pressed from the &cmdline
:period.
The global variable
.var %(Com)
contains the current command string, and may be modified.
Whatever it is modified to is what will be processed by the &cmdline
processor.
.np
The script invoked is the file specified by the global variable
.var %(Cmdhook)
:period.
:DT.Modified Hook
:DD.The hook script
is called whenever
a command is about to modify an unmodified file. If the file is
modified, the hook is not called.
.np
The script invoked is the file specified by the global variable
.var %(Modhook)
:period.
:DT.Mouse Columns Sel Hook
:DD.The hook script
is called whenever a selected column range
has been picked. Picking a selected region is done by
right-clicking the region with the mouse, or by double clicking
the region with the mouse, or by using the underscore ('_') &cmdmode
keystroke.
.np
The script is invoked with the following parameters:
:DL break.
:DT.%1
:DD.The selected string.
:DT.%2
:DD.Line on screen of selected string.
:DT.%3
:DD.Column on screen of start of selected string.
:DT.%4
:DD.Column on screen of end of selected string.
:eDL.
The script invoked is the file is specified by the global variable
.var %(MCselhook)
:period.
:DT.Mouse Lines Sel Hook
:DD.The hook script
is called whenever a selected line range
has been picked. Picking a selected region is done by
right-clicking the region with the mouse, or by double clicking
the region with the mouse, or by using the underscore ('_')
&cmdmode keystroke.
:DL break.
:DT.%1
:DD.Line on screen where selection request occurred.
:DT.%2
:DD.Column on screen where selection request occurred.
:DT.%3
:DD.First line of selected region.
:DT.%4
:DD.Last line of selected region.
:eDL.
The script invoked is the file specified by the global
variable
.var %(MLselhook)
:period.
.*
:eDL.
.*
.* ******************************************************************
.section *refid='screxpr' 'Script Expressions'
.* ******************************************************************
.*
.np
&edvi allows the use of constant expressions in its script
language. Long integers and strings may be used in an expression.
Some sample expressions are:
.millust begin
5*3+12
(7*7)+10*((3+5)*8+9)
5 >.= %(var)
("%(str)" == "foo") || ("%(str)" == "bar")
(5+%i*3 == 15)
rdonly == 1
.millust end
.np
An expression is composed of operators and tokens. Operators act
on the tokens to give a final result.
.np
A token in an expression may be a special keyword, a boolean setting
value, an integer, or
a string.
.np
A string is indicated by surrounding the string with double quotes (").
A token is an integer if it starts with a numeric
digit (0 to 9).
.np
If a token starts with a dot ('.'), then the remainder of the token
is assumed to be a setting token. This token evaluates to be
1 or 0 for a boolean setting, or to the actual value of the setting
for all others.
.millust begin
.autoindent - 1 if autoindent is true, 0 otherwise
.ai - 1 if autoindent is true, 0 otherwise
.autosave - current value of autosave
.tmpdir - current tmpdir string
.millust end
.np
If a token is not surrounded by double quotes, and is not a keyword and
is not an integer, then that token is assumed to be a string.
.np
If an expression contains conditional operators, then the result of the
expression is a boolean value (1 or 0). The following script language
control flow commands expect boolean results:
:UL compact.
:LI.:cont.
.keyref if
:LI.:cont.
.keyref elseif
:LI.:cont.
.keyref quif
:LI.:cont.
.keyref while
:LI.:cont.
.keyref until
:eUL.
.np
The following are conditional operators in an expression:
:UL compact.
:LI.:cont.
.keyword ==
(equal to)
:LI.:cont.
.keyword !=
(not equal to)
:LI.:cont.
.keyword >.
(greater than)
:LI.:cont.
.keyword >.=
(greater than or equal to)
:LI.:cont.
.keyword <.
(less than)
:LI.:cont.
.keyword <.=
(less than or equal to)
:LI.:cont.
.keyword &&
(boolean AND)
:LI.:cont.
.keyword ||
(boolean OR)
:eUL.
.np
An expression may also operate on its token using various mathematical
operators, these operators are
:UL compact.
:LI.:cont.
.keyword +
(plus)
:LI.:cont.
.keyword -
(minus)
:LI.:cont.
.keyword *
(multiply)
:LI.:cont.
.keyword /
(divide)
:LI.:cont.
.keyword **
(exponentiation)
:LI.:cont.
.keyword &caret.
(bitwise NOT)
:LI.:cont.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -