emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d373daf568: Add new command 'vc-dir-mark-by-regexp'


From: Lars Ingebrigtsen
Subject: master d373daf568: Add new command 'vc-dir-mark-by-regexp'
Date: Wed, 11 May 2022 08:59:34 -0400 (EDT)

branch: master
commit d373daf568cd45153d842de49288eb424e5b32e9
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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 cca8441daa..3ddea0ae58 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 9e985de0b3..68c7490e56 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 1545763a3a..9335da1006 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."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]