common/log.c: minor whitespace change
[nvi.git] / perl_api / VI.pod
blobf73a93656b1a2539026961be6a052359e5b7a946
1 =head1 NAME
3 VI - VI module within perl embedded nvi
5 =head1 SYNOPSIS
7     sub wc {
8       my $words;
9       $i = $VI::StartLine;
10       while ($i <= $VI::StopLine) {
11         $_ = $curscr->GetLine($i++);
12         $words+=split;
13       }
14       $curscr->Msg("$words words");
15     }
17 =head1 DESCRIPTION
19 This pseudo module is available to perl programs run from within nvi and
20 provides access to the files being edited and some internal data.
22 Beware that you should not use this module from within a C<perldo> or
23 from within an C<END> block or a C<DESTROY> method.
25 =head2 Variables
27 These are set by nvi before starting each perl command.
29 =over 8
31 =item * $curscr
33 Object that represents the current screen.
34 It can be used as the ScreenId parameter of the functions below,
35 or you can use object oriented syntax.
37         # the following two are equivalent
38         $curscr->DelLine(57);
39         VI::DelLine($curscr, 57);
41 =item * $StartLine
43 Line number of the first line of the selected range or of the file if no
44 range was specified.
46 =item * $StopLine
48 Line number of the last line of the selected range or of the file if no
49 range was specified.
51 =back
53 =head2 Functions
55 =over 8
57 =item * AppendLine
59     VI::AppendLine(screenId,lineNumber,text);
61 Append the string text after the line in lineNumber.
63 =item * DelLine
65     VI::DelLine(screenId,lineNum);
67 Delete lineNum.
69 =item * EndScreen
71 VI::EndScreen(screenId);
73 End a screen.
75 =item * FindScreen
77     VI::FindScreen(file);
79 Return the screen id associated with file name.
81 =item * GetCursor
83     ($line, $column) = VI::GetCursor(screenId);
85 Return the current cursor position as a list with two elements.
87 =item * GetLine
89     VI::GetLine(screenId,lineNumber);
91 Return lineNumber.
93 =item * GetMark
95     ($line, $column) = VI::GetMark(screenId,mark);
97 Return the mark's cursor position as a list with two elements.
99 =item * GetOpt
101     VI::GetOpt(screenId,option);
103 Return the value of an option.
105 =item * InsertLine
107     VI::InsertLine(screenId,lineNumber,text);
109 Insert the string text before the line in lineNumber.
111 =item * LastLine
113     VI::LastLine(screenId);
115 Return the last line in the screen.
117 =item * MapKey
119     VI::MapKey(screenId,key,perlproc);
121 Associate a key with a perl procedure.
123 =item * Msg
125     VI::Msg(screenId,text);
127 Set the message line to text.
129 =item * NewScreen
131     VI::NewScreen(screenId);
132     VI::NewScreen(screenId,file);
134 Create a new screen.  If a filename is specified then the screen is
135 opened with that file.
137 =item * Run
139     VI::Run(screenId,cmd);
141 Run the ex command cmd.
143 =item * SetCursor
145     VI::SetCursor(screenId,line,column);
147 Set the cursor to the line and column numbers supplied.
149 =item * SetLine
151     VI::SetLine(screenId,lineNumber,text);
153 Set lineNumber to the text supplied.
155 =item * SetMark
157     VI::SetMark(screenId,mark,line,column);
159 Set the mark to the line and column numbers supplied.
161 =item * SetOpt
163     VI::SetOpt(screenId,command);
165 Set an option.
167 =item * SwitchScreen
169     VI::SwitchScreen(screenId,screenId);
171 Change the current focus to screen.
173 =item * TagQ
175     $screen->TagQ("tag identification string")
177 Creates a new tag queue object associated to $screen
178 to which "tags" can be added.
179 See further about methods you can use on tag queues.
181 =item * UnmapKey
183     VI::UnmmapKey(screenId,key);
185 Unmap a key.
187 =item * Warn
189 This is the default warning handler.
190 It adds any warnings to the error string.
192 =item * Opt
194     $screen->Opt;
196 Returns a tied hash representing the options of the screen.
197 Note that you can only retrieve and set hash elements.
199 =item * Map
201     $screen->Map;
203 Returns a tied hash representing the mappings of the screen.
204 Note that you can only retrieve, set and delete hash elements.
206 =item * Mark
208     $screen->Mark;
210 Returns a tied hash representing the marks of the screen.
212 =item * Line
214     $screen->Line;
216 Returns a tied array representing the lines of the screen.
218 =back
220 =head2 Tag queue methods
222 =item * Add
224     $tagq->Add($filename, $searchstring, $msg)
226 Adds a tag to the tag queue. 
227 The $searchstring argument is (line)number or
228 a string representing a regular expression.
230 =item * Push
232     $tagq->Push()
234 Pushes the tag queue onto its associated screen.
235 The result of the operation is as if the user had enter the
236 tag command and nvi had found the locations that were added
237 using the Add method.
239 For an example, see the make.pl script.
241 =back
243 =head1 EXAMPLES
245     sub showmarks {
246       my ($mark, $all);
247       for $mark ('a' .. 'z') {
248         eval {VI::GetMark($VI::ScreenId, $mark)};
249         $all .= $mark unless ($@);
250       }
251       VI::Msg($VI::ScreenId,"Set marks: $all");
252     }
254     sub forall {
255       my ($code) = shift;
256       my ($i) = $VI::StartLine-1;
257       while (++$i <= $VI::StopLine) {
258         $_ = VI::GetLine($VI::ScreenId, $i);
259         VI::SetLine($VI::ScreenId, $i, $_) if(&$code);
260       }
261     }
263 Now you can do
265     :perl forall sub{s/perlre/substitution/}
267 Although you'll probably use
269     :perldo s/perlre/substitution/
271 instead.
273 See L<perlre> for perl regular expressions.
275 =head1 SEE ALSO
277 L<nviperl>
279 =head1 AUTHOR
281 Sven Verdoolaege <skimo@kotnet.org>