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