16668Re: Creation of clip
- Jun 24, 2007Hi Flo,
--- In email@example.com, "Flo" <flo.gehrke@...> wrote:
> I'm grateful to you for all these recommendations, and I tried to
> apply them to this clip...
> > When a clip makes use of the clipboard, its nice to restore its
> > original contents at the end.
> That's not given here, isn't it?
Well you do "^!Menu Edit/Copy All" near the end so you can paste the
result to a new document. As is, that ends up remaining on the
clipboard after the clip has finished.
> But I think it could easily be done by saving its contents in a
> variable, and afterwards pasting it back to the clipboard like..
> ^!Set %Var%=^$GetClipboard$ ... ^!SetClipboard ^%Var%
See ^!ClipboardSave and ^!ClipboardRestore
> > You'd have to navigate to the original docindex and then close
> > discard the keywords document.
> I changed the order of these command lines.
> By the way: Isn't it even safer to work with the document name?
> Given that the clip always gets started from the original
> document, we could replace...
> ^!Set %Doc%=^$GetDocIndex$^ with ^!Set %Doc%=^GetDocName
> ^!SetDocIndex ^%Doc% with ^!Open ^%Doc%
Yes, that should work. But then NoteTab has to find the docindex,
maybe slightly faster if you save and restore the docindex yourself.
> (According to the help file, I suppose that ^!Open also selects a
> document that is open already.)
> > Normally it would be a good idea to reverse sort alternates...
> See line #8, and 9 now
> > metacharacters in the keyword document...should be escaped
> > with a backslash
> Certainly, this would be a professional solution. In message # 15199
> you created a subclip GetRegEscape that would do this job.
Since you're using a document buffer, you could use a single ^!Replace
to replace any metacharacters (alternates -- be sure to escape them)
with "\\$0"; the GetRegEscape clip approach is necessary only when
acting on a string instead of a document. There is currently no
provision in NoteTab to do regex string operations.
> > its probably a good idea to check ^!IfRegexOK before using the
> > expression in a "real" statement.
> I hope I've done it the right way.
Haven't tried it, but it looks good to me :)
I haven't made use of classes like punct before myself, so you're
blazing a trail :)
> > Using \b's before and after the alternates would also work, if
> > the keywords are meant to be whole words only.
> This has been added too.
> In addition to that, I've combined the \b's with a negative
> lookbehind and lookahead. They do not allow certain characters
> before or behind a search word that is being treated as a whole
> word. This is mainly aiming at words hyphenated with - (ANSI 45)
> and the apostrophe ' (ANSI 39). For example: If "McDonald" is
> defined as a keyword it normally matches "McDonald's" too even if
> embraced with \b
> since - and ' are interpreted as word delimiters. Consequently, the
> clip would delete a line like...
> "eating a hamburger at McDonald's"
> although it isn't really matched by "McDonald" as a whole word.
> Or "self-service" would be matched by "self" and "service" as well
> although they possibly are regarded as substrings of "self-service"
> only. It depends, of course, on the way you look at "lexical
> problems" like that, and also on the sort of text to be processed.
> Certainly, this construction needs some more testing...
> How to deal with compound nouns written with a space (ANSI 32)?
> For example: "Express" would delete "American Express" although
> we possibly don't regard it as a match of that compound. The only
> solution I can see for that is to enter "American Express" with a
> protected space (ANSI 160) in order to distinguish it from the
> normal space (ANSI 32). With regard to this, we could extend the
> Lookarounds with \xA0 in order to match ANSI 160. Maybe there's a
> better solution (or even more problems)...
Hmn, you bring up some interersting points. "American Express" would
be its own keyword as would "Express". In the case of the "Express"
alternate, it could use a negative look behind, to make sure it it not
preceded by "American\x20". Obviously would require some fine tuning
of the keywords or alternates before applying them to customize them
to that extent.
> ^!SetScreenUpdate Off
> ^!SetHintInfo Working...
> ^!Set %Doc%=^$GetDocIndex$
> ^!Set %Keywords%=^?[(T=O;F="Textfiles (*.txt)|*.txt")Choose Keyword
> ^!Set %Case%=^?[Case-sensitive search:==Yes^=(?-i)|_No^=(?i)]
> ^!Set %Substr%=^?[Search whole words only:==Yes^=1|_No^=0]
> ^!Open ^%Keywords%
> ^!Select All
> ^!Replace "(\r\n)+" >> "|" AWRS
> ^!Replace "\|\Z" >> "" AWRS
> ^!Replace "\A\|" >> "" AWRS
> ^!Set %Search%=^$GetText$
> ^!SetDocIndex ^%Doc%
> ^!Close ^%Keywords% Discard
> ^!IfTrue ^%Substr% Next Else Skip_2
> ;^!Set %Expr%="^%Case%^.*\b(^%Search%)\b.*\r\n"
> ; start of long line
> ^!Set %Expr%="^%Case%^.*\b(?<![[:punct:]])(^%Search%)(?![[:punct:]])
> ; end of long line
> ^!Goto Skip
> ^!Set %Expr%="^%Case%^.*(^%Search%).*\r\n"
> ; Try next line for testing RegEx error ;-)
> ;^!Set %Expr%="[[:punkt:]]+"
> ^!IfRegExOK "^%Expr%" Next Else Message
> ^!Menu Edit/Copy All
> ^!Menu Edit/Paste New
> ^!Replace "^%Expr%" >> "" AWRS
> ^!Info Finished!
> ^!Goto End
> ^!Prompt ^$GetRegexErrorMsg$
- << Previous post in topic Next post in topic >>