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

[StGit PATCH 16/17] Emacs mode: Add mark command

From
David Kågedal <davidk@lysator.liu.se>
Date
Dec 14, 2007, 10:59 UTC
Message-ID
<20071214105928.18066.94814.stgit@krank>
In-Reply-To
<20071214105238.18066.23281.stgit@krank>
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
---
 contrib/stgit.el |   76 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 57 insertions(+), 19 deletions(-)
diff --git a/contrib/stgit.el b/contrib/stgit.el
index 1cb4dd2..dfbf4a0 100644
--- a/contrib/stgit.el
+++ b/contrib/stgit.el
@@ -70,7 +70,7 @@ Argument DIR is the repository path."
     (insert "Branch: ")
     (stgit-run "branch")
     (stgit-run "series" "--description")
-    (stgit-rehighlight (point-min) (point-max))
+    (stgit-rescan)
     (if curpatch
         (stgit-goto-patch curpatch)
       (goto-line curline))))
@@ -98,23 +98,30 @@ Argument DIR is the repository path."
     (t ()))
   "The face used for unapplied patch names")
 
-(defun stgit-rehighlight (start end)
-  "Refresh fontification of region between START and END."
+(defun stgit-rescan ()
+  "Rescan the status buffer."
   (save-excursion
-    (goto-char start)
-    (while (< (point) end)
-      (cond ((looking-at "Branch: \\(.*\\)")
-             (put-text-property (match-beginning 1) (match-end 1) 'face 'bold))
-            ((looking-at "\\([>+-]\\) \\([^ ]+\\) *| \\(.*\\)")
-             (let ((state (match-string 1)))
-               (put-text-property
-                (match-beginning 2) (match-end 2)
-                'face (cond ((string= state ">") 'stgit-top-patch-face)
-                            ((string= state "+") 'stgit-applied-patch-face)
-                            ((string= state "-") 'stgit-unapplied-patch-face)))
-               (put-text-property (match-beginning 3) (match-end 3)
-                                  'face 'stgit-description-face))))
-      (forward-line 1))))
+    (let ((marked ()))
+      (goto-char (point-min))
+      (while (not (eobp))
+        (cond ((looking-at "Branch: \\(.*\\)")
+               (put-text-property (match-beginning 1) (match-end 1)
+                                  'face 'bold))
+              ((looking-at "\\([>+-]\\)\\( \\)\\([^ ]+\\) *| \\(.*\\)")
+               (let ((state (match-string 1))
+                     (patchsym (intern (match-string 3))))
+                 (put-text-property
+                  (match-beginning 3) (match-end 3) 'face
+                  (cond ((string= state ">") 'stgit-top-patch-face)
+                        ((string= state "+") 'stgit-applied-patch-face)
+                        ((string= state "-") 'stgit-unapplied-patch-face)))
+                 (put-text-property (match-beginning 4) (match-end 4)
+                                    'face 'stgit-description-face)
+                 (when (memq patchsym stgit-marked-patches)
+                   (replace-match "*" nil nil nil 2)
+                   (setq marked (cons patchsym marked))))))
+        (forward-line 1))
+      (setq stgit-marked-patches (nreverse marked)))))
 
 (defvar stgit-mode-hook nil
   "Run after `stgit-mode' is setup.")
@@ -125,6 +132,8 @@ Argument DIR is the repository path."
 (unless stgit-mode-map
   (setq stgit-mode-map (make-keymap))
   (suppress-keymap stgit-mode-map)
+  (define-key stgit-mode-map " "   'stgit-mark)
+  (define-key stgit-mode-map "\d" 'stgit-unmark)
   (define-key stgit-mode-map "?"   'stgit-help)
   (define-key stgit-mode-map "h"   'stgit-help)
   (define-key stgit-mode-map "p"   'previous-line)
@@ -153,14 +162,27 @@ Commands:
         goal-column 2)
   (use-local-map stgit-mode-map)
   (set (make-local-variable 'list-buffers-directory) default-directory)
+  (set (make-local-variable 'stgit-marked-patches) nil)
   (set-variable 'truncate-lines 't)
   (run-hooks 'stgit-mode-hook))
 
+(defun stgit-add-mark (patch)
+  (let ((patchsym (intern patch)))
+    (setq stgit-marked-patches (cons patchsym stgit-marked-patches))))
+
+(defun stgit-remove-mark (patch)
+  (let ((patchsym (intern patch)))
+    (setq stgit-marked-patches (delq patchsym stgit-marked-patches))))
+
+(defun stgit-marked-patches ()
+  "Return the names of the marked patches."
+  (mapcar 'symbol-name stgit-marked-patches))
+
 (defun stgit-patch-at-point ()
   "Return the patch name on the current line"
   (save-excursion
     (beginning-of-line)
-    (if (looking-at "[>+-] \\([^ ]*\\)")
+    (if (looking-at "[>+-][ *]\\([^ ]*\\)")
         (match-string-no-properties 1)
       nil)))
 
@@ -168,12 +190,28 @@ Commands:
   "Move point to the line containing PATCH"
   (let ((p (point)))
     (goto-char (point-min))
-    (if (re-search-forward (concat "[>+-] " (regexp-quote patch) " ") nil t)
+    (if (re-search-forward (concat "^[>+-][ *]" (regexp-quote patch) " ") nil t)
         (progn (move-to-column goal-column)
                t)
       (goto-char p)
       nil)))
 
+(defun stgit-mark ()
+  "Mark the patch under point"
+  (interactive)
+  (let ((patch (stgit-patch-at-point)))
+    (stgit-add-mark patch)
+    (stgit-refresh))
+  (next-line))
+
+(defun stgit-unmark ()
+  "Mark the patch on the previous line"
+  (interactive)
+  (forward-line -1)
+  (let ((patch (stgit-patch-at-point)))
+    (stgit-remove-mark patch)
+    (stgit-refresh)))
+
 (defun stgit-rename (name)
   "Rename the patch under point"
   (interactive (list (read-string "Patch name: " (stgit-patch-at-point))))
Previous: David KågedalNext: David Kågedal
Message 17 of 57 in “Series short description”
  1. 00/17 Series short descriptionDavid Kågedal, Dec 14, 2007
  2. 01/17 Add an StGit mode for emacsDavid Kågedal, Dec 14, 2007
  3. 02/17 Emacs mode: Show keybindings when user presses "h" or "?"David Kågedal, Dec 14, 2007
  4. 03/17 Emacs mode: Add an explanatory headerDavid Kågedal, Dec 14, 2007
  5. 04/17 Emacs mode: Makefile for building stgit.elDavid Kågedal, Dec 14, 2007
  6. 05/17 Emacs mode: push/pop next patch, not patch at pointDavid Kågedal, Dec 14, 2007
  7. 06/17 Emacs mode: Let "P" push or pop patch at pointDavid Kågedal, Dec 14, 2007
  8. 07/17 Emacs mode: Bind "G" to "stg goto"David Kågedal, Dec 14, 2007
  9. 08/17 Emacs mode: show patches' short descriptionDavid Kågedal, Dec 14, 2007
  10. 09/17 Emacs mode: Improve the output buffer stateDavid Kågedal, Dec 14, 2007
  11. 10/17 Emacs mode: Bind n and pDavid Kågedal, Dec 14, 2007
  12. 11/17 Emacs mode: add stgit-repairDavid Kågedal, Dec 14, 2007
  13. 12/17 Emacs mode: added stgit-commit and stgit-uncommitDavid Kågedal, Dec 14, 2007
  14. 13/17 Emacs mode: Add stgit-edit commandDavid Kågedal, Dec 14, 2007
  15. 14/17 Emacs mode: added fontificationDavid Kågedal, Dec 14, 2007
  16. 15/17 Emacs mode: Added stgit-newDavid Kågedal, Dec 14, 2007
  17. 16/17 Emacs mode: Add mark commandDavid Kågedal, Dec 14, 2007
  18. 17/17 Emacs mode: coalesce commandDavid Kågedal, Dec 14, 2007
  19. Catalin MarinasDec 17, 2007
  20. Karl HasselströmDec 17, 2007
  21. kha/safe and kha/experimental updatedKarl Hasselström, Dec 18, 2007
  22. Catalin MarinasDec 18, 2007
  23. Jakub NarebskiDec 18, 2007
  24. Catalin MarinasDec 18, 2007
  25. David KågedalDec 19, 2007
  26. David KågedalDec 19, 2007
  27. Catalin MarinasDec 19, 2007
  28. Karl HasselströmDec 19, 2007
  29. Jakub NarebskiDec 19, 2007
  30. Karl HasselströmDec 19, 2007
  31. Catalin MarinasDec 19, 2007
  32. Jakub NarebskiDec 19, 2007
  33. Catalin MarinasDec 19, 2007
  34. David KågedalDec 19, 2007
  35. Karl HasselströmDec 19, 2007
  36. Karl HasselströmDec 19, 2007
  37. Catalin MarinasDec 19, 2007
  38. Karl HasselströmDec 19, 2007
  39. Catalin MarinasDec 19, 2007
  40. Karl HasselströmDec 19, 2007
  41. Catalin MarinasDec 19, 2007
  42. Catalin MarinasDec 19, 2007
  43. David KågedalDec 19, 2007
  44. Catalin MarinasDec 18, 2007
  45. David KågedalDec 18, 2007
  46. Karl HasselströmDec 18, 2007
  47. 0/2 Make new infrastructure subdirectory safeKarl Hasselström, Dec 19, 2007
  48. 1/2 Test that "stg goto" can be called from a subdirectoryKarl Hasselström, Dec 19, 2007
  49. 2/2 Make "stg goto" subdirectory safeKarl Hasselström, Dec 19, 2007
  50. kha/safe updatedKarl Hasselström, Dec 19, 2007
  51. Catalin MarinasDec 19, 2007
  52. Karl HasselströmDec 19, 2007
  53. Catalin MarinasDec 19, 2007
  54. Karl HasselströmDec 20, 2007
  55. David KågedalDec 19, 2007
  56. Karl HasselströmDec 20, 2007
  57. Karl HasselströmDec 19, 2007

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.