1;;; w32-browser.el --- Run Windows application associated with a file.
3;; Filename: w32-browser.el
4;; Description: Run Windows application associated with a file.
5;; Author: Emacs Wiki, Drew Adams
6;; Maintainer: Drew Adams
7;; Copyright (C) 2004-2007, Drew Adams, all rights reserved.
8;; Created: Thu Mar 11 13:40:52 2004
10;; Last-Updated: Fri Jan 19 21:32:40 2007 (-28800 Pacific Standard Time)
13;; URL: http://www.emacswiki.org/cgi-bin/wiki/w32-browser.el
14;; Keywords: mouse, dired, w32, explorer
15;; Compatibility: GNU Emacs 20.x, GNU Emacs 21.x, GNU Emacs 22.x
17;; Features that might be required by this library:
19;; `avoid', `cl', `custom', `dired', `dired+', `dired-aux',
20;; `dired-x', `easymenu', `ediff-diff', `ediff-help', `ediff-init',
21;; `ediff-merg', `ediff-mult', `ediff-util', `ediff-wind',
22;; `fit-frame', `frame-cmds', `frame-fns', `info', `info+',
23;; `misc-fns', `mkhtml', `mkhtml-htmlize', `strings', `thingatpt',
26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30;; Run Windows application associated with a file.
32;; `w32-browser' & `dired-w32-browser' are from the Emacs Wiki.
34;; I modified `w32-browser' to `find-file' if it cannot
35;; `w32-shell-execute'. I modified `dired-multiple-w32-browser' to
36;; use `w32-browser-wait-time'. I wrote `dired-mouse-w32-browser'.
38;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43;; Added: w32-browser-wait-time, soft require of dired+.el.
44;; Uncommented and updated dired-multiple-w32-browser and its binding.
45;; Thanks to Mathias Dahl [brakjoller@gmail.com] for recognizing this actually works.
46;; Conditionalized dired+ vs standard dired in bindings.
48;; Renamed menu-bar-dired-immediate-menu to diredp-menu-bar-immediate-menu.
50;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52;; This program is free software; you can redistribute it and/or modify
53;; it under the terms of the GNU General Public License as published by
54;; the Free Software Foundation; either version 2, or (at your option)
57;; This program is distributed in the hope that it will be useful,
58;; but WITHOUT ANY WARRANTY; without even the implied warranty of
59;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60;; GNU General Public License for more details.
62;; You should have received a copy of the GNU General Public License
63;; along with this program; see the file COPYING. If not, write to
64;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
65;; Floor, Boston, MA 02110-1301, USA.
67;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71(require 'dired+ nil t) ;; diredp-menu-bar-immediate-menu, diredp-menu-bar-operate-menu
75(when (eq system-type 'windows-nt)
77 (defcustom w32-browser-wait-time 0.1
78 "*Delay to wait between `w32-browser' in `dired-multiple-w32-browser'.
79On at least some Windows systems, this delay is needed between calls
80to `w32-browser' within command `dired-multiple-w32-browser'.
81Depending on your system, you might be able to set this to 0, meaning
83 :type 'integer :group 'convenience)
85 (defun w32-browser (file)
86 "Run default Windows application associated with FILE.
87If no associated application, then `find-file' FILE."
88 (or (condition-case nil
89 (w32-shell-execute nil file) ; Use Windows file association
91 (find-file file))) ; E.g. no Windows file association
93 (defun dired-w32-browser ()
94 "Run default Windows application associated with current line's file.
95If file is a directory, then `dired-find-file' instead.
96If no application is associated with file, then `find-file'."
98 (let ((file (dired-get-filename)))
99 (if (file-directory-p file)
101 (w32-browser (dired-replace-in-string "/" "\\" file)))))
103 (defun dired-mouse-w32-browser (event)
104 "Run default Windows application associated with file under mouse click.
105If file is a directory or no application is associated with file, then
110 (set-buffer (window-buffer (posn-window (event-end event))))
112 (goto-char (posn-point (event-end event)))
113 (setq file (dired-get-filename))))
114 (select-window (posn-window (event-end event)))
115 (if (file-directory-p file)
116 (find-file (file-name-sans-versions file t))
117 (w32-browser (file-name-sans-versions file t)))))
119 (defun dired-multiple-w32-browser ()
120 "Run default Windows applications associated with marked files."
122 (let ((files (dired-get-marked-files)))
124 (w32-browser (car files))
125 (sleep-for w32-browser-wait-time)
126 (setq files (cdr files)))))
128 (if (boundp 'diredp-menu-bar-immediate-menu) ; Use Dired+ if loaded.
129 (eval-after-load "dired+"
131 (define-key dired-mode-map [f3] 'dired-w32-browser)
132 (define-key diredp-menu-bar-immediate-menu [dired-w32-browser]
133 '("Open Associated Application" . dired-w32-browser))
134 (define-key dired-mode-map [mouse-2] 'dired-mouse-w32-browser)
135 (define-key diredp-menu-bar-operate-menu [dired-w32-browser]
136 '("Open Associated Applications" . dired-multiple-w32-browser))))
137 (eval-after-load "dired"
139 (define-key dired-mode-map [f3] 'dired-w32-browser)
140 (define-key dired-mode-map [menu-bar immediate dired-w32-browser]
141 '("Open Associated Application" . dired-w32-browser))
142 (define-key dired-mode-map [mouse-2] 'dired-mouse-w32-browser)
143 (define-key dired-mode-map [menu-bar immediate dired-w32-browser]
144 '("Open Associated Applications" . dired-multiple-w32-browser))))))
148(provide 'w32-browser)
150;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151;;; w32-browser.el ends here