;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*-
-;; Copyright (C) 1985-1986, 1992-1997, 2000-2015 Free Software
+;; Copyright (C) 1985-1986, 1992-1997, 2000-2016 Free Software
;; Foundation, Inc.
;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
:version "24.4"
:group 'dired)
+(defcustom dired-always-read-filesystem nil
+ "Non-nil means revert buffers visiting files before searching them.
+ By default, commands like `dired-mark-files-containing-regexp' will
+ search any buffers visiting the marked files without reverting them,
+ even if they were changed on disk. When this option is non-nil, such
+ buffers are always reverted in a temporary buffer before searching
+ them: the search is performed on the temporary buffer, the original
+ buffer visiting the file is not modified."
+ :type 'boolean
+ :version "25.2"
+ :group 'dired)
+
;; Internal variables
(defvar dired-marker-char ?* ; the answer is 42
(put 'dired-actual-switches 'safe-local-variable 'dired-safe-switches-p)
-(defvar dired-re-inode-size "[0-9 \t]*"
+(defvar dired-re-inode-size "[0-9 \t]*[.,0-9]*[BkKMGTPEZY]?[ \t]*"
"Regexp for optional initial inode and file size as made by `ls -i -s'.")
;; These regexps must be tested at beginning-of-line, but are also
(define-key map "." 'dired-clean-directory)
(define-key map "~" 'dired-flag-backup-files)
;; Upper case keys (except !) for operating on the marked files
- (define-key map "A" 'dired-do-search)
+ (define-key map "A" 'dired-do-find-regexp)
(define-key map "C" 'dired-do-copy)
(define-key map "B" 'dired-do-byte-compile)
(define-key map "D" 'dired-do-delete)
(define-key map "M" 'dired-do-chmod)
(define-key map "O" 'dired-do-chown)
(define-key map "P" 'dired-do-print)
- (define-key map "Q" 'dired-do-query-replace-regexp)
+ (define-key map "Q" 'dired-do-find-regexp-and-replace)
(define-key map "R" 'dired-do-rename)
(define-key map "S" 'dired-do-symlink)
(define-key map "T" 'dired-do-touch)
(save-excursion
(goto-char (point-min))
(dired-goto-file-1 file file (point-max)))
- ;; Otherwise, look for it as a relative name. The
- ;; hair is to get the result of `dired-goto-subdir'
- ;; without calling it if we don't have any subdirs.
+ ;; Next, look for it as a relative name with leading
+ ;; subdirectories. (This happens in Dired buffers
+ ;; created by find-dired, for example.)
+ (save-excursion
+ (goto-char (point-min))
+ (dired-goto-file-1 (file-relative-name file
+ default-directory)
+ file (point-max)))
+ ;; Otherwise, look for it as a relative name, a base
+ ;; name only. The hair is to get the result of
+ ;; `dired-goto-subdir' without calling it if we don't
+ ;; have any subdirs.
(save-excursion
(when (if (string= dir (expand-file-name default-directory))
(goto-char (point-min))
(defun dired-current-directory (&optional localp)
"Return the name of the subdirectory to which this line belongs.
This returns a string with trailing slash, like `default-directory'.
-Optional argument means return a file name relative to `default-directory'."
+Optional argument means return a file name relative to `default-directory',
+in which case the value could be an empty string if `default-directory'
+is the directory where the file on this line resides."
(let ((here (point))
(alist (or dired-subdir-alist
;; probably because called in a non-dired buffer
(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
"Mark all files with contents containing REGEXP for use in later commands.
A prefix argument means to unmark them instead.
-`.' and `..' are never marked."
+`.' and `..' are never marked.
+
+Note that if a file is visited in an Emacs buffer, and
+`dired-always-read-filesystem' is nil, this command will
+look in the buffer without revisiting the file, so the results might
+be inconsistent with the file on disk if its contents has changed
+since it was last visited."
(interactive
(list (read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
" files containing (regexp): ")
(message "Checking %s" fn)
;; For now we do it inside emacs
;; Grep might be better if there are a lot of files
- (if prebuf
+ (if (and prebuf (not dired-always-read-filesystem))
(with-current-buffer prebuf
(save-excursion
(goto-char (point-min))