annotate lisp/efs/dired-vir.el @ 22:8fc7fe29b841 r19-15b94

Import from CVS: tag r19-15b94
author cvs
date Mon, 13 Aug 2007 08:50:29 +0200
parents
children 7e54bd776075 9f59509498e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;; -*-Emacs-Lisp-*-
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4 ;; File: dired-vir.el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; Dired Version: $Revision: 1.1 $
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; Description: Virtual dired mode for browsing ls -lR listings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; Created: 7-Mar-1991 16:00
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;;; Requirements and provisions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 (provide 'dired-vir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 (require 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 (defun dired-virtual (dirname &optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 "Put this buffer into Virtual Dired mode.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 In Virtual Dired mode, all commands that do not actually consult the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 filesystem will work.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 This is useful if you want to peruse and move around in an ls -lR
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 output file, for example one you got from an ftp server. With
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 efs, you can even dired a directory containing an ls-lR file,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 visit that file and turn on virtual dired mode. But don't try to save
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 this file, as dired-virtual indents the listing and thus changes the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 If you have save a Dired buffer in a file you can use \\[dired-virtual] to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 resume it in a later session.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 Type \\<dired-mode-map>\\[revert-buffer] in the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 Virtual Dired buffer and answer `y' to convert the virtual to a real
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 dired buffer again. You don't have to do this, though: you can relist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 single subdirs using \\[dired-do-redisplay].
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 ;; DIRNAME is the top level directory of the buffer. It will become
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 ;; its `default-directory'. If nil, the old value of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 ;; default-directory is used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 ;; Optional SWITCHES are the ls switches to use.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 ;; Shell wildcards will be used if there already is a `wildcard'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 ;; line in the buffer (thus it is a saved Dired buffer), but there
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 ;; is no other way to get wildcards. Insert a `wildcard' line by
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 ;; hand if you want them.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 (list (read-string "Virtual Dired directory: " (dired-virtual-guess-dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (or (looking-at " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 ;; if not already indented, do it now:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 (indent-region (point-min) (point-max) 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 (or dirname (setq dirname default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 (setq dirname (expand-file-name (file-name-as-directory dirname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 (setq default-directory dirname) ; contains no wildcards
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 (let ((wildcard (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (forward-line 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 (and (looking-at "^ wildcard ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 (buffer-substring (match-end 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 (progn (end-of-line) (point)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 (if wildcard
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (setq dirname (expand-file-name wildcard default-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 ;; If raw ls listing (not a saved old dired buffer), give it a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 ;; decent subdir headerline:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 (or (looking-at dired-subdir-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 (dired-insert-headerline default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (dired-mode dirname (or switches dired-listing-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 (setq mode-name "Virtual Dired"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 revert-buffer-function 'dired-virtual-revert)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (set (make-local-variable 'dired-subdir-alist) nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 (dired-build-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (dired-initial-position dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (defun dired-virtual-guess-dir ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 ;; Guess and return appropriate working directory of this buffer,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 ;; assumed to be in Dired or ls -lR format.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 ;; The guess is based upon buffer contents.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 ;; If nothing could be guessed, returns nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (let ((regexp "^\\( \\)?\\([^ \n\r]*\\)\\(:\\)[\n\r]")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (subexpr 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (cond ((looking-at regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 ;; If a saved dired buffer, look to which dir and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 ;; perhaps wildcard it belongs:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (let ((dir (buffer-substring (match-beginning subexpr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 (match-end subexpr))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (file-name-as-directory dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 ;; Else no match for headerline found. It's a raw ls listing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 ;; In raw ls listings the directory does not have a headerline
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 ;; try parent of first subdir, if any
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 ((re-search-forward regexp nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (file-name-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 (directory-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 (file-name-as-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (buffer-substring (match-beginning subexpr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (match-end subexpr))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 (t ; if all else fails
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 (defun dired-virtual-revert (&optional arg noconfirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 (if (not
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (y-or-n-p "Cannot revert a Virtual Dired buffer - switch to Real Dired mode? "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (error "Cannot revert a Virtual Dired buffer.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (setq mode-name "Dired"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 revert-buffer-function 'dired-revert)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (revert-buffer)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 ;; A zero-arg version of dired-virtual.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 ;; You need my modified version of set-auto-mode for the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 ;; `buffer-contents-mode-alist'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 ;; Or you use infer-mode.el and infer-mode-alist, same syntax.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 (defun dired-virtual-mode ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 "Put current buffer into virtual dired mode (see `dired-virtual').
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 Useful on `buffer-contents-mode-alist' (which see) with the regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 \"^ \\(/[^ /]+\\)/?+:$\"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 to put saved dired buffers automatically into virtual dired mode.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 Also useful for `auto-mode-alist' (which see) like this:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 \(setq auto-mode-alist (cons '(\"[^/]\\.dired$\" . dired-virtual-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 auto-mode-alist)\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 (dired-virtual (dired-virtual-guess-dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 ;;; end of dired-vir.el