git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Teach git.el to mark/unmark files by regexp

From
David Christensen <david@endpoint.com>
Date
Aug 27, 2008, 03:24 UTC
Message-ID
<1219807480-57122-1-git-send-email-david@endpoint.com>

Adds the functions git-mark-regexp and git-unmark-regexp to git.el. Creates a mark-map keymap to support dired-like behavior for marking/unmarking via regexp. Also adds these functions to the menubar.

Signed-off-by: David Christensen <david@endpoint.com>
---
 contrib/emacs/git.el |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index c1cf1cb..279610f 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -944,6 +944,27 @@ Return the list of files that haven't been handled."
   ; move back to goal column after invalidate
   (when goal-column (move-to-column goal-column)))
 
+(defun git-mark-regexp (re)
+  "Mark all files which match a provided regexp."
+  (interactive "sMark files matching regular expression: ")
+  (unless git-status (error "Not in git-status buffer."))
+  (ewoc-map (lambda (info) (unless (git-fileinfo->marked info)
+                             (when (string-match re (git-fileinfo->name info))
+                               (setf (git-fileinfo->marked info) t)))) git-status)
+  ; move back to goal column after invalidate
+  (when goal-column (move-to-column goal-column)))
+
+(defun git-unmark-regexp (re)
+  "Unmark all files which match a provided regexp."
+  (interactive "sUnmark files matching regular expression: ")
+  (unless git-status (error "Not in git-status buffer."))
+  (ewoc-map (lambda (info) (when (git-fileinfo->marked info)
+                             (when (string-match re (git-fileinfo->name info))
+                               (setf (git-fileinfo->marked info) nil)) t)) git-status)
+  ; move back to goal column after invalidate
+  (when goal-column (move-to-column goal-column)))
+
+
 (defun git-toggle-all-marks ()
   "Toggle all file marks."
   (interactive)
@@ -1420,9 +1441,11 @@ amended version of it."
   (let ((map (make-keymap))
         (commit-map (make-sparse-keymap))
         (diff-map (make-sparse-keymap))
-        (toggle-map (make-sparse-keymap)))
+        (toggle-map (make-sparse-keymap))
+        (mark-map (make-sparse-keymap)))
     (suppress-keymap map)
     (define-key map "?"   'git-help)
+    (define-key map "*"    mark-map)
     (define-key map "h"   'git-help)
     (define-key map " "   'git-next-file)
     (define-key map "a"   'git-add-file)
@@ -1469,6 +1492,9 @@ amended version of it."
     (define-key toggle-map "i" 'git-toggle-show-ignored)
     (define-key toggle-map "k" 'git-toggle-show-unknown)
     (define-key toggle-map "m" 'git-toggle-all-marks)
+    ; the mark submap
+    (define-key mark-map "%" 'git-mark-regexp)
+    (define-key mark-map "\C-?" 'git-unmark-regexp)
     (setq git-status-mode-map map))
   (easy-menu-define git-menu git-status-mode-map
     "Git Menu"
@@ -1499,8 +1525,10 @@ amended version of it."
       "--------"
       ["Mark" git-mark-file t]
       ["Mark All" git-mark-all t]
+      ["Mark Regexp" git-mark-regexp t]
       ["Unmark" git-unmark-file t]
       ["Unmark All" git-unmark-all t]
+      ["Unmark Regexp" git-unmark-regexp t]
       ["Toggle All Marks" git-toggle-all-marks t]
       ["Hide Handled Files" git-remove-handled t]
       "--------"
-- 
1.6.0.1.90.g27a6e.dirty
Next: Alexandre Julliard
Message 1 of 5 in “Teach git.el to mark/unmark files by regexp”
  1. Teach git.el to mark/unmark files by regexpDavid Christensen, Aug 27, 2008
  2. Alexandre JulliardAug 30, 2008
  3. David ChristensenAug 30, 2008
  4. Teach git.el to mark/unmark files by regexpDavid Christensen, Sep 12, 2008
  5. Teach git.el to mark/unmark files by regexpDavid Christensen, Sep 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.