guix-commits
[Top][All Lists]
Advanced

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

05/05: snippets: Fix move.


From: guix-commits
Subject: 05/05: snippets: Fix move.
Date: Thu, 6 Oct 2022 15:18:25 -0400 (EDT)

lilyp pushed a commit to branch master
in repository guix.

commit 5e63e51afee0f674ff2ac961e3103011f53035cd
Author: Liliana Marie Prikler <liliana.prikler@gmail.com>
AuthorDate: Thu Oct 6 21:09:43 2022 +0200

    snippets: Fix move.
    
    The current move is never correct.  It flip-flops between car and cadr for
    the destination.  Since the position of the destination is not actually a
    fixed point in the list of changes, use a more robust method of inferring 
it.
    
    * etc/snippets/tempel/text-mode (move\ ): Infer source and destination from
    washed diffs.  Process new module before destination.
---
 etc/snippets/tempel/text-mode | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/etc/snippets/tempel/text-mode b/etc/snippets/tempel/text-mode
index da72b29d3c..364c21266d 100644
--- a/etc/snippets/tempel/text-mode
+++ b/etc/snippets/tempel/text-mode
@@ -122,12 +122,34 @@ text-mode :when (and (fboundp 'git-commit-mode) 
(git-commit-mode))
                                      nil 'noerror)
               (match-string-no-properties 1)))
           var)
-       ": Move to "
-       (concat "("
-               (string-replace "\.scm" ""
-                               (string-replace "/" " "
-                                               (car (magit-staged-files))))
-               ").")
+       ": Move to ("
+       (p (with-temp-buffer
+            (magit-git-wash #'magit-diff-wash-diffs
+              "diff" "--staged")
+            (goto-char (point-min))
+            (when (and
+                   (re-search-forward "\\+(define-public \\(\\S-+\\)"
+                                      nil 'noerror)
+                   (re-search-backward "modified[ ]*\\(\\S-+\\)"
+                                       nil 'noerror))
+              (string-replace
+               "\.scm" ""
+               (string-replace "/" " "
+                               (match-string-no-properties 1)))))
+          new-module)
+       ")." n
        n
-       n "* " (car (magit-staged-files)) " (" (s var) "): Move from here…"
-       n "* " (cadr (magit-staged-files)) " (" (s var) "): …to here.")
+       "* " (p (with-temp-buffer
+                  (magit-git-wash #'magit-diff-wash-diffs
+                    "diff" "--staged")
+                  (goto-char (point-min))
+                  (when (and
+                         (re-search-forward "\\-(define-public \\(\\S-+\\)"
+                                            nil 'noerror)
+                         (re-search-backward "modified[ ]*\\(\\S-+\\)"
+                                             nil 'noerror))
+                    (match-string-no-properties 1)))
+                source)
+       " (" (s var) "): Move from here…" n
+       "* " (concat (string-replace " " "/" new-module) ".scm")
+       " (" (s var) "): …to here.")



reply via email to

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