[Terry said:]
> I'm having problems in writing what should be a simple procedure to tailor
> ved. I feel pretty silly because I'm sure it's simple, but... where is the
> information telling you how to tailor ved in any detail? (can it even be done?
> what am I missing?)
Yes, VED can be tailored quite extensively (perhaps too much :-) There
are no real tutorials, but you will find much of the information you
need in REF * VEDPROCS, * VEDCOMMS (especially the last couple of
sections), and * VEDVARS.
For XVed read REF * XVED.
[...]
> That is, I want to be able to define a procedure, say ved_i, so that I
> can do
>
> ENTER i(string) (or is it 'i/string'?)
>
> whereupon it searches for the string and replaces it with string/index{string}
>
> I thought it would be something simple, like:
>
> define ved_i(string);
> vars vedargument;
> '/string/@&\\index{@&}' -> vedargument;
> ved_s();
> enddefine;
>
nearly :-)
Let's look at the string you create
'/string/@&\\index{@&}' =>
** '/string/@&\index{@&}'
Note there is only 1 "\" before the "index", the search-and-replace
command with need two. You need to escape the "\" character twice, once
when you create the string, and once for the argument processing of VED.
So we write it like this:
'/string/@&\\\\index{@&}' =>
** '/string/@&\\index{@&}'
The second problem is that we want the contents of the variable -string-
in -vedargument-, not the string 'string'. To do this we use -sys_><-
like this:
vars string='Fred';
'/' sys_>< string sys_>< '/@&\\\\index{@&}' =>
** '/Fred/@&\\index{@&}'
The final problem is that the -ved_<whatever>- procedures do not take an
explicit argument. The text after an "<ENTER> foo" command is placed in
the string -vedargument- before the -ved_foo- procedure is called, so
-ved_i- should be written as follows:
define ved_i;
vars vedargument;
'/' sys_>< vedargument sys_>< '/@&\\\\index{@&}'
-> vedargument;
ved_s();
enddefine;
As an alternative you could use the -veddo- procedure which takes a
string as an argument and treats it just like an <ENTER> command. So
-ved_i- could be re-written as:
define ved_i;
veddo('s/' sys_>< vedargument sys_>< '/@&\\\\index{@&}');
enddefine;
> It would also be nice to get Xved to replace a highlighted (in black)
> string S with 'S\index{S}' at the click of a button.
To do this we will need to use
-vvedclipboard-
An active variable which will be -false-, or the current primary
or clipboard selection.
-vedselection_cut-
A procedure which cuts the selection from the buffer.
With these we can define a mouse handler (see REF * XVED) as follows:
define vedmouse__index_selection();
lvars string;
if vvedclipboard ->> string then
;;; REMOVE THE SELECTED TEXT
vedselection_cut();
;;; INSERT THE TEXT "SELECTION\index{SELECTION}"
vedinsertstring(string);
vedinsertstring('\\index{');
vedinsertstring(string);
vedinsertstring('}');
else
vederror('YOU HAVE TO SELECT SOMETHING');
endif;
;;; TO TELL XVED WE HAVE HANDLED THE BUTTON EVENT
true -> xvedeventhandled;
enddefine;
We now need to say when the handler gets called. We do this with
-vedset- like this (see REF * XVED for details.)
vedset mouse (at front)
index_selection = click btn2 2 times
endvedset
Which basically translates to "call -vedmouse__index_selection- when you
double click button 2".
Hope this helps.
aids (adrianh@cogs.susx.ac.uk) ObDisclamer: Poplog used to pay my wages
Phone: +44 (0)273 678367 URL: http://www.cogs.susx.ac.uk/users/adrianh/
|