Page 1 of 1

Open browser from editor

Posted: Sat 15 Sep, 2012 21:45
by Geth
Hi,

I've switched recently to FAR3 from FAR1. I've used this plugin to open URLs from the editor. Since it's not maintained anymore, I decided to mimick its feature by macro (FML).
Use it if you wish (fix bugs, customize it), it's just an idea. Also, if you can point me to a better solution (macro/plugin), please do so.

Here it is, it does what I wrote earlier:

Code: Select all

macro Areas="Editor" Bind="CtrlH" Condition="Selected:0" Description="Editor - Open Link" Name="EditorOpenLink" {{
    History.Disable(1)
    %position = Editor.CurPos;
    End
    Editor.Undo(0)
    Print(" ")
    Editor.Undo(1)
    Editor.Pos(1, 2, %position)
    $While (Editor.CurPos != 1 && substr(Editor.Value, Editor.CurPos - 1, 1) != " " && substr(Editor.Value, Editor.CurPos - 1, 1) != "\"" && substr(Editor.Value, Editor.CurPos - 1, 1) != "'" && substr(Editor.Value, Editor.CurPos - 1, 1) != "{")
        Left
    $End
    $If (Editor.CurPos != 1 || substr(Editor.Value, Editor.CurPos - 1, 1) == " " || substr(Editor.Value, Editor.CurPos - 1, 1) == "\"" || substr(Editor.Value, Editor.CurPos - 1, 1) == "'" || substr(Editor.Value, Editor.CurPos - 1, 1) == "{")
        Right
    $End
    $If (substr(Editor.Value, Editor.CurPos - 1, 4) != "http")
        Editor.Undo(2)
        Editor.Pos(1, 2, %position)
        $Exit
    $End
    $While (substr(Editor.Value, Editor.CurPos - 1, 1) != " " && substr(Editor.Value, Editor.CurPos - 1, 1) != "\"" && substr(Editor.Value, Editor.CurPos - 1, 1) != "'" && substr(Editor.Value, Editor.CurPos - 1, 1) != "}")
        ShiftRight
    $End
    %link = Editor.SelValue;
    F12
    %screenNumber = GetHotkey();
    0
    Esc
    Print(@"run:nul<start " + %link)
    Enter
    F12
    Print(%screenNumber)
    Editor.Undo(2)
    Home
    Editor.Pos(1, 2, %position)
}}
Notes:
  • Uses Windows default URL handler (means default browser)
    Opens the links which starts with http
    Won't work correctly on for example (http://example.com), so when there's an extra character at the start/end. Works if the extra characters are either single or double quotes or curly braces (as you can see in the ugly code). Idea: call external URL parser?
    Destroys command line content
Here's another macro, which will open browser search with selected text, assuming browser can do search like IE (use of question mark):

Code: Select all

macro Areas="Editor" Bind="CtrlAltH" Condition="Selected:1" Description="Editor - Search Internet" Name="EditorSearchInternet" {{
    History.Disable(1)
    %term = Editor.SelValue;
    F12
    %screenNumber = GetHotkey();
    0
    Esc
    Print("run:nul<|\"" + %%BrowserPath + "\"|start \"\" \"" + %%BrowserExecutable + "\" ? " + %term)
    Enter
    F12
    Print(%screenNumber)
}}
Now to use this second one, you should configure your browser like in this macro:

Code: Select all

macro Areas="Shell" Description="OnStart" Events="Open" Name="OnStart" {{
    $If (Env("PROCESSOR_ARCHITECTURE") == "x86")
        %%BrowserPath = Env("ProgramFiles");
    $Else
        %%BrowserPath = Env("ProgramFiles(x86)");
    $End
    %%BrowserPath = %%BrowserPath + @"\Internet Explorer";
    %%BrowserExecutable = "IExplore.exe";
    MSave("%%BrowserPath")
    MSave("%%BrowserExecutable")
}}
Feel free to comment on it.

Re: Open browser from editor

Posted: Sun 16 Sep, 2012 16:18
by HaRT
What's wrong with the «Open in new window­» (ONew) plugin in FAR3? FAR3 supports FAR1 plugins.
BTW, I use the Active Help plugin to open URLs from the Editor.

Re: Open browser from editor

Posted: Sun 16 Sep, 2012 17:03
by Geth
Hi,

Thanks for comments.
As for the OpenNew and Active Help plugins: I disabled OEM plugin support (all the other plugins I use are FAR3 versions). I assume that might be a problem? Also I use FAR x64, so these won't work (OEM plugins enabled). Links for example this one: http://hu.wikipedia.org/wiki/Árvíztűrő_tükörfúrógép, will these work?

Re: Open browser from editor

Posted: Fri 21 Sep, 2012 02:52
by Geth
I've uploaded a version with minor improvements: 1 stupid bug fixed via quoting the url when sent to start, the open link feature works on selection too, so opening partial links is now possible.