Re: open_webpage function

From: mitchell <mforal.n....at.gmail.com>
Date: Tue, 23 Mar 2010 07:43:43 -0700 (PDT)

Robert,

Thanks. Added to hg (r527).

Mitchell

> since not even Microsoft is forcing Internet Explorer on its users
> anymore I think Textadept shouldn't either. ;-)
> I came up with the following in menu.lua
>
> local function open_webpage(url)
>   local cmd
>   if WIN32 then
>     cmd = string.format('start \"\" \"%s\"', url)
>     if io.popen(cmd) == nil then error(l.MENU_BROWSER_ERROR..url) end
>   else
>     if MAC then
>       cmd = string.format('"%s" "file://%s"', 'open', url)
>     else
>       cmd = string.format('%s "%s"', 'xdg-open', url)
>     end
>     if os.execute(cmd) ~= 0 then error(l.MENU_BROWSER_ERROR..url) end
>   end
> end
>
> In Windows there is the 'start' command to open files and webpages
> with the 'default application'. For some reason it didn't work (for
> me) with os.execute, so I used io.popen. I'm not sure if it's a
> problem that there is no closing of this object.
> The first option for 'start' is the name of the window or something so
> the command is e.g.
> start "" index.html
> (I also tried rundll32 url.dll,FileProtocolHandler index.html, but
> this command only worked from the command line not when I tried to
> call it through Textadept.)
>
> On Linux there are as well options like the Mac 'open' command: I
> found xdg-open, x-www-browser and gnome-open.
> I believe that xdg-open (part of the package xdg-utils) is the most
> common. x-www-browser appears to be part of Debian, and gnome-open
> comes with libgnome. I have it installed even though I don't have a
> Gnome desktop.
> They all seem to use different mechanisms to define the 'default
> browser'.
>
> If the Error message in locale.conf is changed to:
> % core/ext/menu.lua
> % "Error loading webpage:
> MENU_BROWSER_ERROR "Error loading webpage: "
>
> The error message will tell the user which file it tried to load:
> /home/robert/textadept/core/ext/menu.lua:352: Error loading webpage: /
> home/robert/textadept/doc/index.html
>
> So if no xdg-open or other launcher is found, the user could copy and
> paste the path into his browser of choice.
>
> - Robert
Received on Tue 23 Mar 2010 - 10:43:43 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:40:34 EST