*** empty log message ***
[bpt/emacs.git] / lisp / url / url-dired.el
1 ;;; url-dired.el --- URL Dired minor mode
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Keywords: comm, files
7
8 ;; This file is part of GNU Emacs.
9
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 3, or (at your option)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Code:
26
27 (autoload 'dired-get-filename "dired")
28
29 (defvar url-dired-minor-mode-map
30 (let ((map (make-sparse-keymap)))
31 (define-key map "\C-m" 'url-dired-find-file)
32 (define-key map [mouse-2] 'url-dired-find-file-mouse)
33 map)
34 "Keymap used when browsing directories.")
35
36 (defvar url-dired-minor-mode nil
37 "Whether we are in url-dired-minor-mode")
38
39 (make-variable-buffer-local 'url-dired-minor-mode)
40
41 (defun url-dired-find-file ()
42 "In dired, visit the file or directory named on this line."
43 (interactive)
44 (let ((filename (dired-get-filename)))
45 (find-file filename)))
46
47 (defun url-dired-find-file-mouse (event)
48 "In dired, visit the file or directory name you click on."
49 (interactive "@e")
50 (mouse-set-point event)
51 (url-dired-find-file))
52
53 (defun url-dired-minor-mode (&optional arg)
54 "Minor mode for directory browsing."
55 (interactive "P")
56 (cond
57 ((null arg)
58 (setq url-dired-minor-mode (not url-dired-minor-mode)))
59 ((equal 0 arg)
60 (setq url-dired-minor-mode nil))
61 (t
62 (setq url-dired-minor-mode t))))
63
64 (if (not (fboundp 'add-minor-mode))
65 (defun add-minor-mode (toggle name &optional keymap after toggle-fun)
66 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
67 TOGGLE is a symbol which is used as the variable which toggle the minor mode,
68 NAME is the name that should appear in the modeline (it should be a string
69 beginning with a space), KEYMAP is a keymap to make active when the minor
70 mode is active, and AFTER is the toggling symbol used for another minor
71 mode. If AFTER is non-nil, then it is used to position the new mode in the
72 minor-mode alists. TOGGLE-FUN specifies an interactive function that
73 is called to toggle the mode on and off; this affects what appens when
74 button2 is pressed on the mode, and when button3 is pressed somewhere
75 in the list of modes. If TOGGLE-FUN is nil and TOGGLE names an
76 interactive function, TOGGLE is used as the toggle function.
77
78 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)"
79 (if (not (assq toggle minor-mode-alist))
80 (setq minor-mode-alist (cons (list toggle name) minor-mode-alist)))
81 (if (and keymap (not (assq toggle minor-mode-map-alist)))
82 (setq minor-mode-map-alist (cons (cons toggle keymap)
83 minor-mode-map-alist)))))
84
85 (add-minor-mode 'url-dired-minor-mode " URL" url-dired-minor-mode-map)
86
87 (defun url-find-file-dired (dir)
88 "\"Edit\" directory DIR, but with additional URL-friendly bindings."
89 (interactive "DURL Dired (directory): ")
90 (find-file dir)
91 (url-dired-minor-mode t))
92
93 (provide 'url-dired)
94
95 ;;; arch-tag: 2694f21a-43e1-4391-b3cb-cf6e5349f15f
96 ;;; url-dired.el ends here