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