Re: open_webpage function

From: Robert <ro....at.web.de>
Date: Fri, 2 Apr 2010 00:38:12 -0700 (PDT)

Hi Mitchell,

I tested the 2.2beta (Thanks a lot!) and
unfortunately there seems to be a problem on Windows.
With the p:close() you added the Windows "shell" just hangs.
It's of course nicer to close a connection but if I read the docs
correctly it should get closed automatically.
This works (on my Win XP):

-- WIN32
cmd = string.format('start "" "%s"', url)
local p = io.popen(cmd)
if not p then error(l.MENU_BROWSER_ERROR..url) end -- else p:close()
end

Does it work for anybody on other Windows versions?

- Robert

On 31 Mrz., 00:17, mitchell <mforal.n....at.gmail.com> wrote:
> Robert,
>
> > I've been using this and it appears that (at least on my setup) xdg-
> > open doesn't allow returning to Textadept without closing the browser
> > (in my case Firefox) - with gnome-open there is no problem.
> > So either we shouldn't use xdg-open or add an & to the command string.
> > 'xdg-open "%s" &'
>
> > Sorry, I thought had tested this.
>
> Thanks. Committed.
>
> Mitchell
>
> > Robert
>
> > On Mar 23, 4:43 pm, mitchell <mforal.n....at.gmail.com> wrote:
>
> > > 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 Fri 02 Apr 2010 - 03:38:12 EDT

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