annotate lisp/dired/dired-x.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; dired-x.el --- Sebastian Kremer's Extra DIRED hacked up for GNU Emacs19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Keywords: dired extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 (defconst dired-extra-version (substring "!Revision: 1.191 !" 11 -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 "Id: dired-x.el,v 1.191 1992/05/14 11:41:54 sk RelBeta ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Copyright (C) 1991 Sebastian Kremer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; LISPDIR ENTRY for the Elisp Archive ===============================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; dired-x|Sebastian Kremer|sk@thp.uni-koeln.de
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; |Extra Features for Tree Dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; |Date: 1992/05/14 11:41:54 |Revision: 1.191 |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; INSTALLATION ======================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; In your ~/.emacs, say
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; (setq dired-load-hook '(lambda () (load "dired-x")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; At load time dired-x will install itself using the various other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; dired hooks. It will redefine some functions and bind dired keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; If gmhist is present, dired-x will take advantage of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (require 'dired) ; we will redefine some functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ; and also need some macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (provide 'dired-extra) ; but this file is "dired-x"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (provide 'dired-x) ; but this file is "dired-x"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; Customization (see also defvars in other sections below)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; user should define this as `nil' prior to loading dired-x in order that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; compression/decompression material of emacs19 is not overwritten.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defvar dired-mark-keys '("Z")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "*List of keys (strings) that insert themselves as file markers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defvar dired-dangerous-shell-command "^rm" ; e.g. "rm" or "rmdir"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "*Regexp for dangerous shell commands that should never be the default.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; Add key bindings. This file is supposed to be loaded immediately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; after dired, inside dired-load-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (define-key dired-mode-map "V" 'dired-vm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (define-key dired-mode-map "\(" 'dired-set-marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (define-key dired-mode-map "\)" 'dired-restore-marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (define-key dired-mode-map "I" 'dired-do-insert-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;(define-key dired-mode-map "\M-f" 'dired-flag-extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (define-key dired-mode-map "\M-M" 'dired-do-unmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (define-key dired-mode-map "\M-o" 'dired-omit-toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (define-key dired-mode-map "\M-(" 'dired-mark-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (define-key dired-mode-map "," 'dired-mark-rcs-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (define-key dired-mode-map "\M-!" 'dired-smart-shell-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (define-key dired-mode-map "\M-&" 'dired-smart-background-shell-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (define-key dired-mode-map "T" 'dired-do-toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (define-key dired-mode-map "w" 'dired-copy-filename-as-kill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (define-key dired-mode-map "\M-g" 'dired-goto-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (define-key dired-mode-map "\M-G" 'dired-goto-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (define-key dired-mode-map "&" 'dired-do-background-shell-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (define-key dired-mode-map "A" 'dired-do-byte-compile-and-load)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (define-key dired-mode-map "F" 'dired-do-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (define-key dired-mode-map "S" 'dired-do-relsymlink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (define-key dired-mode-map "%S" 'dired-do-relsymlink-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (mapcar (function;; do this last to override bindings above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (define-key dired-mode-map x 'dired-mark-with-this-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 dired-mark-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; Install ourselves into the appropriate hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun dired-add-hook (hook-var function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Add a function to a hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 First argument HOOK-VAR (a symbol) is the name of a hook, second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 argument FUNCTION is the function to add.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Returns nil if FUNCTION was already present in HOOK-VAR, else new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 value of HOOK-VAR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (interactive "SAdd to hook-var (symbol): \naAdd which function to %s? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if (not (boundp hook-var)) (set hook-var nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (if (or (not (listp (symbol-value hook-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (eq (car (symbol-value hook-var)) 'lambda))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (set hook-var (list (symbol-value hook-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (if (memq function (symbol-value hook-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (set hook-var (cons function (symbol-value hook-var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (dired-add-hook 'dired-mode-hook 'dired-extra-startup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (dired-add-hook 'dired-after-readin-hook 'dired-omit-expunge)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defvar dired-default-marker dired-marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "*The value of `dired-marker-char' in effect before dired-x was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 loaded and the value which is restored if the marker stack underflows.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 This is usually the asterisk `*'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (defun dired-extra-startup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 "Automatically put on dired-mode-hook to get extra dired features:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 \\<dired-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 \\[dired-vm]\t-- VM on folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 \\[dired-rmail]\t-- Rmail on folder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 \\[dired-do-insert-subdir]\t-- insert all marked subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 \\[dired-do-find-file]\t-- visit all marked files simultaneously
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 \\[dired-set-marker-char], \\[dired-restore-marker-char]\t-- change and display dired-marker-char dynamically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 \\[dired-omit-toggle]\t-- toggle omitting of files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 \\[dired-mark-sexp]\t-- mark by lisp expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 \\[dired-do-unmark]\t-- replace existing marker with another.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 \\[dired-mark-rcs-files]\t-- mark all RCS controlled files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 \\[dired-mark-files-compilation-buffer]\t-- mark compilation files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 \\[dired-copy-filename-as-kill]\t-- copy the file or subdir names into the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 \t You can feed it to other commands using \\[yank].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 For more features, see variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 dired-omit-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 dired-omit-extenstions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 dired-dangerous-shell-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 dired-mark-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 dired-local-variables-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 dired-find-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 dired-guess-have-gnutar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 dired-auto-shell-command-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 See also functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 dired-sort-on-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 dired-do-relsymlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 dired-flag-extension
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 dired-virtual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 dired-jump-back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 dired-jump-back-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; This must be done in each new dired buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (dired-hack-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (dired-omit-startup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (dired-marker-stack-startup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;; Handle customization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (or (fboundp 'read-with-history-in) ; it's loaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (not (subrp (symbol-function 'read-from-minibuffer))) ; it's 19.4L
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; else try to load gmhist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (load "gmhist" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (if (not (fboundp 'read-with-history-in))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 nil ; Gmhist is not available
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; Else use generic minibuffer history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (put 'dired-shell-command-history 'dangerous dired-dangerous-shell-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; Redefinition - when this is loaded, dired.el has alreay been loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defun dired-read-regexp (prompt &optional initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq dired-flagging-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (if (null initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (read-with-history-in 'regexp-history prompt initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (put 'regexp-history 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (put 'regexp-history 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (read-with-history-in 'regexp-history prompt initial)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defun dired-read-dir-and-switches (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (nreverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (read-string "Dired listing switches: " dired-listing-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (read-file-name-with-history-in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 'file-history ; or 'dired-history?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (format "Dired %s(directory): " str) nil default-directory nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;; Dynamic Markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun dired-mark-with-this-char (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "Mark the current file or subdir with the last key you pressed to invoke
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 this command. Else like \\[dired-mark-subdir-or-file] command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (let ((dired-marker-char;; use last character, in case of prefix cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 last-command-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (dired-mark-subdir-or-file arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (defvar dired-marker-stack nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "List of previously used dired marker characters.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defvar dired-marker-string ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 "String version of `dired-marker-stack'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defun dired-current-marker-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "Computes and returns `dired-marker-string'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (setq dired-marker-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (concat " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (mapconcat (function char-to-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (reverse dired-marker-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defun dired-marker-stack-startup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (make-local-variable 'dired-marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (make-local-variable 'dired-del-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (make-local-variable 'dired-marker-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (or (assq 'dired-marker-stack minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (cons '(dired-marker-stack dired-marker-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 minor-mode-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (defun dired-set-marker-char (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 "Set the marker character to something else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 Use \\[dired-restore-marker-char] to restore the previous value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (interactive "cNew marker character: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (setq dired-marker-stack (cons c dired-marker-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (dired-current-marker-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq dired-marker-char c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (set-buffer-modified-p (buffer-modified-p)) ; update mode line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (message "New marker is %c" dired-marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defun dired-restore-marker-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Restore the marker character to its previous value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 Uses `dired-default-marker' if the marker stack is empty."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq dired-marker-stack (cdr dired-marker-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 dired-marker-char (car dired-marker-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (dired-current-marker-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (set-buffer-modified-p (buffer-modified-p)) ; update mode line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (or dired-marker-char (setq dired-marker-char dired-default-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (message "Marker is %c" dired-marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;;; Sort on Size kludge if your ls can't do it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defun dired-sort-on-size ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "Sorts a dired listing on file size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 If your ls cannot sort on size, this is useful as `dired-after-readin-hook':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 \(setq dired-after-readin-hook 'dired-sort-on-size\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (require 'sort)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (dired-goto-next-file) ; skip `total' line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (sort-subr t ; biggest file first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 'forward-line 'end-of-line 'dired-get-file-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (defun dired-get-file-size ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (re-search-forward "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (string-to-int (buffer-substring (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (backward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;;; Misc. (mostly featurismic) commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; Mail folders
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (defvar dired-vm-read-only-folders nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 "*If t, \\[dired-vm] will visit all folders read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 If neither nil nor t, e.g. the symbol `if-file-read-only', only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 files not writable by you are visited read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 Read-only folders only work in VM 5, not in VM 4.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defun dired-vm (&optional read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 "Run VM on this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 With prefix arg, visit folder read-only (this requires at least VM 5).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 See also variable `dired-vm-read-only-folders'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (let ((dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (fil (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; take care to supply 2nd arg only if requested - may still run VM 4!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (cond (read-only (vm-visit-folder fil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ((eq t dired-vm-read-only-folders) (vm-visit-folder fil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ((null dired-vm-read-only-folders) (vm-visit-folder fil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (t (vm-visit-folder fil (not (file-writable-p fil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; so that pressing `v' inside VM does prompt within current directory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (set (make-local-variable 'vm-folder-directory) dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (defun dired-rmail ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 "Run RMAIL on this file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (rmail (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;; More subdir operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun dired-do-insert-subdir ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "Insert all marked subdirectories in situ that are not yet inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 Non-directories are silently ignored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (let ((files (or (dired-mark-get-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (error "No files marked."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (while files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (if (file-directory-p (car files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (save-excursion (dired-maybe-insert-subdir (car files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (setq files (cdr files)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (defun dired-mark-extension (extension &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 "Mark all files with a certain extension for use in later commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 A `.' is not automatically prepended to the string entered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;; EXTENSION may also be a list of extensions instead of a single one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;; Optional MARKER-CHAR is marker to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (interactive "sMarking extension: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (or (listp extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq extension (list extension)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (dired-mark-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (concat ".";; don't match names with nothing but an extension
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (mapconcat 'regexp-quote extension "\\|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 "\\)$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (defun dired-flag-extension (extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 "In dired, flag all files with a certain extension for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 A `.' is *not* automatically prepended to the string entered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (interactive "sFlagging extension: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (dired-mark-extension extension dired-del-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (defvar patch-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 '(".rej" ".orig")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 "List of extensions of dispensable files created by the `patch' program.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (defvar tex-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 '(".toc" ".log" ".aux");; these are already in completion-ignored-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 "List of extensions of dispensable files created by TeX.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defvar latex-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 '(".idx" ".lof" ".lot" ".glo")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 "List of extensions of dispensable files created by LaTeX.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (defvar bibtex-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 '(".blg" ".bbl")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 "List of extensions of dispensable files created by BibTeX.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (defvar texinfo-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 '(".cp" ".cps" ".fn" ".fns" ".ky" ".kys" ".pg" ".pgs"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ".tp" ".tps" ".vr" ".vrs")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 "List of extensions of dispensable files created by texinfo.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (defun dired-clean-patch ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 "Flag dispensable files created by patch for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 See variable `patch-unclean-extensions'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (dired-flag-extension patch-unclean-extensions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (defun dired-clean-tex ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 "Flag dispensable files created by tex etc. for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 See variable `texinfo-unclean-extensions', `latex-unclean-extensions',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 `bibtex-unclean-extensions' and `texinfo-unclean-extensions'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (dired-flag-extension (append texinfo-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 latex-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 bibtex-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 tex-unclean-extensions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (defun dired-do-unmark (unmarker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 "Unmark marked files by replacing the marker with another character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 The new character defaults to a space, effectively unmarking them."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (interactive "sChange marker to: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (if (string= unmarker "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (setq unmarker " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq unmarker (substring unmarker 0 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (let ((regexp (dired-marker-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (while (re-search-forward regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (replace-match unmarker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; This is unused but might come in handy sometime
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;(defun dired-directories-of (files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ; ;; Return unique list of parent directories of FILES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ; (let (dirs dir file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ; (while files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ; (setq file (car files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ; files (cdr files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ; dir (file-name-directory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ; (or (member dir dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ; (setq dirs (cons dir dirs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ; dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; Adapted from code by wurgler@zippysun.math.uakron.edu (Tom Wurgler).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; Suggest you bind it to a key. I use C-x C-j.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defun dired-jump-back (&optional other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 "Jump back to dired:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 If in a file, dired the current directory and move to file's line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 If in dired already, pop up a level and goto old directory's line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 In case the proper dired file line cannot be found, refresh the dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 buffer and try again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (let* ((file buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (dir (if file (file-name-directory file) default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (if (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (setq dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (if other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (dired-up-directory-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (dired-up-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (dired-really-goto-file dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (if other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (dired-other-window dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (dired dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (if file (dired-really-goto-file file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (defun dired-jump-back-other-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 "Like \\[dired-jump-back], but to other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (dired-jump-back t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defun dired-really-goto-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (or (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (progn ; refresh and try again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (dired-insert-subdir (file-name-directory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (dired-goto-file file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (defun dired-up-directory-other-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 "Like `dired-up-directory', but in other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (let* ((dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (up (file-name-directory (directory-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (or (dired-goto-file (directory-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (dired-goto-subdir up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;; Only in this case it really uses another window:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (dired-other-window up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (dired-goto-file dir)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (defun dired-mark-rcs-files (&optional unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 "Mark all files that are under RCS control.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 With prefix argument, unflag all those files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 Mentions RCS files for which a working file was not found in this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Type \\[dired-why] to see them again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; Returns failures, or nil on success.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; Finding those with locks would require to peek into the ,v file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;; depends slightly on the RCS version used and should be done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;; together with the Emacs RCS interface.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ;; Unfortunately, there is no definitive RCS interface yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (message "%sarking RCS controlled files..." (if unflag-p "Unm" "M"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (let ((dired-marker-char (if unflag-p ?\ dired-marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 rcs-files wf failures count total)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (mapcar ; loop over subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (lambda (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (or (equal (file-name-nondirectory (directory-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 "RCS")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; skip inserted RCS subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (setq rcs-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (append (directory-files dir t ",v$") ; *,v and RCS/*,v
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (let ((rcs-dir (expand-file-name "RCS" dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (if (file-directory-p rcs-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (mapcar ; working files from ./RCS are in ./
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (expand-file-name x dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (directory-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (file-name-as-directory rcs-dir) nil ",v$"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 rcs-files)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (mapcar (function car) dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (setq total (length rcs-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (while rcs-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq wf (substring (car rcs-files) 0 -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 rcs-files (cdr rcs-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (save-excursion (if (dired-goto-file wf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (dired-mark-file 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (setq failures (cons wf failures)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (if (null failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (message "%d RCS file%s %smarked."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 total (dired-plural-s total) (if unflag-p "un" ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (setq count (length failures))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (dired-log-summary "RCS working file not found %s" failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (message "%d RCS file%s: %d %smarked - %d not found %s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 total (dired-plural-s total) (- total count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (if unflag-p "un" "") count failures))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 failures))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (defun dired-do-toggle ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 "Toggle marks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 That is, currently marked files become unmarked and vice versa.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 Files marked with other flags (such as `D') are not affected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 `.' and `..' are never toggled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 As always, hidden subdirs are not affected."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (or (dired-between-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (looking-at dired-re-dot)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; use subst instead of insdel because it does not move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ;; the gap and thus should be faster and because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ;; other characters are left alone automatically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (apply 'subst-char-in-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (point) (1+ (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (if (eq ?\040 (following-char)) ; SPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (list ?\040 dired-marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (list dired-marker-char ?\040))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (forward-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ;; This function is missing in simple.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (defun copy-string-as-kill (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 "Save STRING as if killed in a buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (setq kill-ring (cons string kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (if (> (length kill-ring) kill-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (setq kill-ring-yank-pointer kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (defvar dired-marked-files nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 "List of filenames from last `dired-copy-filename-as-kill' call.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (defun dired-copy-filename-as-kill (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 "Copy names of marked (or next ARG) files into the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 The names are separated by a space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 With a zero prefix arg, use the complete pathname of each marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 With a raw (just \\[universal-argument]) prefix arg, use the relative pathname of each marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 If on a subdir headerline and no prefix arg given, use subdirname instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 You can then feed the file name to other commands with \\[yank].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 The list of names is also stored onto the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 `dired-marked-files' for use, e.g., in an `\\[eval-expression]' command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (copy-string-as-kill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (or (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (dired-get-subdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (mapconcat (function identity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (setq dired-marked-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (cond ((zerop (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (dired-mark-get-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ((integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (dired-mark-get-files 'no-dir arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (t ; else a raw arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (dired-mark-get-files t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (dired-mark-get-files 'no-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 " ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (message "%s" (car kill-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (defun dired-do-background-shell-command (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 "Like \\[dired-do-shell-command], but starts command in background.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 Note that you can type input to the command in its buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 This requires background.el from the comint package to work."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;; With the version in emacs-19.el, you can alternatively just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ;; append an `&' to any shell command to make it run in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;; background, but you can't type input to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (dired-do-shell-command arg t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;; redefines dired.el to put back in the dired-offer-kill-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 ;; feature which rms didn't like.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (defun dired-clean-up-after-deletion (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ;; Clean up after a deleted file or directory FN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;; Remove expanded subdir of deleted dir, if any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (save-excursion (and (dired-goto-subdir fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (dired-kill-subdir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ;; Offer to kill buffer of deleted file FN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (let ((buf (get-file-buffer fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (and buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (funcall (function y-or-n-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (format "Kill buffer of %s, too? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (file-name-nondirectory fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (save-excursion;; you never know where kill-buffer leaves you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (kill-buffer buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (let ((buf-list (dired-buffers-for-top-dir fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (buf nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (and buf-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (y-or-n-p (format "Kill dired buffer%s of %s, too? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (dired-plural-s (length buf-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (file-name-nondirectory fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (while buf-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (save-excursion (kill-buffer (car buf-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (setq buf-list (cdr buf-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 ;; Anything else?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ;;; Omitting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ;;; Enhanced omitting of lines from directory listings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ;;; Marked files are never omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ;;; Adapted from code submitted by:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ;;; Michael D. Ernst, mernst@theory.lcs.mit.edu, 1/11/91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (make-variable-buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (defvar dired-omit-files-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 "*If non-nil, \"uninteresting\" files are not listed (buffer-local).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 Use \\[dired-omit-toggle] to toggle its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 Uninteresting files are those whose filenames match regexp `dired-omit-files',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 plus those ending with extensions in `dired-omit-extensions'."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (defvar dired-omit-files "^#\\|\\.$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 "*Filenames matching this regexp will not be displayed (buffer-local).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 This only has effect when `dired-omit-files-p' is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 See also `dired-omit-extensions'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (defvar dired-omit-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (append completion-ignored-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 latex-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 bibtex-unclean-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 texinfo-unclean-extensions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 "*If non-nil, a list of extensions (strings) to omit from Dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 listings. Defaults to the elements of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 `completion-ignored-extensions', `latex-unclean-extensions',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 `bibtex-unclean-extensions' and `texinfo-unclean-extensions'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 ;; should probably get rid of this and always use 'no-dir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;; sk 28-Aug-1991 09:37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (defvar dired-omit-localp 'no-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "The LOCALP argument dired-omit-expunge passes to dired-get-filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 If it is 'no-dir, omitting is much faster, but you can only match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 against the basename of the file. Set it to nil if you need to match the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 whole pathname.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ;; \017=^O for Omit - other packages can chose other control characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (defvar dired-omit-marker-char ?\017
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 "Temporary marker used by by dired-omit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 Should never be used as marker by the user or other packages.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (defun dired-omit-startup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (or (assq 'dired-omit-files-p minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; Append at end so that it doesn't get between "Dired" and "by name".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (append minor-mode-alist '((dired-omit-files-p " Omit"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (defun dired-omit-toggle (&optional flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 "Toggle between displaying and omitting files matching `dired-omit-files'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 With an arg, and if omitting was off, don't toggle and just mark the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 files but don't actually omit them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 With an arg, and if omitting was on, turn it off but don't refresh the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (if flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (if dired-omit-files-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (setq dired-omit-files-p (not dired-omit-files-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (dired-mark-unmarked-files (dired-omit-regexp) nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 dired-omit-localp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 ;; no FLAG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (setq dired-omit-files-p (not dired-omit-files-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (if (not dired-omit-files-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (revert-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;; this will mention how many were omitted:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (dired-omit-expunge))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 ;; This is sometimes let-bound to t if messages would be annoying,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;; e.g., in dired-awrh.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (defvar dired-omit-silent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;; in emacs19 `(dired-do-kill)' is called `(dired-do-kill-lines)'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (if (fboundp 'dired-do-kill-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (fset 'dired-do-kill 'dired-do-kill-lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (defun dired-omit-expunge (&optional regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 "Erases all unmarked files matching REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 Does nothing if global variable `dired-omit-files-p' is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 If REGEXP is nil or not specified, uses `dired-omit-files', and also omits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 filenames ending in `dired-omit-extensions'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 If REGEXP is the empty string, this function is a no-op.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 This functions works by temporarily binding `dired-marker-char' to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 `dired-omit-marker-char' and calling `dired-do-kill'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (interactive "sOmit files (regexp): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (if dired-omit-files-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (let ((omit-re (or regexp (dired-omit-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (or (string= omit-re "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (let ((dired-marker-char dired-omit-marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (or dired-omit-silent (message "Omitting..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (if (dired-mark-unmarked-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 omit-re nil nil dired-omit-localp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (setq count (dired-do-kill nil (if dired-omit-silent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 "Omitted %d line%s.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (or dired-omit-silent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (message "(Nothing to omit)")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (defun dired-omit-regexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (concat (if dired-omit-files (concat "\\(" dired-omit-files "\\)") "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (if (and dired-omit-files dired-omit-extensions) "\\|" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (if dired-omit-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (concat ".";; a non-extension part should exist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (mapconcat 'regexp-quote dired-omit-extensions "\\|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 "\\)$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ;; Returns t if any work was done, nil otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 "Marks unmarked files matching REGEXP, displaying MSG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 REGEXP is matched against the complete pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 Does not re-mark files which already have a mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 With prefix argument, unflag all those files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 Second optional argument LOCALP is as in `dired-get-filename'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (let ((dired-marker-char (if unflag-p ?\ dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;; not already marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (looking-at " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;; uninteresting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (let ((fn (dired-get-filename localp t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (and fn (string-match regexp fn))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (defun dired-omit-new-add-entry (filename &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ;; This redefines dired.el's dired-add-entry to avoid calling ls for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;; files that are going to be omitted anyway.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (if dired-omit-files-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;; perhaps return t without calling ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (let ((omit-re (dired-omit-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (if (or (string= omit-re "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (string-match omit-re
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ((eq 'no-dir dired-omit-localp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ((eq t dired-omit-localp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (dired-make-relative filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (dired-make-absolute filename directory))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;; if it didn't match, go ahead and add the entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (dired-omit-old-add-entry filename marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; dired-add-entry returns t for success, perhaps we should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; return file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;; omitting is not turned on at all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (dired-omit-old-add-entry filename marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 ;; Save old defun if not already done:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (or (fboundp 'dired-omit-old-add-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (fset 'dired-omit-old-add-entry (symbol-function 'dired-add-entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;; Redefine dired.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (fset 'dired-add-entry 'dired-omit-new-add-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (defun dired-mark-sexp (predicate &optional unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 "Mark files for which PREDICATE returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 With a prefix arg, unflag those files instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 PREDICATE is a lisp expression that can refer to the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 inode [integer] the inode of the file (only for ls -i output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 s [integer] the size of the file for ls -s output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (ususally in blocks or, with -k, in KByte)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 mode [string] file permission bits, e.g. \"-rw-r--r--\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 nlink [integer] number of links to file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 uid [string] owner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 gid [string] group (If the gid is not displayed by ls,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 this will still be set (to the same as uid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 size [integer] file size in bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 time [string] the time that ls displays, e.g. \"Feb 12 14:17\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 name [string] the name of the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 sym [string] if file is a symbolic link, the linked-to name, else \"\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 For example, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (equal 0 size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 to mark all zero length files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;; Using sym="" instead of nil avoids the trap of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ;; (string-match "foo" sym) into which a user would soon fall.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ;; Give `equal' instead of `=' in the example, as this works on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 ;; integers and strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (interactive "xMark if (lisp expr): \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (message "%s" predicate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 inode s mode nlink uid gid size time name sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (save-excursion (and (dired-parse-ls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (eval predicate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (format "'%s file" predicate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 ;; With Jamie's compiler we could do the following instead:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ; (eval (byte-compile-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ; (macroexpand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ; (` (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 ; (save-excursion (and (dired-parse-ls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 ; (, predicate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ; (format "'%s file" (quote (, predicate))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 ;; This isn't measurably faster, though, at least for simple predicates.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;; Caching compiled predicates might be interesting if you use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 ;; this command a lot or with complicated predicates.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;; Alternatively compiling PREDICATE by hand should not be too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ;; hard - e.g., if it uses just one variable, not all of the ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;; line needs to be parsed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (if (fboundp 'gmhist-make-magic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (gmhist-make-magic 'dired-mark-sexp 'eval-expression-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (defun dired-parse-ls ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 ;; Sets vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 ;; inode s mode nlink uid gid size time name sym
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;; (probably let-bound in caller) according to current file line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;; Returns t for succes, nil if this is no file line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ;; Upon success, all variables are set, either to nil or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 ;; appropriate value, so they need not be initialized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ;; Moves point within the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (if (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (let (pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (mode-len 10) ; length of mode string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 ;; like in dired.el, but with subexpressions \1=inode, \2=s:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (forward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (if (looking-at dired-re-inode-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (setq inode (string-to-int (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 s (string-to-int (buffer-substring (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (match-end 2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (setq inode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 s nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (setq mode (buffer-substring (point) (+ mode-len (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (forward-char mode-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (setq nlink (read (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (setq uid (buffer-substring (point) (progn (forward-word 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (re-search-forward "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (setq size (string-to-int (buffer-substring (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (backward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (setq pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (backward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ;; if no gid is displayed, gid will be set to uid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 ;; but user will then not reference it anyway in PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (setq gid (buffer-substring (save-excursion (forward-word 1) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 time (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (1- (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 name (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (or (dired-move-to-end-of-filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 sym (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (if (looking-at " -> ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (buffer-substring (progn (forward-char 4) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (progn (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ;; tester
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 ;;(defun dired-parse-ls-show ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 ;; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 ;; (let (inode s mode size uid gid nlink time name sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;; (if (dired-parse-ls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ;; (message "%s" (list inode s mode nlink uid gid size time name sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ;; (message "Not on a file line."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ;; Mark files whose names appear in another buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (defun dired-mark-these-files (file-list from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 ;; Mark the files in FILE-LIST. Relative filenames are taken to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 ;; in the current dired directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ;; FROM is a string (used for logging) describing where FILE-LIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 ;; came from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 ;; Logs files that were not found and displays a success or failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;; message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (message "Marking files %s..." from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (let ((total (length file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (cur-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 file failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (while file-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (setq file (dired-make-absolute (car file-list) cur-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 file-list (cdr file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;;(message "Marking file `%s'" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (if (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (dired-mark-file 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (setq failures (cons (dired-make-relative file) failures))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (dired-log "Cannot mark this file (not found): %s\n" file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (if failures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (dired-log-summary (message "Failed to mark %d of %d files %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (length failures) total from failures))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (message "Marked %d file%s %s." total (dired-plural-s total) from))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (defun dired-mark-files-from-other-dired-buffer (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 "Mark files that are marked in the other Dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 I.e, mark those files in this Dired buffer that have the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 non-directory part as the marked files in the Dired buffer in the other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (interactive (list (window-buffer (next-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (if (eq (get-buffer buf) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (error "Other dired buffer is the same"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (or (stringp buf) (setq buf (buffer-name buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (let ((other-files (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (or (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (error "%s is not a dired buffer" buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (dired-mark-get-files 'no-dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (dired-mark-these-files other-files (concat "from buffer " buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (defun dired-mark-files-compilation-buffer (&optional regexp buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 "Mark the files mentioned in the `*compilation*' buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 With an arg, you may specify the other buffer and your own regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 instead of `compilation-error-regexp'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 Use `^.+$' (the default with a prefix arg) to match complete lines or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 an empty string for `compilation-error-regexp'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 In conjunction with narrowing the other buffer you can mark an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 arbitrary list of files, one per line, with this command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (read-string "Use compilation regexp: " "^.+$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (read-buffer "Use buffer: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (let ((next-buffer (window-buffer (next-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (if (eq next-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (other-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 next-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (let (other-files user-regexp-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (if (zerop (length regexp)) ; nil or ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (setq regexp compilation-error-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (setq user-regexp-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (or buf (setq buf "*compilation*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (or (stringp buf) (setq buf (buffer-name buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (set-buffer (or (get-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (error "No %s buffer!" buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (let (file new-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (while (re-search-forward regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (setq new-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 ;; If user specified a regexp with subexpr 1, and it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 ;; matched, take that one for the file name, else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 ;; take whole match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 ;; Else take the match from the compile regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (if user-regexp-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (or (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (if user-regexp-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (or (match-end 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (match-beginning 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (or (equal file new-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 ;; Avoid marking files twice as this is slow. Multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ;; lines for the same file are common when compiling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (setq other-files (cons new-file other-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 file new-file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (dired-mark-these-files other-files (concat "from buffer " buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ;; make-symbolic-link always expand-file-name's its args, so relative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 ;; symlinks (e.g. "foo" -> "../bar/foo") are impossible to create.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 ;; Following code uses ln -s for a workaround.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (defvar dired-keep-marker-relsymlink ?S
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 "See variable `dired-keep-marker-move'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (defun dired-make-symbolic-link (name1 name2 &optional ok-if-already-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;; Args NAME1 NAME2 &optional OK-IF-ALREADY-EXISTS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;; Create file NAME2, a symbolic link pointing to NAME1 (which may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 ;; be any string whatsoever and is passed untouched to ln -s).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;; OK-IF-ALREADY-EXISTS means that NAME2 will be overwritten if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;; already exists. If it is an integer, user will be asked about this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;; On error, signals a file-error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (interactive "FSymlink to (string): \nFMake symbolic link to `%s': \np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (setq name2 (expand-file-name name2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (let* ((file-symlink-p (file-symlink-p name2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (file-exists-p (file-exists-p name2)) ; dereferences symlinks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (file-or-symlink-exists (or file-symlink-p file-exists-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (if (and file-symlink-p (not file-exists-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;; We do something dirty here as dired.el never checks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ;; file-symlink-p in addition to file-exists-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ;; This way me make sure we never silently overwrite even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ;; symlinks to non-existing files (what an achievement! ;-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (setq ok-if-already-exists 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (if (or (null ok-if-already-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (integerp ok-if-already-exists))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (if (and file-or-symlink-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (not (and (integerp ok-if-already-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 "File %s already exists; symlink anyway? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 name2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (signal 'file-error (cons "File already exists" name2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 ;; Bombs if NAME1 starts with "-", but not all ln programs may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 ;; understand "--" to mean end of options...sigh
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (let (err)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (if file-or-symlink-exists (delete-file name2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (setq err (dired-check-process "SymLink" "ln" "-s" name1 name2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (if err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (signal 'file-error (cons "ln" err))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (defun dired-make-relative-symlink (file1 file2 &optional ok-if-already-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 "Three arguments: FILE1 FILE2 &optional OK-IF-ALREADY-EXISTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 Make a symbolic link (pointing to FILE1) in FILE2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 The link is relative (if possible), for example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 \"/vol/tex/bin/foo\" \"/vol/local/bin/foo\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 results in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 \"../../tex/bin/foo\" \"/vol/local/bin/foo\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (interactive "FRelSymLink: \nFRelSymLink %s: \np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (let (name1 name2 len1 len2 (index 0) sub)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (setq file1 (expand-file-name file1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 file2 (expand-file-name file2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 len1 (length file1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 len2 (length file2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;; Find common initial pathname components:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (let (next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (while (and (setq next (string-match "/" file1 index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (setq next (1+ next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (< next (min len1 len2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;; For the comparison, both substrings must end in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;; `/', so NEXT is *one plus* the result of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ;; string-match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 ;; E.g., consider the case of linking "/tmp/a/abc"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ;; to "/tmp/abc" erronously giving "/tmp/a" instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 ;; of "/tmp/" as common initial component
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (string-equal (substring file1 0 next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (substring file2 0 next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (setq index next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (setq name2 file2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 sub (substring file1 0 index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 name1 (substring file1 index)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (if (string-equal sub "/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;; No common initial pathname found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (setq name1 file1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ;; Else they have a common parent directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (let ((tem (substring file2 index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;; Count number of slashes we must compensate for ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (while (setq start (string-match "/" tem start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (setq count (1+ count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 start (1+ start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 ;; ... and prepend a "../" for each slash found:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (setq count (1- count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 name1 (concat "../" name1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (dired-make-symbolic-link
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (directory-file-name name1) ; must not link to foo/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ; (trailing slash!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 name2 ok-if-already-exists)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (defun dired-do-relsymlink (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 "Symlink all marked (or next ARG) files into a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 or make a symbolic link to the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 This creates relative symbolic links like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 foo -> ../bar/foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 not absolute ones like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 foo -> /ugly/path/that/may/change/any/day/bar/foo"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (dired-do-create-files 'relsymlink (function dired-make-relative-symlink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 "RelSymLink" arg dired-keep-marker-relsymlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 ;; XEmacs: added extra arg per tbarker@sun059.cpdsc.com (Ted Barker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (defun dired-do-relsymlink-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 "RelSymlink all marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 See functions `dired-rename-regexp' and `dired-do-relsymlink'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 for more info. With optional prefix ARG, will operate on ARG files following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 point if no files are marked."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (interactive (dired-mark-read-regexp "RelSymLink"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (function dired-make-relative-symlink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 "RelSymLink" arg regexp newname whole-path dired-keep-marker-relsymlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; Virtual dired mode to browse ls -lR listings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ;; sk@sun5 7-Mar-1991 16:00
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (fset 'virtual-dired 'dired-virtual)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (defun dired-virtual (dirname &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 "Put this buffer into Virtual Dired mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 In Virtual Dired mode, all commands that do not actually consult the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 filesystem will work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 This is useful if you want to peruse and move around in an ls -lR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 output file, for example one you got from an ftp server. With
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ange-ftp, you can even dired a directory containing an ls-lR file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 visit that file and turn on virtual dired mode. But don't try to save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 this file, as dired-virtual indents the listing and thus changes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 If you have save a Dired buffer in a file you can use \\[dired-virtual] to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 resume it in a later session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 Type \\<dired-mode-map>\\[revert-buffer] in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 Virtual Dired buffer and answer `y' to convert the virtual to a real
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 dired buffer again. You don't have to do this, though: you can relist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 single subdirs using \\[dired-do-redisplay].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 ;; DIRNAME is the top level directory of the buffer. It will become
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 ;; its `default-directory'. If nil, the old value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 ;; default-directory is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ;; Optional SWITCHES are the ls switches to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 ;; Shell wildcards will be used if there already is a `wildcard'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 ;; line in the buffer (thus it is a saved Dired buffer), but there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; is no other way to get wildcards. Insert a `wildcard' line by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ;; hand if you want them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (list (read-string "Virtual Dired directory: " (dired-virtual-guess-dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (or (looking-at " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ;; if not already indented, do it now:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (indent-region (point-min) (point-max) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (or dirname (setq dirname default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (setq dirname (expand-file-name (file-name-as-directory dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (setq default-directory dirname) ; contains no wildcards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (let ((wildcard (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (and (looking-at "^ wildcard ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (buffer-substring (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (progn (end-of-line) (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (if wildcard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (setq dirname (expand-file-name wildcard default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 ;; If raw ls listing (not a saved old dired buffer), give it a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;; decent subdir headerline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (or (looking-at dired-subdir-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (dired-insert-headerline default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (dired-mode dirname (or switches dired-listing-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (setq mode-name "Virtual Dired"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 revert-buffer-function 'dired-virtual-revert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (set (make-local-variable 'dired-subdir-alist) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (dired-build-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (dired-initial-position dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (defun dired-virtual-guess-dir ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 ;; Guess and return appropriate working directory of this buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 ;; assumed to be in Dired or ls -lR format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 ;; The guess is based upon buffer contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 ;; If nothing could be guessed, returns nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (let ((regexp "^\\( \\)?\\([^ \n\r]*\\)\\(:\\)[\n\r]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (subexpr 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (cond ((looking-at regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 ;; If a saved dired buffer, look to which dir and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 ;; perhaps wildcard it belongs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (let ((dir (buffer-substring (match-beginning subexpr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (match-end subexpr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (file-name-as-directory dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ;; Else no match for headerline found. It's a raw ls listing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 ;; In raw ls listings the directory does not have a headerline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;; try parent of first subdir, if any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ((re-search-forward regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (file-name-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (directory-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (buffer-substring (match-beginning subexpr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (match-end subexpr))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (t ; if all else fails
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (defun dired-virtual-revert (&optional arg noconfirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (if (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (y-or-n-p "Cannot revert a Virtual Dired buffer - switch to Real Dired mode? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (error "Cannot revert a Virtual Dired buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (setq mode-name "Dired"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 revert-buffer-function 'dired-revert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (revert-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 ;; A zero-arg version of dired-virtual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 ;; You need my modified version of set-auto-mode for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 ;; `buffer-contents-mode-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 ;; Or you use infer-mode.el and infer-mode-alist, same syntax.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (defun dired-virtual-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 "Put current buffer into virtual dired mode (see `dired-virtual').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 Useful on `buffer-contents-mode-alist' (which see) with the regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 \"^ \\(/[^ /]+\\)/?+:$\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 to put saved dired buffers automatically into virtual dired mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 Also useful for `auto-mode-alist' (which see) like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 \(setq auto-mode-alist (cons '(\"[^/]\\.dired$\" . dired-virtual-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 auto-mode-alist)\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (dired-virtual (dired-virtual-guess-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (defvar dired-find-subdir nil ; t is pretty near to DWIM...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 "*If non-nil, Dired does not make a new buffer for a directory if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 can be found (perhaps as subdir) in some existing Dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 If there are several Dired buffers for a directory, the most recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 used is chosen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 Dired avoids switching to the current buffer, so that if you have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 a normal and a wildcard buffer for the same directory, C-x d RET will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 toggle between those two.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (or (fboundp 'dired-old-find-buffer-nocreate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (fset 'dired-old-find-buffer-nocreate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (symbol-function 'dired-find-buffer-nocreate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (defun dired-find-buffer-nocreate (dirname) ; redefine dired.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (if dired-find-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (let* ((cur-buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (buffers (nreverse (dired-buffers-for-dir-exact dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (cur-buf-matches (and (memq cur-buf buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 ;; wildcards must match, too:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (equal dired-directory dirname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 ;; We don't want to switch to the same buffer---
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (setq buffers (delq cur-buf buffers));;need setq with delq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (or (car (sort buffers (function dired-x-buffer-more-recently-used-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 ;; ---unless it's the only possibility:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (and cur-buf-matches cur-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (dired-old-find-buffer-nocreate dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;; this should be a builtin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (defun dired-x-buffer-more-recently-used-p (buffer1 buffer2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 "Return t if BUFFER1 is more recently used than BUFFER2."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (if (equal buffer1 buffer2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (let ((more-recent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (list (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (while (and list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (not (setq more-recent (equal buffer1 (car list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (not (equal buffer2 (car list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 more-recent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (defun dired-buffers-for-dir-exact (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 ;; Return a list of buffers that dired DIR (a directory or wildcard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 ;; at top level, or as subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 ;; Top level matches must match the wildcard part too, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 ;; The list is in reverse order of buffer creation, most recent last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 ;; As a side effect, killed dired buffers for DIR are removed from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ;; dired-buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (let ((alist dired-buffers) result elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 alist (cdr alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (let ((buf (cdr elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (if (buffer-name buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ;; Top level must match exactly against dired-directory in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 ;; case one of them is a wildcard.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (if (or (equal dir (save-excursion (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 dired-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (assoc dir (save-excursion (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (setq result (cons buf result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 ;; else buffer is killed - clean up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (setq dired-buffers (delq elt dired-buffers)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (defun dired-buffers-for-top-dir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 ;; Return a list of buffers that dired DIR (a directory, not a wildcard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 ;; at top level, with or without wildcards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 ;; As a side effect, killed dired buffers for DIR are removed from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 ;; dired-buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (setq dir (file-name-as-directory dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (let ((alist dired-buffers) result elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 alist (cdr alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (let ((buf (cdr elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (if (buffer-name buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (if (equal dir (save-excursion (set-buffer buf) default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (setq result (cons buf result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 ;; else buffer is killed - clean up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (setq dired-buffers (delq elt dired-buffers)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (defun dired-initial-position (dirname) ; redefine dired.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (if dired-find-subdir (dired-goto-subdir dirname)) ; new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 ;;; Let `C-x f' and `C-x 4 f' know about Tree Dired's multiple directories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 ;;; As a bonus, you get filename-at-point as default with a prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ;; It's easier to add to this alist than redefine function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 ;; default-directory while keeping the old information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (defconst default-directory-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 '((dired-mode . (if (fboundp 'dired-current-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (dired-current-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 "Alist of major modes and their opinion on default-directory, as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 lisp expression to evaluate. A resulting value of nil is ignored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 favor of default-directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (defun default-directory ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 "Usage like variable `default-directory', but knows about the special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 cases in variable `default-directory-alist' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (or (eval (cdr (assq major-mode default-directory-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (defun find-file-read-filename-at-point (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (if (fboundp 'gmhist-read-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (let ((fn (filename-at-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (gmhist-read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 prompt (default-directory) fn nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 ;; the INITIAL arg is only accepted in Emacs 19 or with gmhist:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (gmhist-read-file-name prompt (default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 ;; Else gmhist is not available, thus no initial input possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 ;; Could use filename-at-point as default and mung prompt...ugh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 ;; Nah, get gmhist, folks!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (read-file-name prompt (default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (defun filename-at-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 "Get the filename closest to point, but don't change your position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 Has a preference for looking backward when not directly on a symbol."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 ;; Not at all perfect - point must be right in the name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (let ((filename-chars ".a-zA-Z0-9---_/:$") start end filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (bol (save-excursion (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (eol (save-excursion (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 ;; first see if you're just past a filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (if (looking-at "[] \t\n[{}()]") ; whitespace or some parens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (skip-chars-backward " \n\t\r({[]})")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (if (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (backward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (if (string-match (concat "[" filename-chars "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (char-to-string (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (skip-chars-backward filename-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (if (string-match "[/~]" (char-to-string (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (setq start (1- start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (skip-chars-forward filename-chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (error "No file found around point!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (expand-file-name (buffer-substring start (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (defun find-this-file (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 "Edit file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 Switch to a buffer visiting file FILENAME, creating one if none already exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 Interactively, with a prefix arg, calls `filename-at-point'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 Useful to edit the file mentioned in the buffer you are editing, or to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 test if that file exists: use minibuffer completion after snatching the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 name or part of it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (interactive (list (find-file-read-filename-at-point "Find file: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (find-file (expand-file-name fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (defun find-this-file-other-window (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 "Edit file FILENAME in other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 Switch to a buffer visiting file FILENAME, creating one if none already exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 Interactively, with a prefix arg, call `filename-at-point'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 Useful to edit the file mentioned in the buffer you are editing, or to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 test if that file exists: use minibuffer completion after snatching the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 name or part of it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (interactive (list (find-file-read-filename-at-point "Find file: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (find-file-other-window (expand-file-name fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (defun dired-smart-shell-command (cmd &optional insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 "Like function `shell-command', but in the current Tree Dired directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (interactive "sShell command: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (let ((default-directory (default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (shell-command cmd insert)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (if (fboundp 'gmhist-make-magic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (gmhist-make-magic 'dired-smart-shell-command 'shell-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (defun dired-smart-background-shell-command (cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 "Run a shell command in the background.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 Like function `background' but in the current Tree Dired directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (interactive "s%% ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (shell-command (concat "cd " (default-directory) "; " cmd " &")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (if (fboundp 'gmhist-make-magic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (gmhist-make-magic 'dired-smart-background-shell-command 'shell-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 ;; Local variables for Dired buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (defvar dired-local-variables-file ".dired"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 "If non-nil, filename for local variables for Dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 If Dired finds a file with that name in the current directory, it will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 temporarily insert it into the dired buffer and run `hack-local-variables'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 Type \\[info] and and `g' `(emacs)File Variables' `RET' for more info on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 local variables.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (defun dired-hack-local-variables ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 "Parse, and bind or evaluate as appropriate, any local variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 for current dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 See variable `dired-local-variables-file'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (if (and dired-local-variables-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (file-exists-p dired-local-variables-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (let (buffer-read-only opoint )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (setq opoint (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (insert "\^L\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (insert-file-contents dired-local-variables-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (let ((buffer-file-name dired-local-variables-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (hack-local-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 ;; Must delete it as (eobp) is often used as test for last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 ;; subdir in dired.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (delete-region opoint (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (set-marker opoint nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 ;; Guess what shell command to apply to a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (defvar dired-guess-have-gnutar nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 "*If non-nil, name of the GNU tar executable (e.g. \"tar\" or \"gnutar\").
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 GNU tar's `z' switch is used for compressed tar files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 If you don't have GNU tar, set this to nil: a pipe using `zcat' is then used.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (defvar dired-make-gzip-quiet t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 "*If non-nil, pass -q to shell commands involving gzip this will override
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 GZIP environment variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (defvar dired-znew-switches nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 "*If non-nil, a string of switches that will be passed to `znew'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 example: \"-K\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (defvar dired-auto-shell-command-alist-default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (list "\\.tar$" (if dired-guess-have-gnutar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (concat dired-guess-have-gnutar " xvf")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 "tar xvf"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 ;; regexps for compressed archives must come before the .Z rule to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 ;; be recognized:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (list "\\.tar\\.Z$" (if dired-guess-have-gnutar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (concat dired-guess-have-gnutar " zxvf")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (concat "zcat * | tar xvf -"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 ;; optional conversion to gzip (GNU zip) format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (concat "znew"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (if dired-make-gzip-quiet " -q")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 " " dired-znew-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 ;; gzip'ed (GNU zip) archives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (list "\\.tar\\.g?z$\\|\\.tgz$" (if dired-guess-have-gnutar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (concat dired-guess-have-gnutar " zxvf")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 ;; use `gunzip -qc' instead of `zcat' since some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 ;; people don't install GNU zip's version of zcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (concat "gunzip -qc * | tar xvf -")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 '("\\.shar.Z$" "zcat * | unshar")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 ;; use `gunzip -c' instead of `zcat'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 '("\\.shar.g?z$" "gunzip -qc * | unshar")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 '("\\.ps$" "ghostview" "xv" "lpr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 '("\\.ps.g?z$" "gunzip -qc * | ghostview -"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 ;; optional decompression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (concat "gunzip" (if dired-make-gzip-quiet " -q")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 '("\\.ps.Z$" "zcat * | ghostview -"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 ;; optional conversion to gzip (GNU zip) format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (concat "znew"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (if dired-make-gzip-quiet " -q")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 " " dired-znew-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 '("\\.dvi$" "xdvi" "dvips")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 '("\\.au$" "play") ; play Sun audiofiles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 '("\\.mpg$" "mpeg_play")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 '("\\.dl$" "xdl") ; loop pictures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 '("\\.fli$" "xanim")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 '("\\.gl$" "xgrasp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 '("\\.uu$" "uudecode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 '("\\.hqx$" "mcvert")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 '("\\.sh$" "sh") ; execute shell scripts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 '("\\.xbm$" "bitmap") ; view X11 bitmaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 '("\\.xpm$" "sxpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 '("\\.gp$" "gnuplot")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 '("\\.p[bgpn]m$" "xv")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 '("\\.gif$" "xv") ; view gif pictures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 '("\\.tif$" "xv")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 '("\\.jpg$" "xv")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 '("\\.fig$" "xfig") ; edit fig pictures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 '("\.tex$" "latex" "tex")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 '("\\.texi\\(nfo\\)?$" "makeinfo" "texi2dvi")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (if (eq window-system 'x) ; under X, offer both...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 '("\\.dvi$" "xtex" "dvips") ; ...preview and printing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 '("\\.dvi$" "dvips"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 '("\\.g?z$" (concat "gunzip" (if dired-make-gzip-quiet " -q" ""))) ; quiet?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 '("\\.Z$" "uncompress"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 ;; optional conversion to gzip (GNU zip) format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (concat "znew" (if dired-make-gzip-quiet " -q") " " dired-znew-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 ;; some popular archivers:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 '("\\.zoo$" "zoo x//")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 '("\\.zip$" "unzip")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 '("\\.lzh$" "lharc x")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 '("\\.arc$" "arc x")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 '("\\.shar$" "unshar") ; use "sh" if you don't have unshar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 "Default for variable `dired-auto-shell-command-alist' (which see).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 Set this to nil to turn off shell command guessing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (defvar dired-auto-shell-command-alist nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 "*If non-nil, an alist of file regexps and their suggested commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 Dired shell commands will look up the name of a file in this list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 and suggest the matching command as default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 Each element of this list looks like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 \(REGEXP COMMAND...\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 where each COMMAND can either be a string or a lisp expression that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 evaluates to a string. If several COMMANDs are given, the first one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 will be the default and minibuffer completion will use the given set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 These rules take precedence over the predefined rules in the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 `dired-auto-shell-command-alist-default' (to which they are prepended).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 You can set this variable in your ~/.emacs. For example, to add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 rules for `.foo' and `.bar' files, write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 \(setq dired-auto-shell-command-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (list (list \"\\\\.foo$\" \"FOO-COMMAND\");; fixed rule
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 ;; possibly more rules ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (list \"\\\\.bar$\";; rule with condition test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 '(if condition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 \"BAR-COMMAND-1\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 \"BAR-COMMAND-2\")))\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (setq dired-auto-shell-command-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (if dired-auto-shell-command-alist;; join user and default value:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (append dired-auto-shell-command-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 dired-auto-shell-command-alist-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 ;; else just copy the default value:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 dired-auto-shell-command-alist-default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 (defun dired-guess-default (files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 ;; Guess a shell command for FILES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 ;; Returns a command or a list of commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 ;; You may want to redefine this to try something smarter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (if (or (cdr files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (null dired-auto-shell-command-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 nil ; If more than one file, don't guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (let* ((file (car files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (alist dired-auto-shell-command-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (case-fold-search nil) ; need search to be case-sensitive in order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 ; to distinguish between gzip'ed (`.z') and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 ; compressed (`.Z') files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 elt re cmds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 re (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 alist (cdr alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (if (string-match re file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (setq cmds (cdr elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 alist nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (cond ((not (cdr cmds)) (eval (car cmds))) ; single command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (t (mapcar (function eval) cmds))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (defun dired-guess-shell-command (prompt files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 ;;"Ask user with PROMPT for a shell command, guessing a default from FILES."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (let ((default (dired-guess-default files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 default-list old-history val (failed t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (if (not (featurep 'gmhist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (read-string prompt (if (listp default) (car default) default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 ;; else we have gmhist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (if (null default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (read-with-history-in 'dired-shell-command-history prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (or (boundp 'dired-shell-command-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (setq dired-shell-command-history nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (setq old-history dired-shell-command-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (if (listp default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 ;; more than one guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (setq default-list default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 default (car default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 prompt (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (format "{%d guesses} " (length default-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 ;; just one guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (setq default-list (list default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (put 'dired-shell-command-history 'default default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 ;; push guesses onto history so that they can be retrieved with M-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (setq dired-shell-command-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (append default-list dired-shell-command-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ;; the unwind-protect returns VAL, and we too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (setq val (read-with-history-in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 'dired-shell-command-history prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 failed nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 ;; Undo pushing onto the history list so that an aborted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 ;; command doesn't get the default in the next command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (setq dired-shell-command-history old-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (if (not failed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (or (equal val (car-safe dired-shell-command-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (setq dired-shell-command-history
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (cons val dired-shell-command-history))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 ;; redefine dired.el's version:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (defun dired-read-shell-command (prompt arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 "Read a dired shell command using generic minibuffer history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 This command tries to guess a command from the filename(s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 from the variable `dired-auto-shell-command-alist' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 nil 'shell files ; bufname type files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 'dired-guess-shell-command ; function &rest args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (format prompt (dired-mark-prompt arg files)) files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 ;; Byte-compile-and-load (requires jwz@lucid.com's new byte compiler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (defun dired-do-byte-compile-and-load (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 "Byte compile marked and load (or next ARG) Emacs lisp files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 This requires jwz@lucid.com's new optimizing byte compiler."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (dired-mark-map-check (function dired-byte-compile-and-load) arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 'byte-compile-and-load t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (defun dired-byte-compile-and-load ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 ;; Return nil for success, offending file name else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (let* (buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (from-file (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (new-file (byte-compile-dest-file from-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (if (not (string-match elisp-source-extention-re from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (dired-log "Attempt to compile non-elisp file %s\n" from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 ;; return a non-nil value as error indication
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (dired-make-relative from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (save-excursion;; Jamie's compiler may switch buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (byte-compile-and-load-file from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (dired-remove-file new-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (forward-line) ; insert .elc after its .el file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (dired-add-file new-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ;; Visit all marked files simultaneously.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 ;; After an idea by wurgler@zippysun.math.uakron.edu (Tom Wurgler).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (defun dired-do-find-file (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 "Visit all marked files at once, and display them simultaneously.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 See also function `simultaneous-find-file'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 If you want to keep the dired buffer displayed, type \\[split-window-vertically] first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 If you want just the marked files displayed and nothing else, type \\[delete-other-windows] first."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (simultaneous-find-file (dired-mark-get-files nil arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (defun simultaneous-find-file (file-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 "Visit all files in FILE-LIST and display them simultaneously.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 The current window is split across all files in FILE-LIST, as evenly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 as possible. Remaining lines go to the bottommost window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 The number of files that can be displayed this way is restricted by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 the height of the current window and the variable `window-min-height'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ;; It is usually too clumsy to specify FILE-LIST interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ;; unless via dired (dired-do-find-file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (let ((size (/ (window-height) (length file-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (or (<= window-min-height size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (error "Too many files to visit simultaneously"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (find-file (car file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (setq file-list (cdr file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (while file-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 ;; Split off vertically a window of the desired size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 ;; The upper window will have SIZE lines. We select the lower
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 ;; (larger) window because we want to split that again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (select-window (split-window nil size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (find-file (car file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (setq file-list (cdr file-list)))))