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