Open browser from editor

Here you can discuss any topic concerning Far macro commands.
Post Reply
User avatar
Geth
Posts: 3
Joined: Sat 15 Sep, 2012 20:55
Location: Budapest, Hungary

Open browser from editor

Post 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.
User avatar
HaRT
Moderator
Posts: 10806
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 220 times
Been thanked: 357 times

Re: Open browser from editor

Post 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.
Фар есть инструмент, а не нянька. © 2009 DrKnS
User avatar
Geth
Posts: 3
Joined: Sat 15 Sep, 2012 20:55
Location: Budapest, Hungary

Re: Open browser from editor

Post 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?
User avatar
Geth
Posts: 3
Joined: Sat 15 Sep, 2012 20:55
Location: Budapest, Hungary

Re: Open browser from editor

Post 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.
Post Reply

Return to “Macro Commands Discussions”