Commit | Line | Data |
---|---|---|
276f1d00 | 1 | ;;; dired-x.el --- extra Dired functionality |
cb3fe1f0 | 2 | |
73b0cd50 | 3 | ;; Copyright (C) 1993-1994, 1997, 2001-2011 Free Software Foundation, Inc. |
552939e4 | 4 | |
cb3fe1f0 RS |
5 | ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de> |
6 | ;; Lawrence R. Dodd <dodd@roebling.poly.edu> | |
2d29381c | 7 | ;; Maintainer: Romain Francoise <rfrancoise@gnu.org> |
a443d46e | 8 | ;; Keywords: dired extensions files |
bd78fa1d | 9 | ;; Package: emacs |
cb3fe1f0 | 10 | |
cb3fe1f0 RS |
11 | ;; This file is part of GNU Emacs. |
12 | ||
eb3fa2cf | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
cb3fe1f0 | 14 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
cb3fe1f0 RS |
17 | |
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
cb3fe1f0 | 25 | |
9572a9dd | 26 | ;;; Commentary: |
cb3fe1f0 | 27 | |
461b69ae GM |
28 | ;; This is based on Sebastian Kremer's excellent dired-x.el (Dired Extra), |
29 | ;; version 1.191, adapted for GNU Emacs. See the `dired-x' info pages. | |
b578f267 | 30 | |
461b69ae | 31 | ;; USAGE: In your ~/.emacs, |
b578f267 EN |
32 | ;; |
33 | ;; (add-hook 'dired-load-hook | |
461b69ae | 34 | ;; (lambda () |
da5e0ce4 | 35 | ;; (load "dired-x") |
d7af463c | 36 | ;; ;; Set global variables here. For example: |
b578f267 | 37 | ;; ;; (setq dired-guess-shell-gnutar "gtar") |
461b69ae | 38 | ;; )) |
d7af463c | 39 | ;; (add-hook 'dired-mode-hook |
461b69ae | 40 | ;; (lambda () |
d7af463c | 41 | ;; ;; Set buffer-local variables here. For example: |
ce64e046 | 42 | ;; ;; (dired-omit-mode 1) |
461b69ae | 43 | ;; )) |
b578f267 EN |
44 | ;; |
45 | ;; At load time dired-x.el will install itself, redefine some functions, and | |
461b69ae | 46 | ;; bind some dired keys. |
b578f267 | 47 | |
461b69ae | 48 | ;; User customization: M-x customize-group RET dired-x RET. |
b578f267 | 49 | |
461b69ae GM |
50 | ;; When loaded this code redefines the following functions of GNU Emacs: |
51 | ;; From dired.el: dired-clean-up-after-deletion, dired-find-buffer-nocreate, | |
52 | ;; and dired-initial-position. | |
53 | ;; From dired-aux.el: dired-add-entry and dired-read-shell-command. | |
b578f267 | 54 | |
461b69ae | 55 | ;; *Please* see the `dired-x' info pages for more details. |
cb3fe1f0 RS |
56 | |
57 | \f | |
b578f267 | 58 | ;;; Code: |
cb3fe1f0 | 59 | |
b578f267 | 60 | ;; LOAD. |
cb3fe1f0 | 61 | |
461b69ae GM |
62 | ;; This is a no-op if dired-x is being loaded via `dired-load-hook', |
63 | ;; but maybe not if a dired-x function is being autoloaded. | |
d82cfc0c | 64 | (require 'dired) |
9572a9dd | 65 | |
461b69ae | 66 | ;; We will redefine some functions and also need some macros. |
d82cfc0c | 67 | (require 'dired-aux) |
9572a9dd | 68 | |
b578f267 | 69 | ;;; User-defined variables. |
cb3fe1f0 | 70 | |
286c247d RS |
71 | (defgroup dired-x nil |
72 | "Extended directory editing (dired-x)." | |
73 | :group 'dired) | |
cb3fe1f0 | 74 | |
286c247d RS |
75 | (defgroup dired-keys nil |
76 | "Dired keys customizations." | |
77 | :prefix "dired-" | |
78 | :group 'dired-x) | |
cb3fe1f0 | 79 | |
286c247d | 80 | (defcustom dired-bind-vm nil |
9201cc28 | 81 | "Non-nil means \"V\" runs `dired-vm', otherwise \"V\" runs `dired-rmail'. |
3176a6a0 GM |
82 | RMAIL files in the old Babyl format (used before before Emacs 23.1) |
83 | contain \"-*- rmail -*-\" at the top, so `dired-find-file' | |
84 | will run `rmail' on these files. New RMAIL files use the standard | |
85 | mbox format, and so cannot be distinguished in this way." | |
286c247d RS |
86 | :type 'boolean |
87 | :group 'dired-keys) | |
88 | ||
89 | (defcustom dired-bind-jump t | |
da5e0ce4 GM |
90 | "Non-nil means bind `dired-jump' to C-x C-j, otherwise do not. |
91 | Setting this variable directly after dired-x is loaded has no effect - | |
92 | use \\[customize]." | |
286c247d | 93 | :type 'boolean |
da5e0ce4 GM |
94 | :set (lambda (sym val) |
95 | (if (set sym val) | |
96 | (progn | |
97 | (define-key global-map "\C-x\C-j" 'dired-jump) | |
98 | (define-key global-map "\C-x4\C-j" 'dired-jump-other-window)) | |
99 | (if (eq 'dired-jump (lookup-key global-map "\C-x\C-j")) | |
100 | (define-key global-map "\C-x\C-j" nil)) | |
101 | (if (eq 'dired-jump-other-window (lookup-key global-map "\C-x4\C-j")) | |
102 | (define-key global-map "\C-x4\C-j" nil)))) | |
286c247d RS |
103 | :group 'dired-keys) |
104 | ||
105 | (defcustom dired-bind-man t | |
da5e0ce4 GM |
106 | "Non-nil means bind `dired-man' to \"N\" in dired-mode, otherwise do not. |
107 | Setting this variable directly after dired-x is loaded has no effect - | |
108 | use \\[customize]." | |
286c247d | 109 | :type 'boolean |
da5e0ce4 GM |
110 | :set (lambda (sym val) |
111 | (if (set sym val) | |
112 | (define-key dired-mode-map "N" 'dired-man) | |
113 | (if (eq 'dired-man (lookup-key dired-mode-map "N")) | |
114 | (define-key dired-mode-map "N" nil)))) | |
286c247d RS |
115 | :group 'dired-keys) |
116 | ||
117 | (defcustom dired-bind-info t | |
da5e0ce4 GM |
118 | "Non-nil means bind `dired-info' to \"I\" in dired-mode, otherwise do not. |
119 | Setting this variable directly after dired-x is loaded has no effect - | |
120 | use \\[customize]." | |
286c247d | 121 | :type 'boolean |
da5e0ce4 GM |
122 | :set (lambda (sym val) |
123 | (if (set sym val) | |
124 | (define-key dired-mode-map "I" 'dired-info) | |
125 | (if (eq 'dired-info (lookup-key dired-mode-map "I")) | |
126 | (define-key dired-mode-map "I" nil)))) | |
286c247d RS |
127 | :group 'dired-keys) |
128 | ||
129 | (defcustom dired-vm-read-only-folders nil | |
9201cc28 | 130 | "If non-nil, \\[dired-vm] will visit all folders read-only. |
cb3fe1f0 | 131 | If neither nil nor t, e.g. the symbol `if-file-read-only', only |
da5e0ce4 | 132 | files not writable by you are visited read-only." |
286c247d RS |
133 | :type '(choice (const :tag "off" nil) |
134 | (const :tag "on" t) | |
e2c146c1 | 135 | (other :tag "non-writable only" if-file-read-only)) |
286c247d | 136 | :group 'dired-x) |
cb3fe1f0 | 137 | |
ce64e046 LH |
138 | (define-minor-mode dired-omit-mode |
139 | "Toggle Dired-Omit mode. | |
140 | With numeric ARG, enable Dired-Omit mode if ARG is positive, disable | |
6fbad7af | 141 | otherwise. Enabling and disabling is buffer-local. |
ce64e046 | 142 | If enabled, \"uninteresting\" files are not listed. |
cb3fe1f0 | 143 | Uninteresting files are those whose filenames match regexp `dired-omit-files', |
2223a1b3 JL |
144 | plus those ending with extensions in `dired-omit-extensions'. |
145 | ||
146 | To enable omitting in every Dired buffer, you can put in your ~/.emacs | |
147 | ||
148 | (add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1))) | |
149 | ||
150 | See Info node `(dired-x) Omitting Variables' for more information." | |
ce64e046 LH |
151 | :group 'dired-x |
152 | (if dired-omit-mode | |
153 | ;; This will mention how many lines were omitted: | |
154 | (let ((dired-omit-size-limit nil)) (dired-omit-expunge)) | |
155 | (revert-buffer))) | |
156 | ||
157 | ;; For backward compatibility | |
cf24b82d | 158 | (define-obsolete-variable-alias 'dired-omit-files-p 'dired-omit-mode "22.1") |
cb3fe1f0 | 159 | |
99358b97 | 160 | (defcustom dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$" |
9201cc28 | 161 | "Filenames matching this regexp will not be displayed. |
ce64e046 LH |
162 | This only has effect when `dired-omit-mode' is t. See interactive function |
163 | `dired-omit-mode' \(\\[dired-omit-mode]\) and variable | |
99358b97 RS |
164 | `dired-omit-extensions'. The default is to omit `.', `..', auto-save |
165 | files and lock files." | |
286c247d RS |
166 | :type 'regexp |
167 | :group 'dired-x) | |
cb3fe1f0 | 168 | |
f754f898 TH |
169 | (defcustom dired-omit-verbose t |
170 | "When non-nil, show messages when omitting files. | |
171 | When nil, don't show messages." | |
172 | :type 'boolean | |
173 | :group 'dired-x) | |
174 | ||
286c247d | 175 | (defcustom dired-find-subdir nil ; t is pretty near to DWIM... |
9201cc28 | 176 | "If non-nil, Dired always finds a directory in a buffer of its own. |
0a44133e RS |
177 | If nil, Dired finds the directory as a subdirectory in some other buffer |
178 | if it is present as one. | |
cb3fe1f0 | 179 | |
6fbad7af | 180 | If there are several dired buffers for a directory, the most recently |
cb3fe1f0 RS |
181 | used is chosen. |
182 | ||
183 | Dired avoids switching to the current buffer, so that if you have | |
b847eb8c | 184 | a normal and a wildcard buffer for the same directory, \\[dired] will |
286c247d RS |
185 | toggle between those two." |
186 | :type 'boolean | |
187 | :group 'dired-x) | |
188 | ||
8e458944 | 189 | (defcustom dired-omit-size-limit 30000 |
9201cc28 | 190 | "Maximum size for the \"omitting\" feature. |
286c247d RS |
191 | If nil, there is no maximum size." |
192 | :type '(choice (const :tag "no maximum" nil) integer) | |
193 | :group 'dired-x) | |
cb3fe1f0 | 194 | |
286c247d | 195 | (defcustom dired-enable-local-variables t |
9201cc28 | 196 | "Control use of local-variables lists in Dired. |
cb3fe1f0 RS |
197 | The value can be t, nil or something else. |
198 | A value of t means local-variables lists are obeyed; | |
199 | nil means they are ignored; anything else means query. | |
200 | ||
5a0c3f56 JB |
201 | This temporarily overrides the value of `enable-local-variables' when |
202 | listing a directory. See also `dired-local-variables-file'." | |
286c247d RS |
203 | :type 'boolean |
204 | :group 'dired-x) | |
cb3fe1f0 | 205 | |
da5e0ce4 GM |
206 | (defcustom dired-guess-shell-gnutar |
207 | (catch 'found | |
208 | (dolist (exe '("tar" "gtar")) | |
209 | (if (with-temp-buffer | |
210 | (ignore-errors (call-process exe nil t nil "--version")) | |
211 | (and (re-search-backward "GNU tar" nil t) t)) | |
212 | (throw 'found exe)))) | |
9201cc28 | 213 | "If non-nil, name of GNU tar executable. |
b847eb8c DL |
214 | \(E.g., \"tar\" or \"gtar\"). The `z' switch will be used with it for |
215 | compressed or gzip'ed tar files. If you don't have GNU tar, set this | |
286c247d | 216 | to nil: a pipe using `zcat' or `gunzip -c' will be used." |
da5e0ce4 GM |
217 | ;; Changed from system-type test to testing --version output. |
218 | ;; Maybe test --help for -z instead? | |
219 | :version "24.1" | |
b847eb8c DL |
220 | :type '(choice (const :tag "Not GNU tar" nil) |
221 | (string :tag "Command name")) | |
286c247d RS |
222 | :group 'dired-x) |
223 | ||
224 | (defcustom dired-guess-shell-gzip-quiet t | |
9201cc28 | 225 | "Non-nil says pass -q to gzip overriding verbose GZIP environment." |
286c247d RS |
226 | :type 'boolean |
227 | :group 'dired-x) | |
228 | ||
229 | (defcustom dired-guess-shell-znew-switches nil | |
9201cc28 | 230 | "If non-nil, then string of switches passed to `znew', example: \"-K\"." |
b847eb8c DL |
231 | :type '(choice (const :tag "None" nil) |
232 | (string :tag "Switches")) | |
286c247d RS |
233 | :group 'dired-x) |
234 | ||
235 | (defcustom dired-clean-up-buffers-too t | |
9201cc28 | 236 | "Non-nil means offer to kill buffers visiting files and dirs deleted in Dired." |
286c247d RS |
237 | :type 'boolean |
238 | :group 'dired-x) | |
cb3fe1f0 | 239 | |
b578f267 | 240 | ;;; KEY BINDINGS. |
cb3fe1f0 | 241 | |
ce64e046 | 242 | (define-key dired-mode-map "\M-o" 'dired-omit-mode) |
71326638 | 243 | (define-key dired-mode-map "*O" 'dired-mark-omitted) |
cb3fe1f0 | 244 | (define-key dired-mode-map "\M-(" 'dired-mark-sexp) |
582bd36a RS |
245 | (define-key dired-mode-map "*(" 'dired-mark-sexp) |
246 | (define-key dired-mode-map "*." 'dired-mark-extension) | |
cb3fe1f0 | 247 | (define-key dired-mode-map "\M-!" 'dired-smart-shell-command) |
cb3fe1f0 RS |
248 | (define-key dired-mode-map "\M-G" 'dired-goto-subdir) |
249 | (define-key dired-mode-map "F" 'dired-do-find-marked-files) | |
250 | (define-key dired-mode-map "Y" 'dired-do-relsymlink) | |
251 | (define-key dired-mode-map "%Y" 'dired-do-relsymlink-regexp) | |
252 | (define-key dired-mode-map "V" 'dired-do-run-mail) | |
253 | ||
438fc253 LH |
254 | ;;; MENU BINDINGS |
255 | ||
c5ca3aa0 GM |
256 | (require 'easymenu) |
257 | ||
258 | (let ((menu (lookup-key dired-mode-map [menu-bar]))) | |
259 | (easy-menu-add-item menu '("Operate") | |
260 | ["Find Files" dired-do-find-marked-files | |
261 | :help "Find current or marked files"] | |
262 | "Shell Command...") | |
263 | (easy-menu-add-item menu '("Operate") | |
264 | ["Relative Symlink to..." dired-do-relsymlink | |
265 | :visible (fboundp 'make-symbolic-link) | |
266 | :help "Make relative symbolic links for current or \ | |
267 | marked files"] | |
268 | "Hardlink to...") | |
269 | (easy-menu-add-item menu '("Mark") | |
270 | ["Flag Extension..." dired-flag-extension | |
271 | :help "Flag files with a certain extension for deletion"] | |
272 | "Mark Executables") | |
273 | (easy-menu-add-item menu '("Mark") | |
274 | ["Mark Extension..." dired-mark-extension | |
275 | :help "Mark files with a certain extension"] | |
276 | "Unmark All") | |
277 | (easy-menu-add-item menu '("Mark") | |
278 | ["Mark Omitted" dired-mark-omitted | |
279 | :help "Mark files matching `dired-omit-files' \ | |
280 | and `dired-omit-extensions'"] | |
281 | "Unmark All") | |
282 | (easy-menu-add-item menu '("Regexp") | |
283 | ["Relative Symlink..." dired-do-relsymlink-regexp | |
284 | :visible (fboundp 'make-symbolic-link) | |
285 | :help "Make relative symbolic links for files \ | |
286 | matching regexp"] | |
287 | "Hardlink...") | |
288 | (easy-menu-add-item menu '("Immediate") | |
289 | ["Omit Mode" dired-omit-mode | |
290 | :style toggle :selected dired-omit-mode | |
291 | :help "Enable or disable omitting \"uninteresting\" \ | |
292 | files"] | |
293 | "Refresh")) | |
438fc253 | 294 | |
cb3fe1f0 | 295 | \f |
efcb74f6 | 296 | ;; Install into appropriate hooks. |
cb3fe1f0 RS |
297 | |
298 | (add-hook 'dired-mode-hook 'dired-extra-startup) | |
299 | (add-hook 'dired-after-readin-hook 'dired-omit-expunge) | |
300 | ||
301 | (defun dired-extra-startup () | |
6fbad7af | 302 | "Automatically put on `dired-mode-hook' to get extra Dired features: |
cb3fe1f0 | 303 | \\<dired-mode-map> |
cb3fe1f0 RS |
304 | \\[dired-do-run-mail]\t-- run mail on folder (see `dired-bind-vm') |
305 | \\[dired-info]\t-- run info on file | |
306 | \\[dired-man]\t-- run man on file | |
307 | \\[dired-do-find-marked-files]\t-- visit all marked files simultaneously | |
ce64e046 | 308 | \\[dired-omit-mode]\t-- toggle omitting of files |
b847eb8c | 309 | \\[dired-mark-sexp]\t-- mark by Lisp expression |
cb3fe1f0 | 310 | |
da5e0ce4 GM |
311 | To see the options you can set, use M-x customize-group RET dired-x RET. |
312 | See also the functions: | |
b847eb8c DL |
313 | `dired-flag-extension' |
314 | `dired-virtual' | |
315 | `dired-jump' | |
316 | `dired-man' | |
317 | `dired-vm' | |
318 | `dired-rmail' | |
319 | `dired-info' | |
320 | `dired-do-find-marked-files'" | |
cb3fe1f0 RS |
321 | (interactive) |
322 | ||
323 | ;; These must be done in each new dired buffer. | |
324 | (dired-hack-local-variables) | |
325 | (dired-omit-startup)) | |
326 | ||
327 | \f | |
b578f267 | 328 | ;;; BUFFER CLEANING. |
cb3fe1f0 | 329 | |
b578f267 | 330 | ;; REDEFINE. |
cb3fe1f0 | 331 | (defun dired-clean-up-after-deletion (fn) |
b847eb8c DL |
332 | "Clean up after a deleted file or directory FN. |
333 | Remove expanded subdir of deleted dir, if any." | |
cb3fe1f0 RS |
334 | (save-excursion (and (cdr dired-subdir-alist) |
335 | (dired-goto-subdir fn) | |
336 | (dired-kill-subdir))) | |
cb3fe1f0 | 337 | ;; Offer to kill buffer of deleted file FN. |
da5e0ce4 GM |
338 | (when dired-clean-up-buffers-too |
339 | (let ((buf (get-file-buffer fn))) | |
340 | (and buf | |
341 | (funcall (function y-or-n-p) | |
342 | (format "Kill buffer of %s, too? " | |
343 | (file-name-nondirectory fn))) | |
344 | (save-excursion ; you never know where kill-buffer leaves you | |
345 | (kill-buffer buf)))) | |
346 | (let ((buf-list (dired-buffers-for-dir (expand-file-name fn)))) | |
347 | (and buf-list | |
348 | (y-or-n-p (format "Kill dired buffer%s of %s, too? " | |
349 | (dired-plural-s (length buf-list)) | |
350 | (file-name-nondirectory fn))) | |
351 | (dolist (buf buf-list) | |
352 | (save-excursion (kill-buffer buf)))))) | |
9572a9dd | 353 | ;; Anything else? |
cb3fe1f0 RS |
354 | ) |
355 | ||
356 | \f | |
b578f267 | 357 | ;;; EXTENSION MARKING FUNCTIONS. |
cb3fe1f0 | 358 | |
efcb74f6 | 359 | ;; Mark files with some extension. |
cb3fe1f0 | 360 | (defun dired-mark-extension (extension &optional marker-char) |
b847eb8c | 361 | "Mark all files with a certain EXTENSION for use in later commands. |
6fbad7af | 362 | A `.' is *not* automatically prepended to the string entered." |
cb3fe1f0 RS |
363 | ;; EXTENSION may also be a list of extensions instead of a single one. |
364 | ;; Optional MARKER-CHAR is marker to use. | |
365 | (interactive "sMarking extension: \nP") | |
366 | (or (listp extension) | |
367 | (setq extension (list extension))) | |
368 | (dired-mark-files-regexp | |
369 | (concat ".";; don't match names with nothing but an extension | |
370 | "\\(" | |
371 | (mapconcat 'regexp-quote extension "\\|") | |
372 | "\\)$") | |
373 | marker-char)) | |
374 | ||
375 | (defun dired-flag-extension (extension) | |
b847eb8c | 376 | "In dired, flag all files with a certain EXTENSION for deletion. |
cb3fe1f0 RS |
377 | A `.' is *not* automatically prepended to the string entered." |
378 | (interactive "sFlagging extension: ") | |
379 | (dired-mark-extension extension dired-del-marker)) | |
380 | ||
efcb74f6 | 381 | ;; Define some unpopular file extensions. Used for cleaning and omitting. |
cb3fe1f0 RS |
382 | |
383 | (defvar dired-patch-unclean-extensions | |
384 | '(".rej" ".orig") | |
385 | "List of extensions of dispensable files created by the `patch' program.") | |
386 | ||
387 | (defvar dired-tex-unclean-extensions | |
388 | '(".toc" ".log" ".aux");; these are already in completion-ignored-extensions | |
389 | "List of extensions of dispensable files created by TeX.") | |
390 | ||
391 | (defvar dired-latex-unclean-extensions | |
392 | '(".idx" ".lof" ".lot" ".glo") | |
393 | "List of extensions of dispensable files created by LaTeX.") | |
394 | ||
395 | (defvar dired-bibtex-unclean-extensions | |
396 | '(".blg" ".bbl") | |
397 | "List of extensions of dispensable files created by BibTeX.") | |
398 | ||
399 | (defvar dired-texinfo-unclean-extensions | |
400 | '(".cp" ".cps" ".fn" ".fns" ".ky" ".kys" ".pg" ".pgs" | |
401 | ".tp" ".tps" ".vr" ".vrs") | |
402 | "List of extensions of dispensable files created by texinfo.") | |
403 | ||
404 | (defun dired-clean-patch () | |
405 | "Flag dispensable files created by patch for deletion. | |
406 | See variable `dired-patch-unclean-extensions'." | |
407 | (interactive) | |
408 | (dired-flag-extension dired-patch-unclean-extensions)) | |
409 | ||
410 | (defun dired-clean-tex () | |
9572a9dd | 411 | "Flag dispensable files created by [La]TeX etc. for deletion. |
ca388882 | 412 | See variables `dired-tex-unclean-extensions', |
9572a9dd KH |
413 | `dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions' and |
414 | `dired-texinfo-unclean-extensions'." | |
cb3fe1f0 RS |
415 | (interactive) |
416 | (dired-flag-extension (append dired-texinfo-unclean-extensions | |
417 | dired-latex-unclean-extensions | |
418 | dired-bibtex-unclean-extensions | |
419 | dired-tex-unclean-extensions))) | |
420 | ||
9572a9dd KH |
421 | (defun dired-very-clean-tex () |
422 | "Flag dispensable files created by [La]TeX *and* \".dvi\" for deletion. | |
423 | See variables `dired-texinfo-unclean-extensions', | |
424 | `dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions' and | |
425 | `dired-texinfo-unclean-extensions'." | |
cb3fe1f0 | 426 | (interactive) |
9572a9dd KH |
427 | (dired-flag-extension (append dired-texinfo-unclean-extensions |
428 | dired-latex-unclean-extensions | |
429 | dired-bibtex-unclean-extensions | |
430 | dired-tex-unclean-extensions | |
431 | (list ".dvi")))) | |
cb3fe1f0 | 432 | \f |
b578f267 | 433 | ;;; JUMP. |
cb3fe1f0 | 434 | |
40c8b203 | 435 | ;;;###autoload |
f5d6548a | 436 | (defun dired-jump (&optional other-window file-name) |
cb3fe1f0 RS |
437 | "Jump to dired buffer corresponding to current buffer. |
438 | If in a file, dired the current directory and move to file's line. | |
6fbad7af | 439 | If in Dired already, pop up a level and goto old directory's line. |
cb3fe1f0 | 440 | In case the proper dired file line cannot be found, refresh the dired |
f5d6548a JL |
441 | buffer and try again. |
442 | When OTHER-WINDOW is non-nil, jump to dired buffer in other window. | |
443 | Interactively with prefix argument, read FILE-NAME and | |
444 | move to its line in dired." | |
445 | (interactive | |
446 | (list nil (and current-prefix-arg | |
447 | (read-file-name "Jump to dired file: ")))) | |
448 | (let* ((file (or file-name buffer-file-name)) | |
cb3fe1f0 | 449 | (dir (if file (file-name-directory file) default-directory))) |
f5d6548a | 450 | (if (and (eq major-mode 'dired-mode) (null file-name)) |
cb3fe1f0 RS |
451 | (progn |
452 | (setq dir (dired-current-directory)) | |
453 | (dired-up-directory other-window) | |
da5e0ce4 | 454 | (unless (dired-goto-file dir) |
cb3fe1f0 | 455 | ;; refresh and try again |
da5e0ce4 GM |
456 | (dired-insert-subdir (file-name-directory dir)) |
457 | (dired-goto-file dir))) | |
cb3fe1f0 RS |
458 | (if other-window |
459 | (dired-other-window dir) | |
460 | (dired dir)) | |
461 | (if file | |
462 | (or (dired-goto-file file) | |
463 | ;; refresh and try again | |
9572a9dd | 464 | (progn |
cb3fe1f0 | 465 | (dired-insert-subdir (file-name-directory file)) |
7e90bcf5 RS |
466 | (dired-goto-file file)) |
467 | ;; Toggle omitting, if it is on, and try again. | |
da5e0ce4 GM |
468 | (when dired-omit-mode |
469 | (dired-omit-mode) | |
470 | (dired-goto-file file))))))) | |
cb3fe1f0 | 471 | |
f5d6548a | 472 | (defun dired-jump-other-window (&optional file-name) |
6fbad7af | 473 | "Like \\[dired-jump] (`dired-jump') but in other window." |
f5d6548a JL |
474 | (interactive |
475 | (list (and current-prefix-arg | |
476 | (read-file-name "Jump to dired file: ")))) | |
477 | (dired-jump t file-name)) | |
cb3fe1f0 | 478 | \f |
b578f267 | 479 | ;;; OMITTING. |
cb3fe1f0 | 480 | |
efcb74f6 SM |
481 | ;; Enhanced omitting of lines from directory listings. |
482 | ;; Marked files are never omitted. | |
cb3fe1f0 RS |
483 | |
484 | ;; should probably get rid of this and always use 'no-dir. | |
485 | ;; sk 28-Aug-1991 09:37 | |
486 | (defvar dired-omit-localp 'no-dir | |
b847eb8c | 487 | "The LOCALP argument `dired-omit-expunge' passes to `dired-get-filename'. |
6fbad7af | 488 | If it is `no-dir', omitting is much faster, but you can only match |
470fa6d1 KS |
489 | against the non-directory part of the file name. Set it to nil if you |
490 | need to match the entire file name.") | |
cb3fe1f0 RS |
491 | |
492 | ;; \017=^O for Omit - other packages can chose other control characters. | |
493 | (defvar dired-omit-marker-char ?\017 | |
5a0c3f56 | 494 | "Temporary marker used by Dired-Omit. |
cb3fe1f0 RS |
495 | Should never be used as marker by the user or other packages.") |
496 | ||
497 | (defun dired-omit-startup () | |
ce64e046 | 498 | (or (assq 'dired-omit-mode minor-mode-alist) |
cb3fe1f0 | 499 | (setq minor-mode-alist |
ce64e046 | 500 | (append '((dired-omit-mode |
ab606888 GM |
501 | (:eval (if (eq major-mode 'dired-mode) |
502 | " Omit" "")))) | |
503 | minor-mode-alist)))) | |
cb3fe1f0 | 504 | |
ce64e046 LH |
505 | (defun dired-mark-omitted () |
506 | "Mark files matching `dired-omit-files' and `dired-omit-extensions'." | |
507 | (interactive) | |
508 | (let ((dired-omit-mode nil)) (revert-buffer)) ;; Show omitted files | |
509 | (dired-mark-unmarked-files (dired-omit-regexp) nil nil dired-omit-localp)) | |
cb3fe1f0 | 510 | |
461b69ae | 511 | (defcustom dired-omit-extensions |
cb3fe1f0 RS |
512 | (append completion-ignored-extensions |
513 | dired-latex-unclean-extensions | |
514 | dired-bibtex-unclean-extensions | |
515 | dired-texinfo-unclean-extensions) | |
b847eb8c | 516 | "If non-nil, a list of extensions \(strings\) to omit from Dired listings. |
685ff9f8 RS |
517 | Defaults to elements of `completion-ignored-extensions', |
518 | `dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions', and | |
b847eb8c | 519 | `dired-texinfo-unclean-extensions'. |
685ff9f8 | 520 | |
ce64e046 | 521 | See interactive function `dired-omit-mode' \(\\[dired-omit-mode]\) and |
461b69ae GM |
522 | variables `dired-omit-mode' and `dired-omit-files'." |
523 | :type '(repeat string) | |
524 | :group 'dired-x) | |
cb3fe1f0 RS |
525 | |
526 | (defun dired-omit-expunge (&optional regexp) | |
527 | "Erases all unmarked files matching REGEXP. | |
ce64e046 | 528 | Does nothing if global variable `dired-omit-mode' is nil, or if called |
ad8c4554 | 529 | non-interactively and buffer is bigger than `dired-omit-size-limit'. |
cb3fe1f0 RS |
530 | If REGEXP is nil or not specified, uses `dired-omit-files', and also omits |
531 | filenames ending in `dired-omit-extensions'. | |
532 | If REGEXP is the empty string, this function is a no-op. | |
533 | ||
534 | This functions works by temporarily binding `dired-marker-char' to | |
535 | `dired-omit-marker-char' and calling `dired-do-kill-lines'." | |
536 | (interactive "sOmit files (regexp): ") | |
ce64e046 | 537 | (if (and dired-omit-mode |
32226619 | 538 | (or (called-interactively-p 'interactive) |
ad8c4554 | 539 | (not dired-omit-size-limit) |
8e458944 RS |
540 | (< (buffer-size) dired-omit-size-limit) |
541 | (progn | |
f754f898 TH |
542 | (when dired-omit-verbose |
543 | (message "Not omitting: directory larger than %d characters." | |
544 | dired-omit-size-limit)) | |
ce64e046 | 545 | (setq dired-omit-mode nil) |
8e458944 | 546 | nil))) |
cb3fe1f0 | 547 | (let ((omit-re (or regexp (dired-omit-regexp))) |
9b5ef74b | 548 | (old-modified-p (buffer-modified-p)) |
cb3fe1f0 RS |
549 | count) |
550 | (or (string= omit-re "") | |
551 | (let ((dired-marker-char dired-omit-marker-char)) | |
f754f898 | 552 | (when dired-omit-verbose (message "Omitting...")) |
cb3fe1f0 RS |
553 | (if (dired-mark-unmarked-files omit-re nil nil dired-omit-localp) |
554 | (progn | |
f754f898 TH |
555 | (setq count (dired-do-kill-lines |
556 | nil | |
557 | (if dired-omit-verbose "Omitted %d line%s." ""))) | |
048ea441 | 558 | (force-mode-line-update)) |
f754f898 | 559 | (when dired-omit-verbose (message "(Nothing to omit)"))))) |
9b5ef74b RS |
560 | ;; Try to preserve modified state of buffer. So `%*' doesn't appear |
561 | ;; in mode-line of omitted buffers. | |
b847eb8c | 562 | (set-buffer-modified-p (and old-modified-p |
9b5ef74b RS |
563 | (save-excursion |
564 | (goto-char (point-min)) | |
565 | (re-search-forward dired-re-mark nil t)))) | |
cb3fe1f0 RS |
566 | count))) |
567 | ||
568 | (defun dired-omit-regexp () | |
569 | (concat (if dired-omit-files (concat "\\(" dired-omit-files "\\)") "") | |
570 | (if (and dired-omit-files dired-omit-extensions) "\\|" "") | |
571 | (if dired-omit-extensions | |
572 | (concat ".";; a non-extension part should exist | |
573 | "\\(" | |
574 | (mapconcat 'regexp-quote dired-omit-extensions "\\|") | |
575 | "\\)$") | |
576 | ""))) | |
577 | ||
578 | ;; Returns t if any work was done, nil otherwise. | |
579 | (defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp) | |
b847eb8c | 580 | "Mark unmarked files matching REGEXP, displaying MSG. |
470fa6d1 | 581 | REGEXP is matched against the entire file name. |
cb3fe1f0 RS |
582 | Does not re-mark files which already have a mark. |
583 | With prefix argument, unflag all those files. | |
6fbad7af | 584 | Optional fourth argument LOCALP is as in `dired-get-filename'." |
cb3fe1f0 | 585 | (interactive "P") |
6fbad7af | 586 | (let ((dired-marker-char (if unflag-p ?\s dired-marker-char))) |
cb3fe1f0 RS |
587 | (dired-mark-if |
588 | (and | |
589 | ;; not already marked | |
590 | (looking-at " ") | |
591 | ;; uninteresting | |
592 | (let ((fn (dired-get-filename localp t))) | |
593 | (and fn (string-match regexp fn)))) | |
594 | msg))) | |
595 | ||
552939e4 GM |
596 | ;; Compiler does not get fset. |
597 | (declare-function dired-omit-old-add-entry "dired-x") | |
598 | ||
efcb74f6 SM |
599 | ;; REDEFINE. |
600 | ;; Redefine dired-aux.el's version of `dired-add-entry' | |
601 | ;; Save old defun if not already done: | |
552939e4 GM |
602 | (or (fboundp 'dired-omit-old-add-entry) |
603 | (fset 'dired-omit-old-add-entry (symbol-function 'dired-add-entry))) | |
e637bdf8 | 604 | |
efcb74f6 | 605 | ;; REDEFINE. |
c8225cbe | 606 | (defun dired-omit-new-add-entry (filename &optional marker-char relative) |
cb3fe1f0 RS |
607 | ;; This redefines dired-aux.el's dired-add-entry to avoid calling ls for |
608 | ;; files that are going to be omitted anyway. | |
ce64e046 | 609 | (if dired-omit-mode |
cb3fe1f0 RS |
610 | ;; perhaps return t without calling ls |
611 | (let ((omit-re (dired-omit-regexp))) | |
612 | (if (or (string= omit-re "") | |
613 | (not | |
614 | (string-match omit-re | |
615 | (cond | |
616 | ((eq 'no-dir dired-omit-localp) | |
617 | filename) | |
618 | ((eq t dired-omit-localp) | |
619 | (dired-make-relative filename)) | |
620 | (t | |
621 | (dired-make-absolute | |
622 | filename | |
623 | (file-name-directory filename))))))) | |
624 | ;; if it didn't match, go ahead and add the entry | |
c8225cbe | 625 | (dired-omit-old-add-entry filename marker-char relative) |
cb3fe1f0 RS |
626 | ;; dired-add-entry returns t for success, perhaps we should |
627 | ;; return file-exists-p | |
628 | t)) | |
629 | ;; omitting is not turned on at all | |
c8225cbe | 630 | (dired-omit-old-add-entry filename marker-char relative))) |
cb3fe1f0 | 631 | |
cb3fe1f0 RS |
632 | ;; Redefine it. |
633 | (fset 'dired-add-entry 'dired-omit-new-add-entry) | |
634 | ||
635 | \f | |
b578f267 | 636 | ;;; VIRTUAL DIRED MODE. |
cb3fe1f0 | 637 | |
efcb74f6 | 638 | ;; For browsing `ls -lR' listings in a dired-like fashion. |
cb3fe1f0 | 639 | |
6fbad7af | 640 | (defalias 'virtual-dired 'dired-virtual) |
cb3fe1f0 RS |
641 | (defun dired-virtual (dirname &optional switches) |
642 | "Put this buffer into Virtual Dired mode. | |
643 | ||
644 | In Virtual Dired mode, all commands that do not actually consult the | |
645 | filesystem will work. | |
646 | ||
647 | This is useful if you want to peruse and move around in an ls -lR | |
648 | output file, for example one you got from an ftp server. With | |
649 | ange-ftp, you can even dired a directory containing an ls-lR file, | |
650 | visit that file and turn on virtual dired mode. But don't try to save | |
651 | this file, as dired-virtual indents the listing and thus changes the | |
652 | buffer. | |
653 | ||
654 | If you have save a Dired buffer in a file you can use \\[dired-virtual] to | |
655 | resume it in a later session. | |
656 | ||
6fbad7af JB |
657 | Type \\<dired-mode-map>\\[revert-buffer] \ |
658 | in the Virtual Dired buffer and answer `y' to convert | |
659 | the virtual to a real dired buffer again. You don't have to do this, though: | |
660 | you can relist single subdirs using \\[dired-do-redisplay]." | |
cb3fe1f0 RS |
661 | |
662 | ;; DIRNAME is the top level directory of the buffer. It will become | |
663 | ;; its `default-directory'. If nil, the old value of | |
664 | ;; default-directory is used. | |
665 | ||
666 | ;; Optional SWITCHES are the ls switches to use. | |
667 | ||
668 | ;; Shell wildcards will be used if there already is a `wildcard' | |
669 | ;; line in the buffer (thus it is a saved Dired buffer), but there | |
670 | ;; is no other way to get wildcards. Insert a `wildcard' line by | |
671 | ;; hand if you want them. | |
672 | ||
673 | (interactive | |
674 | (list (read-string "Virtual Dired directory: " (dired-virtual-guess-dir)))) | |
675 | (goto-char (point-min)) | |
676 | (or (looking-at " ") | |
677 | ;; if not already indented, do it now: | |
678 | (indent-region (point-min) (point-max) 2)) | |
679 | (or dirname (setq dirname default-directory)) | |
680 | (setq dirname (expand-file-name (file-name-as-directory dirname))) | |
681 | (setq default-directory dirname) ; contains no wildcards | |
682 | (let ((wildcard (save-excursion | |
683 | (goto-char (point-min)) | |
684 | (forward-line 1) | |
685 | (and (looking-at "^ wildcard ") | |
686 | (buffer-substring (match-end 0) | |
da5e0ce4 | 687 | (line-end-position)))))) |
cb3fe1f0 RS |
688 | (if wildcard |
689 | (setq dirname (expand-file-name wildcard default-directory)))) | |
690 | ;; If raw ls listing (not a saved old dired buffer), give it a | |
691 | ;; decent subdir headerline: | |
692 | (goto-char (point-min)) | |
693 | (or (looking-at dired-subdir-regexp) | |
e8425548 | 694 | (insert " " |
fc50a3be MY |
695 | (directory-file-name (file-name-directory default-directory)) |
696 | ":\n")) | |
cb3fe1f0 RS |
697 | (dired-mode dirname (or switches dired-listing-switches)) |
698 | (setq mode-name "Virtual Dired" | |
699 | revert-buffer-function 'dired-virtual-revert) | |
700 | (set (make-local-variable 'dired-subdir-alist) nil) | |
701 | (dired-build-subdir-alist) | |
702 | (goto-char (point-min)) | |
703 | (dired-initial-position dirname)) | |
704 | ||
705 | (defun dired-virtual-guess-dir () | |
b847eb8c | 706 | "Guess and return appropriate working directory of this buffer. |
4e6ef391 | 707 | The buffer is assumed to be in Dired or ls -lR format. The guess is |
b847eb8c DL |
708 | based upon buffer contents. If nothing could be guessed, returns |
709 | nil." | |
cb3fe1f0 RS |
710 | |
711 | (let ((regexp "^\\( \\)?\\([^ \n\r]*\\)\\(:\\)[\n\r]") | |
712 | (subexpr 2)) | |
713 | (goto-char (point-min)) | |
714 | (cond ((looking-at regexp) | |
715 | ;; If a saved dired buffer, look to which dir and | |
716 | ;; perhaps wildcard it belongs: | |
717 | (let ((dir (buffer-substring (match-beginning subexpr) | |
718 | (match-end subexpr)))) | |
719 | (file-name-as-directory dir))) | |
720 | ;; Else no match for headerline found. It's a raw ls listing. | |
721 | ;; In raw ls listings the directory does not have a headerline | |
722 | ;; try parent of first subdir, if any | |
723 | ((re-search-forward regexp nil t) | |
724 | (file-name-directory | |
725 | (directory-file-name | |
726 | (file-name-as-directory | |
727 | (buffer-substring (match-beginning subexpr) | |
728 | (match-end subexpr)))))) | |
729 | (t ; if all else fails | |
730 | nil)))) | |
731 | ||
732 | ||
733 | (defun dired-virtual-revert (&optional arg noconfirm) | |
734 | (if (not | |
735 | (y-or-n-p "Cannot revert a Virtual Dired buffer - switch to Real Dired mode? ")) | |
b847eb8c | 736 | (error "Cannot revert a Virtual Dired buffer") |
cb3fe1f0 RS |
737 | (setq mode-name "Dired" |
738 | revert-buffer-function 'dired-revert) | |
739 | (revert-buffer))) | |
740 | ||
741 | ;; A zero-arg version of dired-virtual. | |
cb3fe1f0 | 742 | (defun dired-virtual-mode () |
6fbad7af | 743 | "Put current buffer into Virtual Dired mode (see `dired-virtual'). |
b94d76ae | 744 | Useful on `magic-mode-alist' with the regexp |
cb3fe1f0 | 745 | |
b94d76ae | 746 | \"^ \\\\(/[^ /]+\\\\)+/?:$\" |
cb3fe1f0 | 747 | |
6fbad7af | 748 | to put saved dired buffers automatically into Virtual Dired mode. |
cb3fe1f0 | 749 | |
b94d76ae | 750 | Also useful for `auto-mode-alist' like this: |
cb3fe1f0 | 751 | |
b94d76ae GM |
752 | (add-to-list 'auto-mode-alist |
753 | '(\"[^/]\\\\.dired\\\\'\" . dired-virtual-mode))" | |
cb3fe1f0 RS |
754 | (interactive) |
755 | (dired-virtual (dired-virtual-guess-dir))) | |
756 | ||
757 | \f | |
b578f267 | 758 | ;;; SMART SHELL. |
cb3fe1f0 | 759 | |
efcb74f6 SM |
760 | ;; An Emacs buffer can have but one working directory, stored in the |
761 | ;; buffer-local variable `default-directory'. A Dired buffer may have | |
762 | ;; several subdirectories inserted, but still has but one working directory: | |
763 | ;; that of the top level Dired directory in that buffer. For some commands | |
764 | ;; it is appropriate that they use the current Dired directory instead of | |
765 | ;; `default-directory', e.g., `find-file' and `compile'. This is a general | |
766 | ;; mechanism is provided for special handling of the working directory in | |
767 | ;; special major modes. | |
cb3fe1f0 | 768 | |
da5e0ce4 GM |
769 | (define-obsolete-variable-alias 'default-directory-alist |
770 | 'dired-default-directory-alist "24.1") | |
771 | ||
cb3fe1f0 RS |
772 | ;; It's easier to add to this alist than redefine function |
773 | ;; default-directory while keeping the old information. | |
da5e0ce4 | 774 | (defconst dired-default-directory-alist |
cb3fe1f0 RS |
775 | '((dired-mode . (if (fboundp 'dired-current-directory) |
776 | (dired-current-directory) | |
777 | default-directory))) | |
b847eb8c DL |
778 | "Alist of major modes and their opinion on `default-directory'. |
779 | This is given as a Lisp expression to evaluate. A resulting value of | |
780 | nil is ignored in favor of `default-directory'.") | |
cb3fe1f0 | 781 | |
b847eb8c DL |
782 | (defun dired-default-directory () |
783 | "Usage like variable `default-directory'. | |
da5e0ce4 GM |
784 | Knows about the special cases in variable `dired-default-directory-alist'." |
785 | (or (eval (cdr (assq major-mode dired-default-directory-alist))) | |
cb3fe1f0 RS |
786 | default-directory)) |
787 | ||
d3a89b9e | 788 | (defun dired-smart-shell-command (command &optional output-buffer error-buffer) |
6fbad7af | 789 | "Like function `shell-command', but in the current Virtual Dired directory." |
d3a89b9e JL |
790 | (interactive |
791 | (list | |
57199d9b JL |
792 | (read-shell-command "Shell command: " nil nil |
793 | (cond | |
794 | (buffer-file-name (file-relative-name buffer-file-name)) | |
795 | ((eq major-mode 'dired-mode) (dired-get-filename t t)))) | |
d3a89b9e JL |
796 | current-prefix-arg |
797 | shell-command-default-error-buffer)) | |
b847eb8c | 798 | (let ((default-directory (dired-default-directory))) |
d3a89b9e | 799 | (shell-command command output-buffer error-buffer))) |
cb3fe1f0 RS |
800 | |
801 | \f | |
b578f267 | 802 | ;;; LOCAL VARIABLES FOR DIRED BUFFERS. |
cb3fe1f0 | 803 | |
efcb74f6 | 804 | ;; Brief Description: |
9572a9dd | 805 | ;;; |
efcb74f6 | 806 | ;; * `dired-extra-startup' is part of the `dired-mode-hook'. |
9572a9dd | 807 | ;;; |
efcb74f6 | 808 | ;; * `dired-extra-startup' calls `dired-hack-local-variables' |
9572a9dd | 809 | ;;; |
efcb74f6 | 810 | ;; * `dired-hack-local-variables' checks the value of |
9572a9dd KH |
811 | ;;; `dired-local-variables-file' |
812 | ;;; | |
efcb74f6 | 813 | ;; * Check if `dired-local-variables-file' is a non-nil string and is a |
cb3fe1f0 | 814 | ;;; filename found in the directory of the Dired Buffer being created. |
9572a9dd | 815 | ;;; |
efcb74f6 | 816 | ;; * If `dired-local-variables-file' satisfies the above, then temporarily |
cb3fe1f0 | 817 | ;;; include it in the Dired Buffer at the bottom. |
9572a9dd | 818 | ;;; |
efcb74f6 | 819 | ;; * Set `enable-local-variables' temporarily to the user variable |
cb3fe1f0 RS |
820 | ;;; `dired-enable-local-variables' and run `hack-local-variables' on the |
821 | ;;; Dired Buffer. | |
822 | ||
461b69ae GM |
823 | ;; FIXME do standard dir-locals obsolete this? |
824 | (defcustom dired-local-variables-file (convert-standard-filename ".dired") | |
cb3fe1f0 RS |
825 | "Filename, as string, containing local dired buffer variables to be hacked. |
826 | If this file found in current directory, then it will be inserted into dired | |
6fbad7af JB |
827 | buffer and `hack-local-variables' will be run. See Info node |
828 | `(emacs)File Variables' for more information on local variables. | |
461b69ae GM |
829 | See also `dired-enable-local-variables'." |
830 | :type 'file | |
831 | :group 'dired) | |
cb3fe1f0 RS |
832 | |
833 | (defun dired-hack-local-variables () | |
834 | "Evaluate local variables in `dired-local-variables-file' for dired buffer." | |
835 | (if (and dired-local-variables-file | |
836 | (stringp dired-local-variables-file) | |
837 | (file-exists-p dired-local-variables-file)) | |
838 | (let ((opoint (point-max)) | |
839 | buffer-read-only | |
840 | ;; In case user has `enable-local-variables' set to nil we | |
841 | ;; override it locally with dired's variable. | |
842 | (enable-local-variables dired-enable-local-variables)) | |
843 | ;; Insert 'em. | |
844 | (save-excursion | |
845 | (goto-char opoint) | |
846 | (insert "\^L\n") | |
847 | (insert-file-contents dired-local-variables-file)) | |
848 | ;; Hack 'em. | |
849 | (let ((buffer-file-name dired-local-variables-file)) | |
850 | (hack-local-variables)) | |
851 | ;; Make sure that the modeline shows the proper information. | |
852 | (dired-sort-set-modeline) | |
853 | ;; Delete this stuff: `eobp' is used to find last subdir by dired.el. | |
9572a9dd | 854 | (delete-region opoint (point-max))))) |
cb3fe1f0 | 855 | |
9572a9dd | 856 | (defun dired-omit-here-always () |
b847eb8c | 857 | "Create `dired-local-variables-file' for omitting and reverts directory. |
6fbad7af | 858 | Sets `dired-omit-mode' to t in a local variables file that is readable by |
cb3fe1f0 | 859 | dired." |
9572a9dd | 860 | (interactive) |
cb3fe1f0 RS |
861 | (if (file-exists-p dired-local-variables-file) |
862 | (message "File `./%s' already exists." dired-local-variables-file) | |
863 | ||
864 | ;; Create `dired-local-variables-file'. | |
efcb74f6 | 865 | (with-current-buffer (get-buffer-create " *dot-dired*") |
cb3fe1f0 | 866 | (erase-buffer) |
ce64e046 | 867 | (insert "Local Variables:\ndired-omit-mode: t\nEnd:\n") |
cb3fe1f0 RS |
868 | (write-file dired-local-variables-file) |
869 | (kill-buffer (current-buffer))) | |
870 | ||
871 | ;; Run extra-hooks and revert directory. | |
872 | (dired-extra-startup) | |
873 | (dired-revert))) | |
874 | ||
875 | \f | |
b578f267 | 876 | ;;; GUESS SHELL COMMAND. |
cb3fe1f0 | 877 | |
efcb74f6 | 878 | ;; Brief Description: |
9572a9dd | 879 | ;;; |
efcb74f6 | 880 | ;; `dired-do-shell-command' is bound to `!' by dired.el. |
9572a9dd | 881 | ;;; |
efcb74f6 | 882 | ;; * Redefine `dired-read-shell-command' so it calls |
cb3fe1f0 | 883 | ;;; `dired-guess-shell-command'. |
9572a9dd | 884 | ;;; |
efcb74f6 | 885 | ;; * `dired-guess-shell-command' calls `dired-guess-default' with list of |
cb3fe1f0 | 886 | ;;; marked files. |
9572a9dd | 887 | ;;; |
efcb74f6 | 888 | ;; * Parse `dired-guess-shell-alist-user' and |
cb3fe1f0 RS |
889 | ;;; `dired-guess-shell-alist-default' (in that order) for the first REGEXP |
890 | ;;; that matches the first file in the file list. | |
9572a9dd | 891 | ;;; |
efcb74f6 | 892 | ;; * If the REGEXP matches all the entries of the file list then evaluate |
c0d79871 | 893 | ;;; COMMAND, which is either a string or a Lisp expression returning a |
cb3fe1f0 | 894 | ;;; string. COMMAND may be a list of commands. |
9572a9dd | 895 | ;;; |
efcb74f6 | 896 | ;; * Return this command to `dired-guess-shell-command' which prompts user |
747e8ee2 | 897 | ;;; with it. The list of commands is put into the list of default values. |
cb3fe1f0 RS |
898 | ;;; If a command is used successfully then it is stored permanently in |
899 | ;;; `dired-shell-command-history'. | |
900 | ||
efcb74f6 | 901 | ;; Guess what shell command to apply to a file. |
cb3fe1f0 RS |
902 | (defvar dired-shell-command-history nil |
903 | "History list for commands that read dired-shell commands.") | |
904 | ||
efcb74f6 | 905 | ;; Default list of shell commands. |
cb3fe1f0 | 906 | |
efcb74f6 SM |
907 | ;; NOTE: Use `gunzip -c' instead of `zcat' on `.gz' files. Some do not |
908 | ;; install GNU zip's version of zcat. | |
cb3fe1f0 | 909 | |
461b69ae GM |
910 | (declare-function Man-support-local-filenames "man" ()) |
911 | ||
cb3fe1f0 RS |
912 | (defvar dired-guess-shell-alist-default |
913 | (list | |
ecd69427 | 914 | (list "\\.tar$" |
ca136496 RF |
915 | '(if dired-guess-shell-gnutar |
916 | (concat dired-guess-shell-gnutar " xvf") | |
917 | "tar xvf") | |
918 | ;; Extract files into a separate subdirectory | |
919 | '(if dired-guess-shell-gnutar | |
920 | (concat "mkdir " (file-name-sans-extension file) | |
921 | "; " dired-guess-shell-gnutar " -C " | |
922 | (file-name-sans-extension file) " -xvf") | |
923 | (concat "mkdir " (file-name-sans-extension file) | |
924 | "; tar -C " (file-name-sans-extension file) " -xvf")) | |
925 | ;; List archive contents. | |
926 | '(if dired-guess-shell-gnutar | |
927 | (concat dired-guess-shell-gnutar " tvf") | |
928 | "tar tvf")) | |
cb3fe1f0 RS |
929 | |
930 | ;; REGEXPS for compressed archives must come before the .Z rule to | |
931 | ;; be recognized: | |
932 | (list "\\.tar\\.Z$" | |
ca136496 RF |
933 | ;; Untar it. |
934 | '(if dired-guess-shell-gnutar | |
935 | (concat dired-guess-shell-gnutar " zxvf") | |
936 | (concat "zcat * | tar xvf -")) | |
937 | ;; Optional conversion to gzip format. | |
938 | '(concat "znew" (if dired-guess-shell-gzip-quiet " -q") | |
939 | " " dired-guess-shell-znew-switches)) | |
cb3fe1f0 RS |
940 | |
941 | ;; gzip'ed archives | |
2f017676 | 942 | (list "\\.t\\(ar\\.\\)?gz$" |
ca136496 RF |
943 | '(if dired-guess-shell-gnutar |
944 | (concat dired-guess-shell-gnutar " zxvf") | |
945 | (concat "gunzip -qc * | tar xvf -")) | |
946 | ;; Extract files into a separate subdirectory | |
947 | '(if dired-guess-shell-gnutar | |
948 | (concat "mkdir " (file-name-sans-extension file) | |
949 | "; " dired-guess-shell-gnutar " -C " | |
950 | (file-name-sans-extension file) " -zxvf") | |
951 | (concat "mkdir " (file-name-sans-extension file) | |
952 | "; gunzip -qc * | tar -C " | |
953 | (file-name-sans-extension file) " -xvf -")) | |
954 | ;; Optional decompression. | |
955 | '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q" "")) | |
956 | ;; List archive contents. | |
957 | '(if dired-guess-shell-gnutar | |
958 | (concat dired-guess-shell-gnutar " ztvf") | |
959 | (concat "gunzip -qc * | tar tvf -"))) | |
ecd69427 | 960 | |
7ba7b794 | 961 | ;; bzip2'ed archives |
ecd69427 | 962 | (list "\\.t\\(ar\\.bz2\\|bz\\)$" |
7ba7b794 | 963 | "bunzip2 -c * | tar xvf -" |
ca136496 RF |
964 | ;; Extract files into a separate subdirectory |
965 | '(concat "mkdir " (file-name-sans-extension file) | |
966 | "; bunzip2 -c * | tar -C " | |
967 | (file-name-sans-extension file) " -xvf -") | |
7ba7b794 | 968 | ;; Optional decompression. |
ca136496 | 969 | "bunzip2") |
cb3fe1f0 | 970 | |
c10e0633 GM |
971 | ;; xz'ed archives |
972 | (list "\\.t\\(ar\\.\\)?xz$" | |
973 | "unxz -c * | tar xvf -" | |
974 | ;; Extract files into a separate subdirectory | |
975 | '(concat "mkdir " (file-name-sans-extension file) | |
976 | "; unxz -c * | tar -C " | |
977 | (file-name-sans-extension file) " -xvf -") | |
978 | ;; Optional decompression. | |
979 | "unxz") | |
980 | ||
ecd69427 JL |
981 | '("\\.shar\\.Z$" "zcat * | unshar") |
982 | '("\\.shar\\.g?z$" "gunzip -qc * | unshar") | |
cb3fe1f0 | 983 | |
85400f54 | 984 | '("\\.e?ps$" "ghostview" "xloadimage" "lpr") |
ecd69427 | 985 | (list "\\.e?ps\\.g?z$" "gunzip -qc * | ghostview -" |
ca136496 RF |
986 | ;; Optional decompression. |
987 | '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q"))) | |
ecd69427 | 988 | (list "\\.e?ps\\.Z$" "zcat * | ghostview -" |
ca136496 RF |
989 | ;; Optional conversion to gzip format. |
990 | '(concat "znew" (if dired-guess-shell-gzip-quiet " -q") | |
991 | " " dired-guess-shell-znew-switches)) | |
ecd69427 | 992 | |
cb3fe1f0 | 993 | '("\\.patch$" "cat * | patch") |
ecd69427 | 994 | (list "\\.patch\\.g?z$" "gunzip -qc * | patch" |
ca136496 RF |
995 | ;; Optional decompression. |
996 | '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q"))) | |
ecd69427 | 997 | (list "\\.patch\\.Z$" "zcat * | patch" |
ca136496 RF |
998 | ;; Optional conversion to gzip format. |
999 | '(concat "znew" (if dired-guess-shell-gzip-quiet " -q") | |
1000 | " " dired-guess-shell-znew-switches)) | |
cb3fe1f0 | 1001 | |
ecd69427 | 1002 | ;; The following four extensions are useful with dired-man ("N" key) |
d2ea84be | 1003 | (list "\\.\\(?:[0-9]\\|man\\)$" '(progn (require 'man) |
ca136496 RF |
1004 | (if (Man-support-local-filenames) |
1005 | "man -l" | |
1006 | "cat * | tbl | nroff -man -h"))) | |
d2ea84be | 1007 | (list "\\.\\(?:[0-9]\\|man\\)\\.g?z$" '(progn (require 'man) |
ca136496 RF |
1008 | (if (Man-support-local-filenames) |
1009 | "man -l" | |
1010 | "gunzip -qc * | tbl | nroff -man -h")) | |
1011 | ;; Optional decompression. | |
1012 | '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q"))) | |
ecd69427 | 1013 | (list "\\.[0-9]\\.Z$" '(progn (require 'man) |
ca136496 RF |
1014 | (if (Man-support-local-filenames) |
1015 | "man -l" | |
1016 | "zcat * | tbl | nroff -man -h")) | |
1017 | ;; Optional conversion to gzip format. | |
1018 | '(concat "znew" (if dired-guess-shell-gzip-quiet " -q") | |
1019 | " " dired-guess-shell-znew-switches)) | |
ecd69427 JL |
1020 | '("\\.pod$" "perldoc" "pod2man * | nroff -man") |
1021 | ||
ca136496 RF |
1022 | '("\\.dvi$" "xdvi" "dvips") ; preview and printing |
1023 | '("\\.au$" "play") ; play Sun audiofiles | |
1024 | '("\\.mpe?g$\\|\\.avi$" "xine -p") | |
70ee5ed1 GM |
1025 | '("\\.ogg$" "ogg123") |
1026 | '("\\.mp3$" "mpg123") | |
ca136496 RF |
1027 | '("\\.wav$" "play") |
1028 | '("\\.uu$" "uudecode") ; for uudecoded files | |
cb3fe1f0 | 1029 | '("\\.hqx$" "mcvert") |
ca136496 RF |
1030 | '("\\.sh$" "sh") ; execute shell scripts |
1031 | '("\\.xbm$" "bitmap") ; view X11 bitmaps | |
cb3fe1f0 | 1032 | '("\\.gp$" "gnuplot") |
85400f54 | 1033 | '("\\.p[bgpn]m$" "xloadimage") |
ca136496 | 1034 | '("\\.gif$" "xloadimage") ; view gif pictures |
85400f54 | 1035 | '("\\.tif$" "xloadimage") |
b847eb8c | 1036 | '("\\.png$" "display") ; xloadimage 4.1 doesn't grok PNG |
ecd69427 | 1037 | '("\\.jpe?g$" "xloadimage") |
ca136496 RF |
1038 | '("\\.fig$" "xfig") ; edit fig pictures |
1039 | '("\\.out$" "xgraph") ; for plotting purposes. | |
cb3fe1f0 RS |
1040 | '("\\.tex$" "latex" "tex") |
1041 | '("\\.texi\\(nfo\\)?$" "makeinfo" "texi2dvi") | |
ca136496 RF |
1042 | '("\\.pdf$" "xpdf") |
1043 | '("\\.doc$" "antiword" "strings") | |
1044 | '("\\.rpm$" "rpm -qilp" "rpm -ivh") | |
1045 | '("\\.dia$" "dia") | |
1046 | '("\\.mgp$" "mgp") | |
cb3fe1f0 RS |
1047 | |
1048 | ;; Some other popular archivers. | |
ca136496 RF |
1049 | (list "\\.zip$" "unzip" "unzip -l" |
1050 | ;; Extract files into a separate subdirectory | |
1051 | '(concat "unzip" (if dired-guess-shell-gzip-quiet " -q") | |
1052 | " -d " (file-name-sans-extension file))) | |
cb3fe1f0 | 1053 | '("\\.zoo$" "zoo x//") |
cb3fe1f0 RS |
1054 | '("\\.lzh$" "lharc x") |
1055 | '("\\.arc$" "arc x") | |
1056 | '("\\.shar$" "unshar") | |
1057 | ||
1058 | ;; Compression. | |
1059 | (list "\\.g?z$" '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q"))) | |
ecd69427 | 1060 | (list "\\.dz$" "dictunzip") |
7ba7b794 | 1061 | (list "\\.bz2$" "bunzip2") |
c10e0633 | 1062 | (list "\\.xz$" "unxz") |
cb3fe1f0 | 1063 | (list "\\.Z$" "uncompress" |
ca136496 RF |
1064 | ;; Optional conversion to gzip format. |
1065 | '(concat "znew" (if dired-guess-shell-gzip-quiet " -q") | |
1066 | " " dired-guess-shell-znew-switches)) | |
1067 | ||
1068 | '("\\.sign?$" "gpg --verify")) | |
9572a9dd | 1069 | |
cb3fe1f0 | 1070 | "Default alist used for shell command guessing. |
b847eb8c | 1071 | See `dired-guess-shell-alist-user'.") |
cb3fe1f0 | 1072 | |
b847eb8c DL |
1073 | (defcustom dired-guess-shell-alist-user nil |
1074 | "User-defined alist of rules for suggested commands. | |
1075 | These rules take precedence over the predefined rules in the variable | |
cb3fe1f0 RS |
1076 | `dired-guess-shell-alist-default' (to which they are prepended). |
1077 | ||
1078 | Each element of this list looks like | |
1079 | ||
1080 | \(REGEXP COMMAND...\) | |
1081 | ||
6fbad7af | 1082 | where each COMMAND can either be a string or a Lisp expression that evaluates |
cb3fe1f0 RS |
1083 | to a string. If several COMMANDs are given, the first one will be the default |
1084 | and the rest will be added temporarily to the history and can be retrieved | |
1085 | with \\[previous-history-element] (M-p) . | |
1086 | ||
70ee5ed1 GM |
1087 | The variable `dired-guess-shell-case-fold-search' controls whether |
1088 | REGEXP is matched case-sensitively. | |
1089 | ||
cb3fe1f0 RS |
1090 | You can set this variable in your ~/.emacs. For example, to add rules for |
1091 | `.foo' and `.bar' files, write | |
1092 | ||
1093 | \(setq dired-guess-shell-alist-user | |
b847eb8c | 1094 | (list (list \"\\\\.foo\\\\'\" \"FOO-COMMAND\");; fixed rule |
cb3fe1f0 | 1095 | ;; possibly more rules ... |
de5af6bb | 1096 | (list \"\\\\.bar\\\\'\";; rule with condition test |
cb3fe1f0 RS |
1097 | '(if condition |
1098 | \"BAR-COMMAND-1\" | |
b847eb8c DL |
1099 | \"BAR-COMMAND-2\")))\)" |
1100 | :group 'dired-x | |
1101 | :type '(alist :key-type regexp :value-type (repeat sexp))) | |
cb3fe1f0 | 1102 | |
d7af463c RF |
1103 | (defcustom dired-guess-shell-case-fold-search t |
1104 | "If non-nil, `dired-guess-shell-alist-default' and | |
1105 | `dired-guess-shell-alist-user' are matched case-insensitively." | |
1106 | :group 'dired-x | |
1107 | :type 'boolean) | |
1108 | ||
cb3fe1f0 | 1109 | (defun dired-guess-default (files) |
b847eb8c DL |
1110 | "Guess a shell commands for FILES. Return command or list of commands. |
1111 | See `dired-guess-shell-alist-user'." | |
cb3fe1f0 | 1112 | |
d7af463c | 1113 | (let* ((case-fold-search dired-guess-shell-case-fold-search) |
cb3fe1f0 RS |
1114 | ;; Prepend the user's alist to the default alist. |
1115 | (alist (append dired-guess-shell-alist-user | |
1116 | dired-guess-shell-alist-default)) | |
1117 | (file (car files)) | |
1118 | (flist (cdr files)) | |
1119 | elt regexp cmds) | |
1120 | ||
1121 | ;; Find the first match in the alist for first file in FILES. | |
1122 | (while alist | |
1123 | (setq elt (car alist) | |
1124 | regexp (car elt) | |
1125 | alist (cdr alist)) | |
1126 | (if (string-match regexp file) | |
1127 | (setq cmds (cdr elt) | |
1128 | alist nil))) | |
1129 | ||
1130 | ;; If more than one file, see if all of FILES match regular expression. | |
1131 | (while (and flist | |
1132 | (string-match regexp (car flist))) | |
1133 | (setq flist (cdr flist))) | |
9572a9dd | 1134 | |
cb3fe1f0 RS |
1135 | ;; If flist is still non-nil, then do not guess since this means that not |
1136 | ;; all the files in FILES were matched by the regexp. | |
1137 | (setq cmds (and (not flist) cmds)) | |
1138 | ||
9572a9dd KH |
1139 | ;; Return commands or nil if flist is still non-nil. |
1140 | ;; Evaluate the commands in order that any logical testing will be done. | |
cb3fe1f0 RS |
1141 | (cond ((not (cdr cmds)) |
1142 | (eval (car cmds))) ; single command | |
1143 | (t | |
1144 | (mapcar (function eval) cmds))))) | |
1145 | ||
1146 | (defun dired-guess-shell-command (prompt files) | |
b847eb8c | 1147 | "Ask user with PROMPT for a shell command, guessing a default from FILES." |
cb3fe1f0 | 1148 | (let ((default (dired-guess-default files)) |
5420b514 | 1149 | default-list val) |
cb3fe1f0 RS |
1150 | (if (null default) |
1151 | ;; Nothing to guess | |
c521381a | 1152 | (read-shell-command prompt nil 'dired-shell-command-history) |
cb3fe1f0 | 1153 | (if (listp default) |
cb3fe1f0 RS |
1154 | ;; More than one guess |
1155 | (setq default-list default | |
1156 | default (car default) | |
1157 | prompt (concat | |
1158 | prompt | |
1159 | (format "{%d guesses} " (length default-list)))) | |
cb3fe1f0 RS |
1160 | ;; Just one guess |
1161 | (setq default-list (list default))) | |
5420b514 JL |
1162 | ;; Put the first guess in the prompt but not in the initial value. |
1163 | (setq prompt (concat prompt (format "[%s] " default))) | |
1164 | ;; All guesses can be retrieved with M-n | |
c521381a JL |
1165 | (setq val (read-shell-command prompt nil |
1166 | 'dired-shell-command-history | |
1167 | default-list)) | |
5420b514 JL |
1168 | ;; If we got a return, then return default. |
1169 | (if (equal val "") default val)))) | |
cb3fe1f0 | 1170 | |
efcb74f6 SM |
1171 | ;; REDEFINE. |
1172 | ;; Redefine dired-aux.el's version: | |
cb3fe1f0 | 1173 | (defun dired-read-shell-command (prompt arg files) |
5a0c3f56 | 1174 | "Read a dired shell command prompting with PROMPT (using `read-shell-command'). |
b847eb8c | 1175 | ARG is the prefix arg and may be used to indicate in the prompt which |
c521381a | 1176 | FILES are affected. |
b847eb8c | 1177 | This is an extra function so that you can redefine it." |
c521381a JL |
1178 | (minibuffer-with-setup-hook |
1179 | (lambda () | |
1180 | (set (make-local-variable 'minibuffer-default-add-function) | |
1181 | 'minibuffer-default-add-dired-shell-commands)) | |
1182 | (dired-mark-pop-up | |
1183 | nil 'shell files | |
1184 | 'dired-guess-shell-command | |
1185 | (format prompt (dired-mark-prompt arg files)) ; PROMPT | |
1186 | files))) ; FILES | |
cb3fe1f0 RS |
1187 | |
1188 | \f | |
b578f267 | 1189 | ;;; RELATIVE SYMBOLIC LINKS. |
cb3fe1f0 | 1190 | |
e8425548 JB |
1191 | (declare-function make-symbolic-link "fileio.c") |
1192 | ||
cb3fe1f0 RS |
1193 | (defvar dired-keep-marker-relsymlink ?S |
1194 | "See variable `dired-keep-marker-move'.") | |
1195 | ||
1196 | (defun dired-make-relative-symlink (file1 file2 &optional ok-if-already-exists) | |
b847eb8c | 1197 | "Make a symbolic link (pointing to FILE1) in FILE2. |
cb3fe1f0 RS |
1198 | The link is relative (if possible), for example |
1199 | ||
1200 | \"/vol/tex/bin/foo\" \"/vol/local/bin/foo\" | |
1201 | ||
1202 | results in | |
1203 | ||
b847eb8c | 1204 | \"../../tex/bin/foo\" \"/vol/local/bin/foo\"" |
cb3fe1f0 RS |
1205 | (interactive "FRelSymLink: \nFRelSymLink %s: \np") |
1206 | (let (name1 name2 len1 len2 (index 0) sub) | |
1207 | (setq file1 (expand-file-name file1) | |
1208 | file2 (expand-file-name file2) | |
1209 | len1 (length file1) | |
1210 | len2 (length file2)) | |
470fa6d1 | 1211 | ;; Find common initial file name components: |
cb3fe1f0 RS |
1212 | (let (next) |
1213 | (while (and (setq next (string-match "/" file1 index)) | |
1214 | (setq next (1+ next)) | |
1215 | (< next (min len1 len2)) | |
1216 | ;; For the comparison, both substrings must end in | |
1217 | ;; `/', so NEXT is *one plus* the result of the | |
1218 | ;; string-match. | |
1219 | ;; E.g., consider the case of linking "/tmp/a/abc" | |
34ff2275 | 1220 | ;; to "/tmp/abc" erroneously giving "/tmp/a" instead |
cb3fe1f0 RS |
1221 | ;; of "/tmp/" as common initial component |
1222 | (string-equal (substring file1 0 next) | |
1223 | (substring file2 0 next))) | |
1224 | (setq index next)) | |
1225 | (setq name2 file2 | |
1226 | sub (substring file1 0 index) | |
1227 | name1 (substring file1 index))) | |
1228 | (if (string-equal sub "/") | |
470fa6d1 | 1229 | ;; No common initial file name found |
cb3fe1f0 RS |
1230 | (setq name1 file1) |
1231 | ;; Else they have a common parent directory | |
1232 | (let ((tem (substring file2 index)) | |
1233 | (start 0) | |
1234 | (count 0)) | |
1235 | ;; Count number of slashes we must compensate for ... | |
1236 | (while (setq start (string-match "/" tem start)) | |
1237 | (setq count (1+ count) | |
1238 | start (1+ start))) | |
1239 | ;; ... and prepend a "../" for each slash found: | |
1240 | (while (> count 0) | |
1241 | (setq count (1- count) | |
1242 | name1 (concat "../" name1))))) | |
1243 | (make-symbolic-link | |
1244 | (directory-file-name name1) ; must not link to foo/ | |
1245 | ; (trailing slash!) | |
1246 | name2 ok-if-already-exists))) | |
1247 | ||
5e5eaeda | 1248 | ;;;###autoload |
cb3fe1f0 | 1249 | (defun dired-do-relsymlink (&optional arg) |
b847eb8c DL |
1250 | "Relative symlink all marked (or next ARG) files into a directory. |
1251 | Otherwise make a relative symbolic link to the current file. | |
cb3fe1f0 RS |
1252 | This creates relative symbolic links like |
1253 | ||
1254 | foo -> ../bar/foo | |
1255 | ||
1256 | not absolute ones like | |
1257 | ||
42496dc8 EZ |
1258 | foo -> /ugly/file/name/that/may/change/any/day/bar/foo |
1259 | ||
4d4238cc | 1260 | For absolute symlinks, use \\[dired-do-symlink]." |
cb3fe1f0 RS |
1261 | (interactive "P") |
1262 | (dired-do-create-files 'relsymlink (function dired-make-relative-symlink) | |
1263 | "RelSymLink" arg dired-keep-marker-relsymlink)) | |
1264 | ||
d8e396ce | 1265 | (defun dired-do-relsymlink-regexp (regexp newname &optional arg whole-name) |
cb3fe1f0 RS |
1266 | "RelSymlink all marked files containing REGEXP to NEWNAME. |
1267 | See functions `dired-do-rename-regexp' and `dired-do-relsymlink' | |
1268 | for more info." | |
1269 | (interactive (dired-mark-read-regexp "RelSymLink")) | |
1270 | (dired-do-create-files-regexp | |
1271 | (function dired-make-relative-symlink) | |
d8e396ce | 1272 | "RelSymLink" arg regexp newname whole-name dired-keep-marker-relsymlink)) |
cb3fe1f0 RS |
1273 | |
1274 | \f | |
b578f267 | 1275 | ;;; VISIT ALL MARKED FILES SIMULTANEOUSLY. |
cb3fe1f0 | 1276 | |
efcb74f6 | 1277 | ;; Brief Description: |
9572a9dd | 1278 | ;;; |
efcb74f6 | 1279 | ;; `dired-do-find-marked-files' is bound to `F' by dired-x.el. |
9572a9dd | 1280 | ;;; |
efcb74f6 | 1281 | ;; * Use `dired-get-marked-files' to collect the marked files in the current |
9572a9dd KH |
1282 | ;;; Dired Buffer into a list of filenames `FILE-LIST'. |
1283 | ;;; | |
efcb74f6 | 1284 | ;; * Pass FILE-LIST to `dired-simultaneous-find-file' all with |
cb3fe1f0 | 1285 | ;;; `dired-do-find-marked-files''s prefix argument NOSELECT. |
9572a9dd | 1286 | ;;; |
efcb74f6 | 1287 | ;; * `dired-simultaneous-find-file' runs through FILE-LIST decrementing the |
cb3fe1f0 | 1288 | ;;; list each time. |
9572a9dd | 1289 | ;;; |
5a0c3f56 | 1290 | ;; * If NOSELECT is non-nil then just run `find-file-noselect' on each |
cb3fe1f0 | 1291 | ;;; element of FILE-LIST. |
9572a9dd | 1292 | ;;; |
efcb74f6 | 1293 | ;; * If NOSELECT is nil then calculate the `size' of the window for each file |
cb3fe1f0 RS |
1294 | ;;; by dividing the `window-height' by length of FILE-LIST. Thus, `size' is |
1295 | ;;; cognizant of the window-configuration. | |
9572a9dd | 1296 | ;;; |
efcb74f6 | 1297 | ;; * If `size' is too small abort, otherwise run `find-file' on each element |
cb3fe1f0 RS |
1298 | ;;; of FILE-LIST giving each a window of height `size'. |
1299 | ||
1300 | (defun dired-do-find-marked-files (&optional noselect) | |
1301 | "Find all marked files displaying all of them simultaneously. | |
1302 | With optional NOSELECT just find files but do not select them. | |
1303 | ||
1304 | The current window is split across all files marked, as evenly as possible. | |
1305 | Remaining lines go to bottom-most window. The number of files that can be | |
1306 | displayed this way is restricted by the height of the current window and | |
1307 | `window-min-height'. | |
1308 | ||
9572a9dd | 1309 | To keep dired buffer displayed, type \\[split-window-vertically] first. |
cb3fe1f0 RS |
1310 | To display just marked files, type \\[delete-other-windows] first." |
1311 | ||
1312 | (interactive "P") | |
1313 | (dired-simultaneous-find-file (dired-get-marked-files) noselect)) | |
1314 | ||
1315 | (defun dired-simultaneous-find-file (file-list noselect) | |
1316 | ||
b847eb8c DL |
1317 | "Visit all files in FILE-LIST and display them simultaneously. |
1318 | The current window is split across all files in FILE-LIST, as evenly as | |
1319 | possible. Remaining lines go to the bottom-most window. The number of | |
1320 | files that can be displayed this way is restricted by the height of the | |
1321 | current window and the variable `window-min-height'. With non-nil | |
1322 | NOSELECT the files are merely found but not selected." | |
9572a9dd | 1323 | |
cb3fe1f0 RS |
1324 | ;; We don't make this function interactive because it is usually too clumsy |
1325 | ;; to specify FILE-LIST interactively unless via dired. | |
1326 | ||
1327 | (let (size) | |
1328 | ||
1329 | (if noselect | |
1330 | ;; Do not select the buffer. | |
1331 | (find-file-noselect (car file-list)) | |
1332 | ||
1333 | ;; We will have to select the buffer. Calculate and check window size. | |
1334 | (setq size (/ (window-height) (length file-list))) | |
1335 | (or (<= window-min-height size) | |
b847eb8c | 1336 | (error "Too many files to visit simultaneously. Try C-u prefix")) |
cb3fe1f0 RS |
1337 | (find-file (car file-list))) |
1338 | ||
1339 | ;; Decrement. | |
1340 | (setq file-list (cdr file-list)) | |
1341 | ||
1342 | (while file-list | |
1343 | ||
1344 | (if noselect | |
1345 | ;; Do not select the buffer. | |
1346 | (find-file-noselect (car file-list)) | |
1347 | ||
1348 | ;; Vertically split off a window of desired size. Upper window will | |
1349 | ;; have SIZE lines. Select lower (larger) window. We split it again. | |
1350 | (select-window (split-window nil size)) | |
1351 | (find-file (car file-list))) | |
1352 | ||
1353 | ;; Decrement. | |
1354 | (setq file-list (cdr file-list))))) | |
1355 | ||
1356 | \f | |
b578f267 | 1357 | ;;; MISCELLANEOUS COMMANDS. |
cb3fe1f0 | 1358 | |
efcb74f6 | 1359 | ;; Run man on files. |
9572a9dd | 1360 | |
461b69ae GM |
1361 | (declare-function Man-getpage-in-background "man" (topic)) |
1362 | ||
cb3fe1f0 | 1363 | (defun dired-man () |
da5e0ce4 GM |
1364 | "Run `man' on this file." |
1365 | ;; Used also to say: "Display old buffer if buffer name matches filename." | |
1366 | ;; but I have no idea what that means. | |
cb3fe1f0 | 1367 | (interactive) |
685ff9f8 | 1368 | (require 'man) |
ecd69427 JL |
1369 | (let* ((file (dired-get-filename)) |
1370 | (manual-program (replace-regexp-in-string "\\*" "%s" | |
1371 | (dired-guess-shell-command | |
1372 | "Man command: " (list file))))) | |
685ff9f8 | 1373 | (Man-getpage-in-background file))) |
cb3fe1f0 | 1374 | |
efcb74f6 | 1375 | ;; Run Info on files. |
cb3fe1f0 RS |
1376 | |
1377 | (defun dired-info () | |
da5e0ce4 | 1378 | "Run `info' on this file." |
cb3fe1f0 RS |
1379 | (interactive) |
1380 | (info (dired-get-filename))) | |
1381 | ||
efcb74f6 | 1382 | ;; Run mail on mail folders. |
cb3fe1f0 | 1383 | |
461b69ae GM |
1384 | (declare-function vm-visit-folder "ext:vm" (folder &optional read-only)) |
1385 | (defvar vm-folder-directory) | |
9572a9dd | 1386 | |
cb3fe1f0 RS |
1387 | (defun dired-vm (&optional read-only) |
1388 | "Run VM on this file. | |
da5e0ce4 GM |
1389 | With optional prefix argument, visits the folder read-only. |
1390 | Otherwise obeys the value of `dired-vm-read-only-folders'." | |
cb3fe1f0 RS |
1391 | (interactive "P") |
1392 | (let ((dir (dired-current-directory)) | |
1393 | (fil (dired-get-filename))) | |
da5e0ce4 GM |
1394 | (vm-visit-folder fil (or read-only |
1395 | (eq t dired-vm-read-only-folders) | |
1396 | (and dired-vm-read-only-folders | |
1397 | (not (file-writable-p fil))))) | |
1398 | ;; So that pressing `v' inside VM does prompt within current directory: | |
cb3fe1f0 RS |
1399 | (set (make-local-variable 'vm-folder-directory) dir))) |
1400 | ||
1401 | (defun dired-rmail () | |
1402 | "Run RMAIL on this file." | |
1403 | (interactive) | |
1404 | (rmail (dired-get-filename))) | |
1405 | ||
1406 | (defun dired-do-run-mail () | |
1407 | "If `dired-bind-vm' is t, then function `dired-vm', otherwise `dired-rmail'." | |
1408 | (interactive) | |
1409 | (if dired-bind-vm | |
1410 | ;; Read mail folder using vm. | |
1411 | (dired-vm) | |
1412 | ;; Read mail folder using rmail. | |
1413 | (dired-rmail))) | |
1414 | ||
1415 | \f | |
b578f267 | 1416 | ;;; MISCELLANEOUS INTERNAL FUNCTIONS. |
cb3fe1f0 | 1417 | |
552939e4 | 1418 | (declare-function dired-old-find-buffer-nocreate "dired-x") |
e637bdf8 | 1419 | |
cb3fe1f0 RS |
1420 | (or (fboundp 'dired-old-find-buffer-nocreate) |
1421 | (fset 'dired-old-find-buffer-nocreate | |
1422 | (symbol-function 'dired-find-buffer-nocreate))) | |
1423 | ||
efcb74f6 SM |
1424 | ;; REDEFINE. |
1425 | ;; Redefines dired.el's version of `dired-find-buffer-nocreate' | |
ac1ce341 | 1426 | (defun dired-find-buffer-nocreate (dirname &optional mode) |
10774fb5 KH |
1427 | (if (and dired-find-subdir |
1428 | ;; don't try to find a wildcard as a subdirectory | |
1429 | (string-equal dirname (file-name-directory dirname))) | |
cb3fe1f0 | 1430 | (let* ((cur-buf (current-buffer)) |
10774fb5 | 1431 | (buffers (nreverse |
12c38283 | 1432 | (dired-buffers-for-dir (expand-file-name dirname)))) |
10774fb5 KH |
1433 | (cur-buf-matches (and (memq cur-buf buffers) |
1434 | ;; wildcards must match, too: | |
1435 | (equal dired-directory dirname)))) | |
1436 | ;; We don't want to switch to the same buffer--- | |
1437 | (setq buffers (delq cur-buf buffers));;need setq with delq | |
1438 | (or (car (sort buffers (function dired-buffer-more-recently-used-p))) | |
1439 | ;; ---unless it's the only possibility: | |
1440 | (and cur-buf-matches cur-buf))) | |
ac1ce341 | 1441 | (dired-old-find-buffer-nocreate dirname mode))) |
cb3fe1f0 RS |
1442 | |
1443 | ;; This should be a builtin | |
1444 | (defun dired-buffer-more-recently-used-p (buffer1 buffer2) | |
da5e0ce4 GM |
1445 | "Return t if BUFFER1 is more recently used than BUFFER2. |
1446 | Considers buffers closer to the car of `buffer-list' to be more recent." | |
1447 | (and (not (equal buffer1 buffer2)) | |
1448 | (memq buffer1 (buffer-list)) | |
1449 | (not (memq buffer1 (memq buffer2 (buffer-list)))))) | |
cb3fe1f0 | 1450 | |
efcb74f6 SM |
1451 | ;; Same thing as `dired-buffers-for-dir' of dired.el? - lrd 11/23/93 |
1452 | ;; (defun dired-buffers-for-dir-exact (dir) | |
1453 | ;; ;; Return a list of buffers that dired DIR (a directory or wildcard) | |
1454 | ;; ;; at top level, or as subdirectory. | |
1455 | ;; ;; Top level matches must match the wildcard part too, if any. | |
1456 | ;; ;; The list is in reverse order of buffer creation, most recent last. | |
1457 | ;; ;; As a side effect, killed dired buffers for DIR are removed from | |
1458 | ;; ;; dired-buffers. | |
1459 | ;; (let ((alist dired-buffers) result elt) | |
1460 | ;; (while alist | |
1461 | ;; (setq elt (car alist) | |
1462 | ;; alist (cdr alist)) | |
1463 | ;; (let ((buf (cdr elt))) | |
1464 | ;; (if (buffer-name buf) | |
1465 | ;; ;; Top level must match exactly against dired-directory in | |
1466 | ;; ;; case one of them is a wildcard. | |
1467 | ;; (if (or (equal dir (with-current-buffer buf dired-directory)) | |
1468 | ;; (assoc dir (with-current-buffer buf dired-subdir-alist))) | |
1469 | ;; (setq result (cons buf result))) | |
1470 | ;; ;; else buffer is killed - clean up: | |
1471 | ;; (setq dired-buffers (delq elt dired-buffers))))) | |
1472 | ;; result)) | |
1473 | ||
1474 | ;; REDEFINE. | |
1475 | ;; Redefines dired.el's version of `dired-initial-position' | |
cb3fe1f0 | 1476 | (defun dired-initial-position (dirname) |
b847eb8c DL |
1477 | "Where point should go in a new listing of DIRNAME. |
1478 | Point assumed at beginning of new subdir line. | |
6fbad7af | 1479 | You may redefine this function as you wish, e.g. like in `dired-x.el'." |
cb3fe1f0 RS |
1480 | (end-of-line) |
1481 | (if dired-find-subdir (dired-goto-subdir dirname)) ; new | |
1482 | (if dired-trivial-filenames (dired-goto-next-nontrivial-file))) | |
1483 | ||
1484 | \f | |
1485 | ;; Does anyone use this? - lrd 6/29/93. | |
44c816da | 1486 | ;; Apparently people do use it. - lrd 12/22/97. |
cb3fe1f0 RS |
1487 | (defun dired-mark-sexp (predicate &optional unflag-p) |
1488 | "Mark files for which PREDICATE returns non-nil. | |
1489 | With a prefix arg, unflag those files instead. | |
1490 | ||
1491 | PREDICATE is a lisp expression that can refer to the following symbols: | |
1492 | ||
1493 | inode [integer] the inode of the file (only for ls -i output) | |
1494 | s [integer] the size of the file for ls -s output | |
34ff2275 | 1495 | (usually in blocks or, with -k, in KByte) |
cb3fe1f0 RS |
1496 | mode [string] file permission bits, e.g. \"-rw-r--r--\" |
1497 | nlink [integer] number of links to file | |
1498 | uid [string] owner | |
1499 | gid [string] group (If the gid is not displayed by ls, | |
1500 | this will still be set (to the same as uid)) | |
1501 | size [integer] file size in bytes | |
1502 | time [string] the time that ls displays, e.g. \"Feb 12 14:17\" | |
1503 | name [string] the name of the file | |
1504 | sym [string] if file is a symbolic link, the linked-to name, else \"\" | |
1505 | ||
1506 | For example, use | |
1507 | ||
1508 | (equal 0 size) | |
1509 | ||
1510 | to mark all zero length files." | |
1511 | ;; Using sym="" instead of nil avoids the trap of | |
1512 | ;; (string-match "foo" sym) into which a user would soon fall. | |
1513 | ;; Give `equal' instead of `=' in the example, as this works on | |
1514 | ;; integers and strings. | |
1515 | (interactive "xMark if (lisp expr): \nP") | |
1516 | (message "%s" predicate) | |
1517 | (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)) | |
1518 | inode s mode nlink uid gid size time name sym) | |
1519 | (dired-mark-if | |
1520 | (save-excursion | |
1521 | (and | |
1522 | ;; Sets vars | |
1523 | ;; inode s mode nlink uid gid size time name sym | |
1524 | ||
1525 | ;; according to current file line. Returns t for success, nil if | |
1526 | ;; there is no file line. Upon success, all variables are set, either | |
1527 | ;; to nil or the appropriate value, so they need not be initialized. | |
1528 | ;; Moves point within the current line. | |
1529 | (if (dired-move-to-filename) | |
1530 | (let (pos | |
1531 | (mode-len 10) ; length of mode string | |
1532 | ;; like in dired.el, but with subexpressions \1=inode, \2=s: | |
1533 | (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?")) | |
1534 | (beginning-of-line) | |
1535 | (forward-char 2) | |
1536 | (if (looking-at dired-re-inode-size) | |
1537 | (progn | |
1538 | (goto-char (match-end 0)) | |
027a4b6b JB |
1539 | (setq inode (string-to-number (buffer-substring (match-beginning 1) |
1540 | (match-end 1))) | |
1541 | s (string-to-number (buffer-substring (match-beginning 2) | |
1542 | (match-end 2))))) | |
cb3fe1f0 RS |
1543 | (setq inode nil |
1544 | s nil)) | |
1545 | (setq mode (buffer-substring (point) (+ mode-len (point)))) | |
1546 | (forward-char mode-len) | |
1547 | (setq nlink (read (current-buffer))) | |
44c816da | 1548 | ;; Karsten Wenger <kw@cis.uni-muenchen.de> fixed uid. |
da5e0ce4 | 1549 | (setq uid (buffer-substring (1+ (point)) |
b847eb8c | 1550 | (progn (forward-word 1) (point)))) |
9bc260cf | 1551 | (re-search-forward directory-listing-before-filename-regexp) |
cb3fe1f0 RS |
1552 | (goto-char (match-beginning 1)) |
1553 | (forward-char -1) | |
027a4b6b JB |
1554 | (setq size (string-to-number (buffer-substring (save-excursion |
1555 | (backward-word 1) | |
1556 | (setq pos (point))) | |
1557 | (point)))) | |
cb3fe1f0 RS |
1558 | (goto-char pos) |
1559 | (backward-word 1) | |
1560 | ;; if no gid is displayed, gid will be set to uid | |
1561 | ;; but user will then not reference it anyway in PREDICATE. | |
b847eb8c DL |
1562 | (setq gid (buffer-substring (save-excursion |
1563 | (forward-word 1) (point)) | |
cb3fe1f0 RS |
1564 | (point)) |
1565 | time (buffer-substring (match-beginning 1) | |
1566 | (1- (dired-move-to-filename))) | |
1567 | name (buffer-substring (point) | |
b847eb8c DL |
1568 | (or |
1569 | (dired-move-to-end-of-filename t) | |
1570 | (point))) | |
cb3fe1f0 RS |
1571 | sym (progn |
1572 | (if (looking-at " -> ") | |
b847eb8c DL |
1573 | (buffer-substring |
1574 | (progn (forward-char 4) (point)) | |
1575 | (progn (end-of-line) (point))) | |
cb3fe1f0 RS |
1576 | ""))) |
1577 | t) | |
1578 | nil) | |
1579 | (eval predicate))) | |
1580 | (format "'%s file" predicate)))) | |
1581 | ||
1582 | \f | |
b578f267 | 1583 | ;;; FIND FILE AT POINT. |
cb3fe1f0 | 1584 | |
461b69ae GM |
1585 | (defcustom dired-x-hands-off-my-keys t |
1586 | "Non-nil means don't bind `dired-x-find-file' over `find-file' on keyboard. | |
ccb1d39a | 1587 | Similarly for `dired-x-find-file-other-window' over `find-file-other-window'. |
461b69ae GM |
1588 | If you change this variable without using \\[customize] after `dired-x.el' |
1589 | is loaded then call \\[dired-x-bind-find-file]." | |
1590 | :type 'boolean | |
1591 | :initialize 'custom-initialize-default | |
1592 | :set (lambda (sym val) | |
1593 | (set sym val) | |
1594 | (dired-x-bind-find-file)) | |
1595 | :group 'dired-x) | |
ccb1d39a | 1596 | |
efcb74f6 SM |
1597 | ;; Bind `dired-x-find-file{-other-window}' over wherever |
1598 | ;; `find-file{-other-window}' is bound? | |
ccb1d39a RS |
1599 | (defun dired-x-bind-find-file () |
1600 | "Bind `dired-x-find-file' in place of `find-file' \(or reverse\). | |
1601 | Similarly for `dired-x-find-file-other-window' and `find-file-other-window'. | |
1602 | Binding direction based on `dired-x-hands-off-my-keys'. | |
6fbad7af | 1603 | This function is part of `after-init-hook'." |
ccb1d39a | 1604 | (interactive) |
32226619 | 1605 | (if (called-interactively-p 'interactive) |
ccb1d39a RS |
1606 | (setq dired-x-hands-off-my-keys |
1607 | (not (y-or-n-p "Bind dired-x-find-file over find-file? ")))) | |
1608 | (cond ((not dired-x-hands-off-my-keys) | |
1609 | (substitute-key-definition 'find-file | |
1610 | 'dired-x-find-file | |
1611 | (current-global-map)) | |
1612 | (substitute-key-definition 'find-file-other-window | |
1613 | 'dired-x-find-file-other-window | |
1614 | (current-global-map))) | |
1615 | (t | |
1616 | (substitute-key-definition 'dired-x-find-file | |
1617 | 'find-file | |
1618 | (current-global-map)) | |
1619 | (substitute-key-definition 'dired-x-find-file-other-window | |
1620 | 'find-file-other-window | |
1621 | (current-global-map)))) | |
1622 | ;; Clear mini-buffer. | |
1623 | (message nil)) | |
1624 | ||
efcb74f6 SM |
1625 | ;; Now call it so binding is correct and put on `after-init-hook' in case |
1626 | ;; user changes binding. | |
ccb1d39a RS |
1627 | (dired-x-bind-find-file) |
1628 | (add-hook 'after-init-hook 'dired-x-bind-find-file) | |
1629 | ||
1630 | (defun dired-x-find-file (filename) | |
1631 | "Edit file FILENAME. | |
1632 | May create a new window, or reuse an existing one. | |
1633 | See the function `display-buffer'. | |
1634 | ||
1635 | Identical to `find-file' except when called interactively, with a prefix arg | |
6fbad7af JB |
1636 | \(e.g., \\[universal-argument]\), in which case it guesses filename near point. |
1637 | Useful for editing file mentioned in buffer you are viewing, | |
1638 | or to test if that file exists. Use minibuffer after snatching filename." | |
da5e0ce4 | 1639 | (interactive (list (dired-x-read-filename-at-point "Find file: "))) |
ccb1d39a RS |
1640 | (find-file (expand-file-name filename))) |
1641 | ||
1642 | (defun dired-x-find-file-other-window (filename) | |
1643 | "Edit file FILENAME, in another window. | |
1644 | May create a new window, or reuse an existing one. | |
1645 | See the function `display-buffer'. | |
1646 | ||
5a0c3f56 JB |
1647 | Identical to `find-file-other-window' except when called interactively, with |
1648 | a prefix arg \(e.g., \\[universal-argument]\), in which case it guesses filename near point. | |
6fbad7af JB |
1649 | Useful for editing file mentioned in buffer you are viewing, |
1650 | or to test if that file exists. Use minibuffer after snatching filename." | |
da5e0ce4 | 1651 | (interactive (list (dired-x-read-filename-at-point "Find file: "))) |
ccb1d39a RS |
1652 | (find-file-other-window (expand-file-name filename))) |
1653 | ||
1654 | ;;; Internal functions. | |
cb3fe1f0 | 1655 | |
1e56daa5 | 1656 | ;; Fixme: This should probably use `thing-at-point'. -- fx |
f53a06c3 | 1657 | (defun dired-filename-at-point () |
b847eb8c | 1658 | "Get the filename closest to point, but do not change position. |
5a0c3f56 JB |
1659 | Has a preference for looking backward when not directly on a symbol. |
1660 | Not perfect - point must be in middle of or end of filename." | |
cb3fe1f0 | 1661 | |
f53a06c3 | 1662 | (let ((filename-chars "-.[:alnum:]_/:$+@") |
6b622862 | 1663 | start end filename prefix) |
cb3fe1f0 RS |
1664 | |
1665 | (save-excursion | |
1666 | ;; First see if just past a filename. | |
da5e0ce4 GM |
1667 | (or (eobp) |
1668 | (when (looking-at "[] \t\n[{}()]") ; whitespace or some parens | |
1669 | (skip-chars-backward " \n\t\r({[]})") | |
1670 | (or (bobp) (backward-char 1)))) | |
cb3fe1f0 RS |
1671 | (if (string-match (concat "[" filename-chars "]") |
1672 | (char-to-string (following-char))) | |
1673 | (progn | |
1e56daa5 DL |
1674 | (if (re-search-backward (concat "[^" filename-chars "]") nil t) |
1675 | (forward-char) | |
1676 | (goto-char (point-min))) | |
cb3fe1f0 | 1677 | (setq start (point)) |
6b622862 | 1678 | (setq prefix |
1e56daa5 DL |
1679 | (and (string-match |
1680 | "^\\w+@" | |
8551cb32 | 1681 | (buffer-substring start (line-end-position))) |
6b622862 GM |
1682 | "/")) |
1683 | (goto-char start) | |
cb3fe1f0 RS |
1684 | (if (string-match "[/~]" (char-to-string (preceding-char))) |
1685 | (setq start (1- start))) | |
1e56daa5 | 1686 | (re-search-forward (concat "\\=[" filename-chars "]*") nil t)) |
cb3fe1f0 RS |
1687 | |
1688 | (error "No file found around point!")) | |
1689 | ||
9572a9dd | 1690 | ;; Return string. |
6b622862 | 1691 | (expand-file-name (concat prefix (buffer-substring start (point))))))) |
cb3fe1f0 | 1692 | |
da5e0ce4 | 1693 | (defun dired-x-read-filename-at-point (prompt) |
b847eb8c DL |
1694 | "Return filename prompting with PROMPT with completion. |
1695 | If `current-prefix-arg' is non-nil, uses name at point as guess." | |
ccb1d39a RS |
1696 | (if current-prefix-arg |
1697 | (let ((guess (dired-filename-at-point))) | |
1698 | (read-file-name prompt | |
1699 | (file-name-directory guess) | |
1700 | guess | |
1701 | nil (file-name-nondirectory guess))) | |
1702 | (read-file-name prompt default-directory))) | |
da5e0ce4 GM |
1703 | |
1704 | (define-obsolete-function-alias 'read-filename-at-point | |
1705 | 'dired-x-read-filename-at-point "24.1") ; is this even needed? | |
cb3fe1f0 | 1706 | \f |
b578f267 | 1707 | ;;; BUG REPORTS |
cb3fe1f0 | 1708 | |
461b69ae | 1709 | (define-obsolete-function-alias 'dired-x-submit-report 'report-emacs-bug "24.1") |
cb3fe1f0 RS |
1710 | |
1711 | \f | |
1712 | ;; As Barry Warsaw would say: "This might be useful..." | |
1713 | (provide 'dired-x) | |
1714 | ||
276f1d00 GM |
1715 | ;; Local Variables: |
1716 | ;; byte-compile-dynamic: t | |
1717 | ;; generated-autoload-file: "dired.el" | |
1718 | ;; End: | |
1719 | ||
cb3fe1f0 | 1720 | ;;; dired-x.el ends here |