delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/06/16/06:50:01

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,SPF_NEUTRAL
X-Spam-Check-By: sourceware.org
Message-ID: <4A3778AA.6060206@cornell.edu>
Date: Tue, 16 Jun 2009 06:49:14 -0400
From: Ken Brown <kbrown AT cornell DOT edu>
User-Agent: Thunderbird 2.0.0.21 (Windows/20090302)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: w32-shell-execute function definition is void
References: <fb34b27b0606051002y5ae8f1b4ydbbf71fa47c961ce AT mail DOT gmail DOT com> <24049941 DOT post AT talk DOT nabble DOT com>
In-Reply-To: <24049941.post@talk.nabble.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 6/16/2009 4:36 AM, Marc Girod wrote:
> 
> Mark Fisher-4 wrote:
>> i cannot seem to be able to use/find w32-shell-execute.
>>
> Same thing on 23.0.92
> The error comes e.g. as I do: M-x browse-url
> 
> I can find the function definition in the C sources: src/w32fns.c
> but I remember that this object is not linked to the cygwin emacs.
> 
> So, there ought to be a replacement for these functions, and a 
> test to switch to an alternative set of them?

I haven't tried to write a full-blown replacement, but the following 
works for me.  First, in my .emacs, I have:

;;; System dependent settings
(cond
  ((eq system-type 'cygwin) (load "cygwin-init"))
  ((eq system-type 'windows-nt) (load "nt-init"))
  ((eq system-type 'gnu/linux) (load "linux-init")))

Now in my cygwin-init.el I define a simple-minded version of 
w32-shell-execute that suffices for my purposes:

;; 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)))))

Finally, still in cygwin-init.el, I slightly modify browse-url-of-file:

;; browse-url-of-file doesn't work right under cygwin; I'll just open
;; the file using cygstart instead of trying to convert the filename
;; to a URL.
(require 'browse-url)
(defun browse-url-of-file (&optional file)
   "Ask a WWW browser to display FILE.
Display the current buffer's file if FILE is nil or if called
interactively.  Turn the filename into a URL with function
`browse-url-file-url'.  Pass the URL to a browser using the
`browse-url' function then run `browse-url-of-file-hook'."
   (interactive)
   (or file
       (setq file (buffer-file-name))
       (error "Current buffer has no file"))
   (let ((buf (get-file-buffer file)))
     (if buf
	(save-excursion
	  (set-buffer buf)
	  (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))
   (w32-shell-execute "open" file)
   (run-hooks 'browse-url-of-file-hook))

I'm sure there are better ways to do this, but the above is easy and has 
worked for me for years.  If Eli is watching this thread, maybe he can 
suggest something better that could be submitted as a patch to the emacs 
developers.

Ken

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019