X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/717e7a4e8f2f6aa6ae0be33783d208394eef4a0f..f2536958ec711b50a0cf8714defb921193ea8ae4:/lisp/dired-aux.el diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 46d40d2b41..b9111a8d5b 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1,6 +1,6 @@ ;;; dired-aux.el --- less commonly used parts of dired -;; Copyright (C) 1985-1986, 1992, 1994, 1998, 2000-2015 Free Software +;; Copyright (C) 1985-1986, 1992, 1994, 1998, 2000-2016 Free Software ;; Foundation, Inc. ;; Author: Sebastian Kremer . @@ -35,6 +35,7 @@ ;;; Code: +(require 'cl-lib) ;; We need macros in dired.el to compile properly, ;; and we call subroutines in it too. (require 'dired) @@ -921,6 +922,8 @@ ARGS are command switches passed to PROGRAM.") (defvar dired-compress-files-alist '(("\\.tar\\.gz\\'" . "tar -c %i | gzip -c9 > %o") + ("\\.tar\\.bz2\\'" . "tar -c %i | bzip2 -c9 > %o") + ("\\.tar\\.xz\\'" . "tar -c %i | xz -c9 > %o") ("\\.zip\\'" . "zip %o -r --filesync %i")) "Control the compression shell command for `dired-do-compress-to'. @@ -2483,8 +2486,8 @@ Lower levels are unaffected." (cur-dir (dired-current-directory)) (cons (assoc-string cur-dir dired-switches-alist)) buffer-read-only) - (if (equal cur-dir default-directory) - (error "Attempt to kill top level directory")) + (when (equal cur-dir (expand-file-name default-directory)) + (error "Attempt to kill top level directory")) (prog1 (if remember-marks (dired-remember-marks beg end)) (delete-region beg end) @@ -2711,6 +2714,54 @@ with the command \\[tags-loop-continue]." (tags-query-replace from to delimited '(dired-get-marked-files nil nil 'dired-nondirectory-p))) +(declare-function xref--show-xrefs "xref") +(declare-function xref-query-replace-in-results "xref") + +;;;###autoload +(defun dired-do-find-regexp (regexp) + "Find all matches for REGEXP in all marked files. +For any marked directory, all of its files are searched recursively. +However, files matching `grep-find-ignored-files' and subdirectories +matching `grep-find-ignored-directories' are skipped in the marked +directories. + +REGEXP should use constructs supported by your local `grep' command." + (interactive "sSearch marked files (regexp): ") + (require 'grep) + (defvar grep-find-ignored-files) + (defvar grep-find-ignored-directories) + (let* ((files (dired-get-marked-files)) + (ignores (nconc (mapcar + (lambda (s) (concat s "/")) + grep-find-ignored-directories) + grep-find-ignored-files)) + (xrefs (cl-mapcan + (lambda (file) + (xref-collect-matches regexp "*" file + (and (file-directory-p file) + ignores))) + files))) + (unless xrefs + (user-error "No matches for: %s" regexp)) + (xref--show-xrefs xrefs nil t))) + +;;;###autoload +(defun dired-do-find-regexp-and-replace (from to) + "Replace matches of FROM with TO, in all marked files. +For any marked directory, matches in all of its files are replaced, +recursively. However, files matching `grep-find-ignored-files' +and subdirectories matching `grep-find-ignored-directories' are skipped +in the marked directories. + +REGEXP should use constructs supported by your local `grep' command." + (interactive + (let ((common + (query-replace-read-args + "Query replace regexp in marked files" t t))) + (list (nth 0 common) (nth 1 common)))) + (with-current-buffer (dired-do-find-regexp from) + (xref-query-replace-in-results from to))) + (defun dired-nondirectory-p (file) (not (file-directory-p file)))