about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-01-24T16·29+0000
committerVincent Ambo <tazjin@google.com>2020-01-24T18·51+0000
commitfb5f26e548dc74f49a1242d80d2b23feeef5645e (patch)
tree2abe42e1616e516543c766c82d9be55b57e942f0 /tools
parent2fa7bf7bb078c757216a392578a19fd01d5726f6 (diff)
feat(emacs.d): Add notmuch-depot-apply-patch helper function r/453
This function lets me interactively apply a patch from the currently
opened notmuch message to the depot.
Diffstat (limited to 'tools')
-rw-r--r--tools/emacs/config/functions.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/emacs/config/functions.el b/tools/emacs/config/functions.el
index a7889ca915..dc7ac89d78 100644
--- a/tools/emacs/config/functions.el
+++ b/tools/emacs/config/functions.el
@@ -238,4 +238,25 @@
   (if prefix (text-scale-adjust 0)
     (set-face-attribute 'default nil :height (or to 120))))
 
+(defun notmuch-depot-apply-patch ()
+  "Apply the currently opened notmuch message as a patch on the
+  depot."
+
+  (interactive)
+  ;; The implementation works by letting notmuch render a raw message
+  ;; and capturing it by overriding the `view-buffer' function it
+  ;; calls after rendering.
+  ;;
+  ;; The buffer is then passed to `git-am'.
+  (cl-letf (((symbol-function 'view-buffer)
+             (lambda (buffer &optional exit-action) buffer)))
+    (if-let ((raw-buffer (notmuch-show-view-raw-message)))
+        (progn
+          (with-current-buffer raw-buffer
+            (call-shell-region (point-min) (point-max) "git am -C ~/depot")
+            (message "Patch applied!")
+            (kill-buffer))
+          (magit-status "~/depot"))
+      (warn "notmuch failed to render the raw message buffer"))))
+
 (provide 'functions)