topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 3:43 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: what is happening in this key sequence?  (Read 10696 times)

mackal

  • Member
  • Joined in 2007
  • **
  • Posts: 25
    • View Profile
    • Donate to Member
what is happening in this key sequence?
« on: August 23, 2007, 02:09 PM »
Hi all, I am really starting to get excited about the power of FARR as I slowly discover the new things in 2.0... but occasionally I'm having a hard time understanding what FARR is thinking/doing.  Here is one example in particular, perhaps someone can explain to me what is happening:

  • I hit Ctrl-Space, and FARR comes up
  • I type "tor"; the first entry is the "torrent" alias group in Core_Aliases\Core-Search.alias file
  • I hit Tab or Alt-1, at which point the alias is autocompleted to "torrent" and only the aliases in the group now appear in the result window
  • now when I type the next word, the additional text is used to filter the alias group to only those entries that match the typed text; makes sense
  • once I narrowed down the list of torrent search engines so that the one I want is the only one (or at least at top of list), if I hit space and add another word (presumably the search words), the result list goes empty and hitting Enter does nothing

???

Now, I understand on the lowest level that the problem is that the additional words in the last point are being treated as additional filtering to the list of aliases in the group.  But, how do I enter an argument for $$1 in that case?  Is FARR not supposed to be used in this fashion? (i.e., autocompletion with alias groups)

Of course the workaround is to not hit Tab/autocomplete the alias, but simply use something like "tor my search words" and then use Alt-<number> to fire up the desired search engine.  But the outlined approach above should also work, no?

On a related note, is there way to fire *all* the search engines?  According to help, hitting Ctrl-Enter should execute all the search results, but this only fires up the top-most torrent search for me... I've never actually gotten Ctrl-Enter to work (but haven't really tried it with executables).

Any help on any of the above points would be most welcome.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #1 on: August 23, 2007, 03:04 PM »
I can help a bit.

The torrent vs. tor issue is actually behaving as it should but it's problematic.
The problem is this:
The name of the alias is "torrent" but the regular expression keys on "tor (.*)"
SO, when you type the full word torrent it shows all results in that alias BUT it doesnt know how to regular expression extract.
So it really wants you to type: "tor searchwords"

Now a more subtle problem is that if you use regular expression you can't filter out certain searches.

I think there are two solutions needed in the ideal case.

The first one is easy and that is to make the regular expression for this group match on "tor[rent] (.*)" (whatever the regex for that is) -- that would solve the main problem.

I was also thinking that to enable filtering on regular expressions, we could add a special character that would filter and NOT get matched against regular expressions.  So for example you could type:
"tor searchword *FILTER WORDS"

and it would match as if you typed "tor searchword", and THEN do a filter on results using everything after the *.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #2 on: August 23, 2007, 03:06 PM »
To launch all results i think it's now Ctrl+Alt+Enter (not just Ctrl+Enter).. i forget why.

mackal

  • Member
  • Joined in 2007
  • **
  • Posts: 25
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #3 on: August 23, 2007, 03:26 PM »
To launch all results i think it's now Ctrl+Alt+Enter (not just Ctrl+Enter).. i forget why.

Yes, that was it, thanks.  It would be helpful to amend the help file then, where it still has the old binding.  It's under Advanced Use > Hotkey and Shortcut Summary.

Muahahahaha! >:D  I feel like an evil overlord of the universe with all that power at my fingertips now...  :D

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #4 on: August 23, 2007, 03:30 PM »
It would be helpful to amend the help file then, where it still has the old binding.  It's under Advanced Use > Hotkey and Shortcut Summary.

Thanks, it will be fixed in the new update.

mackal

  • Member
  • Joined in 2007
  • **
  • Posts: 25
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #5 on: August 23, 2007, 03:33 PM »
The first one is easy and that is to make the regular expression for this group match on "tor[rent] (.*)" (whatever the regex for that is) -- that would solve the main problem.

I was also thinking that to enable filtering on regular expressions, we could add a special character that would filter and NOT get matched against regular expressions.  So for example you could type:
"tor searchword *FILTER WORDS"

and it would match as if you typed "tor searchword", and THEN do a filter on results using everything after the *.

Ah, everything is clear now, thanks!  I don't know much (yet) about the mechanics of FARR in how it approaches regex extraction, but your second suggestions sounds excellent!  

An alternative suggestion for the "stop parsing" token would be to use "--"... there is some precedent for this in the UNIX/commandline world, where the token "--" signals to the shell/launcher to stop parsing for command line flags (of the form "-o" or "--another-option"), and simply pass the remaning arguments wholesale to the program invoked, even if they start with a dash.  So in the above example it could be "torrent keyword1 keyword2 keywordn -- nova".

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #6 on: August 23, 2007, 03:50 PM »
by the way for any given custom regular expression you can add this feature yourself if you are daring.

You basically add a second capture group to the regular expression, and use that in the alias "Result Filter" box.

So for example instead of:
^tor (.*)
You would match on
^tor (.*) [--(.*)]?

(actually im not sure about that []? part but if you know regular exressions im trying to add a second expression that is optional).

Then in the Result Filter box you put $$2



Having said that i think it's smarter to add a generic way of applying result filtering to regular expression results and so i will add it, just have to decide on the special characters to use for it.


nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #7 on: August 23, 2007, 04:33 PM »
Having said that i think it's smarter to add a generic way of applying result filtering to regular expression results and so i will add it, just have to decide on the special characters to use for it.

those are all very good ideas !

another suggestion :
a second edit box below the search box or on the right... (optionnal of course ;))
the tab key would cycle through the search box, the filter box, the result (if tab autocompletes is unchecked)

the workflow would be amazing
example :
search keyword {TAB} goo
yubnub keyword {TAB} imdb

That would be so GREAT  :D
please do that  :P

in case you don't do it, i would use this autohotkey script
#IfWinActive,  Find and Run Robot v2 ahk_class TMainForm
Tab::
SendPlay, {Space}--
return
 #IfWinActive


Cheers, nitrix

nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #8 on: August 23, 2007, 04:55 PM »
So for example instead of:
^tor (.*)
You would match on
^tor (.*) [--(.*)]?

i could not make this to work but i'm really interested in making the filter optional
anyone knows how to solve that ?

mackal

  • Member
  • Joined in 2007
  • **
  • Posts: 25
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #9 on: August 23, 2007, 05:19 PM »
So for example instead of:
^tor (.*)
You would match on
^tor (.*) [--(.*)]?

i could not make this to work but i'm really interested in making the filter optional
anyone knows how to solve that ?

Generally "[]" in regex means any character from within those listed between the square brackets (e.g., "[Ii]gnore [Cc]apitalization [Ii]n [Ww]ords"), so this does not work.  To make the second term optional, you really need

^tor (.*) (--(.*))?

But I'm not sure how FARR regexp engine handles nested groups (i.e., "()") as far as assigning them to $$1, $$2, etc.  In some regexp implementations there is a way to specify that a particular "()" is being used only for grouping, and not for extraction; not sure if FARR engine supports that.  If not, then probably the outer group is assigned to $$2, while the inner group to $$3... so you would have to use $$3 in the result filter box.

EDIT: Ah, found it through experimentation, FARR using emacs-like syntax... here is what you want:

^tor (.*) (?:--(.*))?

or to answer my original post

^tor(?:rent)? (.*) (?:--(.*))?

In this particular regex syntax "(?:foo)" means "group foo, but do not extract to a positional parameter".  Thus "tor(?:rent)?", for example, means match either "tor" or "torrent", and if the latter, don't let it affect the meaning of $$1, etc.

EDIT#2: Oops, the latter part, the alias filtering doesn't work because regex engines are greedy and thus the first "(.*)" always matches everything, including any "-- whatever bits here".  It's tricky to do this cleanly.  The workaround I came up with, which is a bit kludgy, is to use:

  ^tor(?:rent)? (?:(.*) -- (.*)|(.*))()

and then modify the torrent search engine invocations to something like

  Mininova | http://mininova.org/search/?search=$$1$$3 /ICON=icons\mininova.ico

Note the $$1$$3 instead of just $$1.

Explanation:

^tor(?:rent)?
    This part is the same as before.

(?:(.*) -- (.*)|(.*))
    Either match strings of form "xxx ... -- yyy ..." or, if not possible (i.e., "--" does not exist), match everything else.
    The outer "(?: ...)" groups the expression, limiting the scope of the "|", but does not cause parameter extraction itself.
    The problem with this, and the ugliness, is that in the case where "--" is absent and the second case is used, that last "(.*)" is assigned to $$3, and not $$1; hence the need for "$$3$$1".

the trailing "()"
    This is necessary in the case where "--" is present, since in this case the last "(.*)" is not used, and thus $$3 does not exist; what ends up happening is that "$$3" is left verbatim in the invocation string.  This extra "()" thus causes $$3 to exist (and be empty) in this scenario; in the alternate case it simply generates a blank $$4.

Oof.  Ugly, I know, but it works.  A greater regex master than I needs to tell us what the proper way of doing this is, if it is even possible to do cleanly.


   
   
« Last Edit: August 23, 2007, 07:51 PM by mackal »

mackal

  • Member
  • Joined in 2007
  • **
  • Posts: 25
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #10 on: August 23, 2007, 05:25 PM »
Incidentally, does anyone know where to find the regexp language specification for the regex engine in FARR?  Mouser?  I presume FARR uses an off-the-shelf/Net library, so maybe the docs for that library will specify this...

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #11 on: August 23, 2007, 06:50 PM »
pcre is the engine i use: http://www.pcre.org/

mackal

  • Member
  • Joined in 2007
  • **
  • Posts: 25
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #12 on: August 23, 2007, 07:39 PM »
Cool, thanks for the info.  So it's Perl-style regexp; that's great!  For anyone else interested, I'll save you the trouble of googling, the full syntax for the Perl regex is here:
    http://perldoc.perl.org/perlre.html

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #13 on: August 24, 2007, 02:56 AM »
To launch all results i think it's now Ctrl+Alt+Enter (not just Ctrl+Enter).. i forget why.

maybe this would refresh your memory, mouser.. :) btw, now that there is customisable hot-keys, how can i revert the action back to Ctrl+Enter?

nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #14 on: August 24, 2007, 03:20 AM »
^tor(?:rent)? (?:(.*) -- (.*)|(.*))()

;D whouah !
this is really one wicked regular expression

Thanks for the tip Mackal !  :Thmbsup:
works great

but there are still problems :
Another way is to use $$c in an alias command which will use the $$1 regular expression field IF it exists, or else clipboard if not.
the $$cc variable does not work here since you want $$c to be $$1$$3
@mouser, is there a way to make $$c be $$1$$3 or clipboard content ? maybe thanks to new variables ?
%$$c|$$1$$3%
  :D

an other way is to use $c :
tor $c -- mini
not as convenient though

Nitrix

« Last Edit: August 24, 2007, 03:25 AM by nitrix-ud »

mackal

  • Member
  • Joined in 2007
  • **
  • Posts: 25
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #15 on: August 24, 2007, 03:51 PM »
Ugh, fudging $$cc to accomodate a kludge... ugliness.  No, the original regex situation must be solved.  And I think it has been.  I gave it some more thought, and here is the proper solution, or at least on way to do it cleanly:

^tor(?:rent)? ((?:[^-]|-(?!-))*)(?:\s*--\s*(.*))?()



Yes, it's hairy, but does things properly.

Explanation:

^tor(?:rent)?
    Same as before.

((?:[^-]|-(?!-))*)
    Capture group $$1: capture as many characters as possible, as long as they are not a dash, or a dash followed by anything other than a second dash.  The outer "()" pair does the capturing/extraction.  The inner "(?: ...)" is there to limit extent of "|", without capturing.  The "(?!-)" is a negative look-ahead: matches when next character is not a dash, but does not consume it.

(?:\s*--\s*(.*))?
    Capture group $$2.  The outer "(?: ....)" groups the expression without capturing.  The trailing "?" makes the whole chunk optional.  The "\s*" are there to strip any white space, although the first instance is futile (the previous capture group will gobble up its trailing white space... regex parsing is greedy).  The inner "(.*)" is the part that actually does the capturing/extraction of $$2.

the trailing ()
    This again was needed, in the case where "--" is not given on the command line.  In such cases $$2 does not exist, hence the "$$2" in the "Result Filter for RegEx" field is being treated as a literal string, rather than a variable.  This causes 0 matching results, unless one of the result hits contains a literal (unsubstituted) "$$2" string.

So with this regex you can go back to using $$1 instead of $$1$$3.

Hope this helps.

nitrix-ud

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 560
    • View Profile
    • Donate to Member
Re: what is happening in this key sequence?
« Reply #16 on: August 25, 2007, 05:15 AM »
@mackal
thanks ! wonderful regex

@mouser,
i think mackal should be a contributor to the advanced FARR hacking guide :D