This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: w32-shell-execute function definition is void


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]