all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* browse-url/w32-shell-execute problems on cygwin
@ 2009-06-17 15:47 Ken Brown
  2009-06-17 16:06 ` Jason Rumney
  0 siblings, 1 reply; 9+ messages in thread
From: Ken Brown @ 2009-06-17 15:47 UTC (permalink / raw)
  To: Emacs

In browse-url.el, browse-url-browser-function is set to 
browse-url-default-windows-browser on cygwin.  But the definition of 
browse-url-default-windows-browser uses w32-shell-execute, which is 
defined in w32fns.c and is not included in the cygwin build.  My 
personal workaround for years has been the following:

;; Minimal replacement for w32-shell-execute under Cygwin.
(defun w32-shell-execute (operation document &optional parameters show-flag)
   (if (string-equal operation "open")
     (shell-command (concat "cygstart " (shell-quote-argument document)))))

(Note: For those not familiar with cygstart, it is a cygwin utility that 
will launch anything that you can type in the "Start Menu" -> "Run" box 
in windows.  For example, typing 'cygstart "http://google.com"' in a 
cygwin shell will open the default windows browser and go to google.)

This has always sufficed for my purposes, though I suppose it would be 
better to implement other operations besides "open" or, at least, give a 
"not implemented" error if there's an attempt to use some other operation.

Now that I am cygwin's emacs maintainer, I would like to replace this 
personal workaround by a suitable change to the emacs sources.  Can 
someone more knowledgeable than I am propose or apply a patch so that 
cygwin users won't get an error when they try to use browse-url?  One 
option would be to implement w32-shell-execute.  Another would be to 
redefine browse-url-default-windows-browser so that, in cygwin, it 
simply calls cygstart on the URL.  Maybe there's a better solution.

Second problem: browse-url-of-file doesn't work right under cygwin 
because it relies on browse-url-file-url to convert the file name to a 
URL; but the URL it returns is not in a form that a windows browser can 
understand.  For example, evaluating

   (browse-url-file-url "/home/kbrown/html/index.html")

yields "file:/home/kbrown/html/index.html", but (on my system) it would 
need to be "file://d:/cygwin-1.7/home/kbrown/html/index.html" for the 
windows browser to be able to handle it.

My personal workaround has been to bypass browse-url-file-url completely 
and instead modify browse-url-of-file:

-  (browse-url (browse-url-file-url file))
+  (w32-shell-execute "open" file)

The point here is that there is no need to convert the file name to a 
URL; the cygwin shell command  'cygstart "/home/kbrown/html/index.html"' 
does the job.

Again, I would appreciate it if someone could find a way to fix the 
problem in the emacs sources.  If you could even just give me some 
pointers as to what approach would be acceptable, I could probably 
provide a patch.

Thanks.

Ken





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 15:47 browse-url/w32-shell-execute problems on cygwin Ken Brown
@ 2009-06-17 16:06 ` Jason Rumney
  2009-06-17 16:14   ` Ken Brown
                     ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jason Rumney @ 2009-06-17 16:06 UTC (permalink / raw)
  To: Ken Brown; +Cc: Emacs

Ken Brown wrote:
> In browse-url.el, browse-url-browser-function is set to 
> browse-url-default-windows-browser on cygwin.
That is wrong, feel free to change it to a better default.

> Second problem: browse-url-of-file doesn't work right under cygwin 
> because it relies on browse-url-file-url to convert the file name to a 
> URL; but the URL it returns is not in a form that a windows browser 
> can understand.  For example, evaluating
>
>   (browse-url-file-url "/home/kbrown/html/index.html")
>
> yields "file:/home/kbrown/html/index.html", but (on my system) it 
> would need to be "file://d:/cygwin-1.7/home/kbrown/html/index.html" 
> for the windows browser to be able to handle it.

That is a general problem with cygwin interacting with non-cygwin 
programs. Cygwin invents its own virtual filesystem that is not 
understood outside of cygwin. See the problems the native build of Emacs 
faces with Cygwin make. I don't see how bypassing browse-url fixes this 
for you, as the path will still be one that Windows does not recognize.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 16:06 ` Jason Rumney
@ 2009-06-17 16:14   ` Ken Brown
  2009-06-17 18:02   ` Ken Brown
  2009-06-17 22:23   ` David Robinow
  2 siblings, 0 replies; 9+ messages in thread
From: Ken Brown @ 2009-06-17 16:14 UTC (permalink / raw)
  To: Jason Rumney; +Cc: Emacs

On 6/17/2009 12:06 PM, Jason Rumney wrote:
> I don't see how bypassing browse-url fixes this 
> for you, as the path will still be one that Windows does not recognize.

No, cygstart takes care of the interaction with Windows.  If you have a 
cygwin system available, just open a shell and type

   cygstart "/unix/style/path/file.html"

and you'll see that it works.  You can omit the quotes as long as 
there's nothing in the file name that needs quoting (like spaces).

Ken




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 16:06 ` Jason Rumney
  2009-06-17 16:14   ` Ken Brown
@ 2009-06-17 18:02   ` Ken Brown
  2009-06-17 21:30     ` Ken Brown
  2009-06-17 22:23   ` David Robinow
  2 siblings, 1 reply; 9+ messages in thread
From: Ken Brown @ 2009-06-17 18:02 UTC (permalink / raw)
  To: Jason Rumney; +Cc: Emacs

On 6/17/2009 12:06 PM, Jason Rumney wrote:
> Ken Brown wrote:
>> In browse-url.el, browse-url-browser-function is set to 
>> browse-url-default-windows-browser on cygwin.
> That is wrong, feel free to change it to a better default.

I don't agree.  Since cygwin doesn't provide its own browser, the 
natural default for a cygwin user is the default windows browser.  What 
I think is wrong (and easy to fix) is that 
browse-url-default-windows-browser doesn't do the right thing on cygwin.

Ken




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 18:02   ` Ken Brown
@ 2009-06-17 21:30     ` Ken Brown
  2009-06-17 21:44       ` Chong Yidong
  0 siblings, 1 reply; 9+ messages in thread
From: Ken Brown @ 2009-06-17 21:30 UTC (permalink / raw)
  To: Jason Rumney; +Cc: Emacs

[-- Attachment #1: Type: text/plain, Size: 812 bytes --]

On 6/17/2009 2:02 PM, Ken Brown wrote:
> On 6/17/2009 12:06 PM, Jason Rumney wrote:
>> Ken Brown wrote:
>>> In browse-url.el, browse-url-browser-function is set to 
>>> browse-url-default-windows-browser on cygwin.
>> That is wrong, feel free to change it to a better default.
> 
> I don't agree.  Since cygwin doesn't provide its own browser, the 
> natural default for a cygwin user is the default windows browser.  What 
> I think is wrong (and easy to fix) is that 
> browse-url-default-windows-browser doesn't do the right thing on cygwin.

To focus the discussion more, let me propose the attached patch.  The 
second hunk fixes what I believe to be a bug in 
browse-url-default-windows-browser.  The first hunk is uglier in the way 
it makes cygwin a special case.  Is there a better way to do this?

Ken

[-- Attachment #2: browse-url.patch --]
[-- Type: text/plain, Size: 1364 bytes --]

--- browse-url.el.orig	2009-01-06 15:29:22.000000000 -0500
+++ browse-url.el	2009-06-17 17:24:02.644422200 -0400
@@ -693,7 +693,9 @@
 	  (cond ((not (buffer-modified-p)))
 		(browse-url-save-file (save-buffer))
 		(t (message "%s modified since last save" file))))))
-  (browse-url (browse-url-file-url file))
+  (if (eq system-type 'cygwin)
+      (shell-command (concat "cygstart " (shell-quote-argument file)))
+    (browse-url (browse-url-file-url file)))
   (run-hooks 'browse-url-of-file-hook))
 
 (defun browse-url-file-url (file)
@@ -827,11 +829,13 @@
 
 (defun browse-url-default-windows-browser (url &optional new-window)
   (interactive (browse-url-interactive-arg "URL: "))
-  (if (eq system-type 'ms-dos)
-      (if dos-windows-version
-	  (shell-command (concat "start " (shell-quote-argument url)))
-	(error "Browsing URLs is not supported on this system"))
-    (w32-shell-execute "open" url)))
+  (cond ((eq system-type 'ms-dos)
+	 (if dos-windows-version
+	     (shell-command (concat "start " (shell-quote-argument url)))
+	   (error "Browsing URLs is not supported on this system")))
+	((eq system-type 'cygwin)
+	 (shell-command (concat "cygstart " (shell-quote-argument url))))
+	(t (w32-shell-execute "open" url))))
 
 (defun browse-url-default-macosx-browser (url &optional new-window)
   (interactive (browse-url-interactive-arg "URL: "))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 21:30     ` Ken Brown
@ 2009-06-17 21:44       ` Chong Yidong
  2009-06-18  1:29         ` Ken Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Chong Yidong @ 2009-06-17 21:44 UTC (permalink / raw)
  To: Ken Brown; +Cc: Emacs, Jason Rumney

Ken Brown <kbrown@cornell.edu> writes:

> -  (browse-url (browse-url-file-url file))
> +  (if (eq system-type 'cygwin)
> +      (shell-command (concat "cygstart " (shell-quote-argument file)))
> +    (browse-url (browse-url-file-url file)))
>
> Is there a better way to do this?

The better way is probably to change browse-url-default-browser (BTW,
this is all post-23.1).




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 16:06 ` Jason Rumney
  2009-06-17 16:14   ` Ken Brown
  2009-06-17 18:02   ` Ken Brown
@ 2009-06-17 22:23   ` David Robinow
  2009-06-18 12:46     ` Ken Brown
  2 siblings, 1 reply; 9+ messages in thread
From: David Robinow @ 2009-06-17 22:23 UTC (permalink / raw)
  To: Jason Rumney; +Cc: Ken Brown, Emacs

On Wed, Jun 17, 2009 at 12:06 PM, Jason Rumney<jasonr@gnu.org> wrote:
> Ken Brown wrote:
...
>>  (browse-url-file-url "/home/kbrown/html/index.html")
>>
>> yields "file:/home/kbrown/html/index.html", but (on my system) it would
>> need to be "file://d:/cygwin-1.7/home/kbrown/html/index.html" for the
>> windows browser to be able to handle it.
>
> That is a general problem with cygwin interacting with non-cygwin programs.
> Cygwin invents its own virtual filesystem that is not understood outside of
> cygwin. See the problems the native build of Emacs faces with Cygwin make. I
> don't see how bypassing browse-url fixes this for you, as the path will
> still be one that Windows does not recognize.

This is a somewhat different problem since in this case Emacs is a
cygwin program.
  cygpath -m  /home/kbrown/html/index.html
will return a suitable windows name
(c:/cygwin17/kbrown/html/index.html  on my system)

It should be relatively simple to incorporate that transformation
directly into a cygwin-specific function. I did something similar for
cygwin make some years ago to get it to build windows emacs.
I'll see if I can find the code. It's been a while.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 21:44       ` Chong Yidong
@ 2009-06-18  1:29         ` Ken Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Ken Brown @ 2009-06-18  1:29 UTC (permalink / raw)
  To: Chong Yidong; +Cc: Emacs, Jason Rumney

On 6/17/2009 5:44 PM, Chong Yidong wrote:
> Ken Brown <kbrown@cornell.edu> writes:
> 
>> -  (browse-url (browse-url-file-url file))
>> +  (if (eq system-type 'cygwin)
>> +      (shell-command (concat "cygstart " (shell-quote-argument file)))
>> +    (browse-url (browse-url-file-url file)))
>>
>> Is there a better way to do this?
> 
> The better way is probably to change browse-url-default-browser

I'm not sure I understand.  I already have a good way of asking a 
browser to load a URL via browse-url-default-windows-browser (as I 
patched it).  The issue here is that browse-url-file-url doesn't return 
a suitable URL.  Or am I misunderstanding you?

> (BTW, this is all post-23.1).

Yes, I wasn't expecting anything else.

Ken





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: browse-url/w32-shell-execute problems on cygwin
  2009-06-17 22:23   ` David Robinow
@ 2009-06-18 12:46     ` Ken Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Ken Brown @ 2009-06-18 12:46 UTC (permalink / raw)
  To: David Robinow; +Cc: Emacs, Jason Rumney

On 6/17/2009 6:23 PM, David Robinow wrote:
> On Wed, Jun 17, 2009 at 12:06 PM, Jason Rumney<jasonr@gnu.org> wrote:
>> Ken Brown wrote:
> ...
>>>  (browse-url-file-url "/home/kbrown/html/index.html")
>>>
>>> yields "file:/home/kbrown/html/index.html", but (on my system) it would
>>> need to be "file://d:/cygwin-1.7/home/kbrown/html/index.html" for the
>>> windows browser to be able to handle it.
>> That is a general problem with cygwin interacting with non-cygwin programs.
>> Cygwin invents its own virtual filesystem that is not understood outside of
>> cygwin. See the problems the native build of Emacs faces with Cygwin make. I
>> don't see how bypassing browse-url fixes this for you, as the path will
>> still be one that Windows does not recognize.
> 
> This is a somewhat different problem since in this case Emacs is a
> cygwin program.
>   cygpath -m  /home/kbrown/html/index.html
> will return a suitable windows name
> (c:/cygwin17/kbrown/html/index.html  on my system)
> 
> It should be relatively simple to incorporate that transformation
> directly into a cygwin-specific function. I did something similar for
> cygwin make some years ago to get it to build windows emacs.
> I'll see if I can find the code. It's been a while.

Thanks for the offer, David, but don't go to any trouble.  I know that I 
could use cygpath to fix browse-url-file-url, but that would require 
special-casing cygwin in browse-url-file-url.  The simpler solution 
using cygstart that I proposed instead does the special-casing in 
browse-url-of-file.  But I don't know if the emacs developers would 
accept a patch with that sort of special-casing in either place.  If so, 
I'll do it however they want.

Ken





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-06-18 12:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-17 15:47 browse-url/w32-shell-execute problems on cygwin Ken Brown
2009-06-17 16:06 ` Jason Rumney
2009-06-17 16:14   ` Ken Brown
2009-06-17 18:02   ` Ken Brown
2009-06-17 21:30     ` Ken Brown
2009-06-17 21:44       ` Chong Yidong
2009-06-18  1:29         ` Ken Brown
2009-06-17 22:23   ` David Robinow
2009-06-18 12:46     ` Ken Brown

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.