sfk@com.hp.hpl.hplb (Steve Knight) wrote:
>
> > Since so few people have responded to my query about this I have begun
> > to suspect that the vast majority of VED users never use backward search
> > anyway. (I've even found some who don't use any search: they always
> > manually scroll up and down the file looking for things.)
>
> What I would like is, now we have the luxury of XVED, is a
> find command that puts up a dialog-box. ("Oh, boring," I can hear
> people thinking to themselves. But wait! There's more.) When
> the user presses the "Search" button it composes a VED command,
> sticks it on the command line, closes the dialog box, and
> executes the command line.
Aha. Try:
<ENTER> searchfor
and
<ENTER> replace
They don't work quite as you describe, but it is a start...
If you don't like either of these, below is a version that I
wrote for my use, which operates similarly to the Frame version. I
like it.
/* --- Copyright University of Sussex 1992. All rights reserved. ----------
> File: $poplib/ved_searchfor.p
> Purpose: Search dialog box.
> Author: Jonathan Meyer, Sept 9 1992
> Documentation: REF *VED_REGEXP_SEARCH *REGEXP
> Related Files: SRC *VED_REGEXP_SEARCH.P *REGEXP_COMPILE.P
*/
section;
compile_mode :pop11 +strict;
uses ved_regexp_search;
;;; ensure that these have been cancelled first:
syscancel("ved_searchfor"); syscancel("ved_replace");
lvars search_box = false, search_sheet, search_sheet1, coords = "selection";
weak vars $-xved$-xvedselectioncoords;
define lconstant box_accept(box, button);
lvars box, button;
if button == "Close" then
propsheet_destroy(search_box);
return(false);
endif;
;;; vedinput will clear the XVed selection, so we remember where the
;;; selection is ourselves.
if testdef xved then
copy(weakref $-xved$-xvedselectioncoords) -> coords;
endif;
vedinput(
procedure;
lvars str, repstr;
;;; puts up an error message.
define dlocal vederror(str);
lvars str, old;
if vedinvedprocess then
dlocal pop_ui_promptsource = search_box;
vedscreenbell();
vedputmessage(str);
;;; STR -> Str.
uppertolower(str) sys_>< '.' -> str;
lowertoupper(str(1)) -> str(1);
pop_ui_prompttool('Ved:Error', "error",
str,true, [Ok], 1) -> (,);
vedinterrupt();
else
mishap(0, str)
endif;
enddefine;
;;; checks that the cursor is over a match
define lconstant Check_cursor_is_on_match(args);
lvars args;
consvector(args.destlist) -> args;
0 -> args(5); ;;; fromhere
lvars (line, col,,) = ved_regexp_search(explode(args));
unless line then
vederror('NOT FOUND');
elseunless line == vedline and col == vedcolumn then
vederror('MUST SEARCH BEFORE CHANGING');
endunless;
enddefine;
search_sheet("Wildcards") -> str;
dlocal vedwildcards = (
if isstartstring('No', str) then
false
elseif isstartstring('Ed', str) then
"ed"
else
true
endif);
if (search_sheet('Search For') ->> str) = nullstring then
vederror('NOTHING TO SEARCH FOR');
endif;
search_sheet('Change To') -> repstr;
;;; set ved so that it will redo this search
ved_set_search(str, repstr, []);
;;; compile the search pattern
ved_regexp_compile(str, repstr,
not(member('Consider Case', search_sheet("Options"))),
not(member('Whole Word', search_sheet("Options"))),
) -> str;
;;; get common search arguments
lvars commonargs = [%
str,
if search_sheet("Within") == "Selection" then
;;; use my own copy of the coords
coords
else
uppertolower(search_sheet("Within")),
endif,
search_sheet("Direction") = 'Backward',
search_sheet("wrap"),
true,
false,
%];
if button == "Search" then
vedputmessage('SEARCHING');
ved_regexp_jumpto(commonargs.dl, ved_regexp_search(), true);
vedputmessage('FOUND');
elseif button = "ChangeAll" then
ved_regexp_substitute(commonargs.dl, false, false, false);
elseif button == "Change" then
Check_cursor_is_on_match(commonargs);
ved_regexp_substitute(commonargs.dl, false, 0, false);
elseif button == "SearchChange" then
vedputmessage('SEARCHING');
ved_regexp_substitute(commonargs.dl, false, 0, false);
else ;;; ChangeSearch
Check_cursor_is_on_match(commonargs);
ved_regexp_substitute(commonargs.dl, false, 0, false);
vedcharright();
vedputmessage('SEARCHING');
ved_regexp_jumpto(commonargs.dl, ved_regexp_search(), true);
vedputmessage('FOUND');
endif;
endprocedure);
false
enddefine;
define lconstant command_accept(s, f, v) -> v;
lvars s, f, v;
box_accept(search_box, f)->;
enddefine;
define global vars ved_searchfor;
unless XptIsLiveType(search_box, "Widget") then
propsheet_new_box('Ved:Search', false, box_accept, ['X']) -> search_box;
propsheet_new(false, search_box, [
['Search For' '' (width = 50) ]
[Options
{'Consider Case' 'Whole Word'} (default = [1], nolabel)
]
+[Wildcards menuof
{'No Wildcards' 'Ed Style Wildcards' 'Ved @ Wildcards'}
(nolabel, aligned = ^false)
]
['Change To' '' (width = 50)]
[Within [File Range Procedure Line Selection]]
['Direction' ['Forward' 'Backward']]
+[wrap true (label= ' Wrap Around')]
]) -> search_sheet;
propsheet_new(false, search_box, [
[Search command Search
(nolabel, aligned = ^false, accepter = ^command_accept)]
+[Change command 'Change'
(nolabel, aligned = ^false, accepter = ^command_accept)]
+[ChangeSearch command 'Change and Search'
(nolabel, aligned = ^false, accepter = ^command_accept)]
+[ChangeAll command 'Change All'
(nolabel, aligned = ^false, accepter = ^command_accept)]
+[Close command ' Dismiss '
(nolabel, aligned = ^false, accepter = ^command_accept)]
]) -> search_sheet1;
endunless;
propsheet_show(search_sheet);
propsheet_show(search_sheet1);
XtUnmanageChild(propsheet_subpart(search_box, "lower_controls"));
propsheet_show(search_box);
enddefine;
define global vars ved_replace;
ved_searchfor();
enddefine;
endsection;
|