Resolve CVS conflicts
[bpt/emacs.git] / lisp / url / url-dired.el
CommitLineData
8c8b8430 1;;; url-dired.el --- URL Dired minor mode
e5566bd5
MB
2;; Author: $Author: monnier $
3;; Created: $Date: 2004/04/04 01:21:46 $
4;; Version: $Revision: 1.1.1.1 $
8c8b8430
SM
5;; Keywords: comm, files
6
7;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8;;; Copyright (c) 1993 - 1996 by William M. Perry <wmperry@cs.indiana.edu>
9;;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc.
10;;;
11;;; This file is part of GNU Emacs.
12;;;
13;;; GNU Emacs is free software; you can redistribute it and/or modify
14;;; it under the terms of the GNU General Public License as published by
15;;; the Free Software Foundation; either version 2, or (at your option)
16;;; any later version.
17;;;
18;;; GNU Emacs is distributed in the hope that it will be useful,
19;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;;; GNU General Public License for more details.
22;;;
23;;; You should have received a copy of the GNU General Public License
24;;; along with GNU Emacs; see the file COPYING. If not, write to the
25;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26;;; Boston, MA 02111-1307, USA.
27;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28
29(autoload 'w3-fetch "w3")
30(autoload 'w3-open-local "w3")
31(autoload 'dired-get-filename "dired")
32
33(defvar url-dired-minor-mode-map
34 (let ((map (make-sparse-keymap)))
35 (define-key map "\C-m" 'url-dired-find-file)
36 (if (featurep 'xemacs)
37 (define-key map [button2] 'url-dired-find-file-mouse)
38 (define-key map [mouse-2] 'url-dired-find-file-mouse))
39 map)
40 "Keymap used when browsing directories.")
41
42(defvar url-dired-minor-mode nil
43 "Whether we are in url-dired-minor-mode")
44
45(make-variable-buffer-local 'url-dired-minor-mode)
46
47(defun url-dired-find-file ()
48 "In dired, visit the file or directory named on this line, using Emacs-W3."
49 (interactive)
50 (let ((filename (dired-get-filename)))
51 (cond ((string-match "/\\(.*@.*\\):\\(/.*\\)" filename)
52 (w3-fetch (concat "file://" (match-string 1 filename) (match-string 2 filename))))
53 (t
54 (w3-open-local filename)))))
55
56(defun url-dired-find-file-mouse (event)
57 "In dired, visit the file or directory name you click on, using Emacs-W3."
58 (interactive "@e")
59 (mouse-set-point event)
60 (url-dired-find-file))
61
62(defun url-dired-minor-mode (&optional arg)
63 "Minor mode for directory browsing with Emacs-W3."
64 (interactive "P")
65 (cond
66 ((null arg)
67 (setq url-dired-minor-mode (not url-dired-minor-mode)))
68 ((equal 0 arg)
69 (setq url-dired-minor-mode nil))
70 (t
71 (setq url-dired-minor-mode t))))
72
73(if (not (fboundp 'add-minor-mode))
74 (defun add-minor-mode (toggle name &optional keymap after toggle-fun)
75 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
76TOGGLE is a symbol which is used as the variable which toggle the minor mode,
77NAME is the name that should appear in the modeline (it should be a string
78beginning with a space), KEYMAP is a keymap to make active when the minor
79mode is active, and AFTER is the toggling symbol used for another minor
80mode. If AFTER is non-nil, then it is used to position the new mode in the
81minor-mode alists. TOGGLE-FUN specifies an interactive function that
82is called to toggle the mode on and off; this affects what appens when
83button2 is pressed on the mode, and when button3 is pressed somewhere
84in the list of modes. If TOGGLE-FUN is nil and TOGGLE names an
85interactive function, TOGGLE is used as the toggle function.
86
87Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)"
88 (if (not (assq toggle minor-mode-alist))
89 (setq minor-mode-alist (cons (list toggle name) minor-mode-alist)))
90 (if (and keymap (not (assq toggle minor-mode-map-alist)))
91 (setq minor-mode-map-alist (cons (cons toggle keymap)
92 minor-mode-map-alist)))))
93
94(add-minor-mode 'url-dired-minor-mode " URL" url-dired-minor-mode-map)
95
96(defun url-find-file-dired (dir)
97 "\"Edit\" directory DIR, but with additional URL-friendly bindings."
98 (interactive "DURL Dired (directory): ")
99 (find-file dir)
100 (url-dired-minor-mode t))
101
102(provide 'url-dired)
e5566bd5
MB
103
104;;; arch-tag: 2694f21a-43e1-4391-b3cb-cf6e5349f15f