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