From d373daf568cd45153d842de49288eb424e5b32e9 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 11 May 2022 14:59:17 +0200 Subject: [PATCH] Add new command 'vc-dir-mark-by-regexp' * doc/emacs/maintaining.texi (VC Directory Commands): Document it. * lisp/vc/vc-dir.el (vc-dir-mode-map): Bind it to `%'. (vc-dir-mark-by-regexp): New command (bug#16460). --- doc/emacs/maintaining.texi | 6 ++++++ etc/NEWS | 5 +++++ lisp/vc/vc-dir.el | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index cca8441daa5..3ddea0ae588 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -1316,6 +1316,12 @@ point is on a directory entry, mark all files in that directory tree (@code{vc-dir-mark-all-files}). With a prefix argument, mark all listed files and directories. +@findex vc-dir-mark-by-regexp +@item % +You can use this command to mark files by regexp +(@code{vc-dir-mark-by-regexp}). If given a prefix, unmark files +instead. + @item G Add the file under point to the list of files that the VC should ignore (@code{vc-dir-ignore}). For instance, if the VC is Git, it diff --git a/etc/NEWS b/etc/NEWS index 9e985de0b39..68c7490e56c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1009,6 +1009,11 @@ info node. This command only works for the Emacs and Emacs Lisp manuals. ** vc ++++ +*** New command '%' ('vc-dir-mark-by-regexp'). +This command marks files based on a regexp. If given a prefix +argument, unmark instead. + --- *** 'C-x v v' on an unregistered file will now use the most specific backend. Previously, if you had an SVN-covered "~/" directory, and a Git-covered diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el index 1545763a3a1..9335da10065 100644 --- a/lisp/vc/vc-dir.el +++ b/lisp/vc/vc-dir.el @@ -325,6 +325,7 @@ See `run-hooks'." (define-key map "U" #'vc-dir-unmark-all-files) (define-key map "\C-?" #'vc-dir-unmark-file-up) (define-key map "\M-\C-?" #'vc-dir-unmark-all-files) + (define-key map "%" #'vc-dir-mark-by-regexp) ;; Movement. (define-key map "n" #'vc-dir-next-line) (define-key map " " #'vc-dir-next-line) @@ -750,6 +751,23 @@ share the same state." (vc-dir-mark-file crt))) (setq crt (ewoc-next vc-ewoc crt)))))))) +(defun vc-dir-mark-by-regexp (regexp &optional unmark) + "Mark all files that match REGEXP. +If UNMARK (interactively, the prefix), unmark instead." + (interactive "sMark files matching: \nP") + (ewoc-map + (lambda (filearg) + (when (and (not (vc-dir-fileinfo->directory filearg)) + (eq (not unmark) + (not (vc-dir-fileinfo->marked filearg))) + ;; We don't want to match on the part of the file + ;; that's above the current directory. + (string-match-p regexp (file-relative-name + (vc-dir-fileinfo->name filearg)))) + (setf (vc-dir-fileinfo->marked filearg) (not unmark)) + t)) + vc-ewoc)) + (defun vc-dir-mark-files (mark-files) "Mark files specified by file names in the argument MARK-FILES. MARK-FILES should be a list of absolute filenames." -- 2.39.2