Programatic access to marks (patch workflow)

22 views
Skip to first unread message

Alex Bennée

unread,
Apr 19, 2016, 11:56:03 AM4/19/16
to mu-discuss
Hi,

In my continuing quest for improving my patch application work-flow I've
been wondering if it is possible to access marks in a programatic way.
To recap I have a custom marker to select patches:

(add-to-list
'mu4e-headers-custom-markers
'("Patches"
;; Match function
(lambda (msg parent-id)
(when
(and
(string-match
parent-id
(or
(mu4e-message-field-raw msg :in-reply-to)
""))
(string-match "^\\[" (mu4e-message-field-raw msg
:subject)))
(add-to-list 'my-mu4e-patches msg)))
;; Param function
(lambda ()
(setq my-mu4e-patches nil
my-mu4e-applied-patches nil)
(let ((msg (mu4e-message-at-point)))
(mu4e-message-field-raw msg :message-id)))))

This selects all the patches in a thread that aren't replies.

I have a custom application routine which sorts the messages and applies
in order (while attempting to be re-startable):

;; Header markers
(defvar my-mu4e-patches nil
"List of mu4e-messages snagged by the (Patches) actions.")
(defvar my-mu4e-applied-patches nil
"List of mu4e-messages successfully applied by the (Patches)
actions.")
(make-variable-buffer-local 'my-mu4e-patches)
(make-variable-buffer-local 'my-mu4e-applied-patches)

(defun my-mu4e-apply-marked-mbox-patches ()
"Apply patches in order."
(interactive)
(let ((new-applications
(--take-while
(= 0 (mu4e-action-git-apply-mbox it))
(--sort
(string<
(mu4e-message-field-raw it :subject)
(mu4e-message-field-raw other :subject))
(-difference my-mu4e-patches
my-mu4e-applied-patches)))))
(setq my-mu4e-applied-patches
(-union my-mu4e-applied-patches new-applications))

(message (format "Applied %d (%d)/%d patches"
(length new-applications)
(length my-mu4e-applied-patches)
(length my-mu4e-patches)))))

And I have a custom mark because I got tired of marking for *something*:

(add-to-list
'mu4e-marks
'(patch
:char ("#" . "#")
:prompt "Patch"))

What I would like to do is have some way of un-marking patches once they
have been applied. I could add my-mu4e-apply-marked-mbox-patches to
:ask-target and maybe do something with :action but the code seems to be
set for an all or nothing approach, so I can't return nil/t depending on
if the "action" succeeded. Is there another way I can unmark a message?

--
Alex Bennée

Alex Bennée

unread,
Apr 19, 2016, 12:23:22 PM4/19/16
to mu-discuss

Alex Bennée <alex....@linaro.org> writes:

> Hi,
>
> In my continuing quest for improving my patch application work-flow I've
> been wondering if it is possible to access marks in a programatic way.
> To recap I have a custom marker to select patches:
<snip>
>
> (defun my-mu4e-apply-marked-mbox-patches ()

OK this is a slightly hacked up version but uses the internal symbol mu4e~headers-goto-docid:

(defun my-mu4e-apply-marked-mbox-patches ()
"Apply patches in order."
(interactive)
(let ((applied-or-skipped
(--take-while
(let ((docid (plist-get it :docid)))
(if (mu4e-mark-docid-marked-p docid)
(if (= 0 (mu4e-action-git-apply-mbox it))
(when (mu4e~headers-goto-docid docid)
(mu4e-mark-set 'unmark) t)
; failed to apply, stop
nil)
; not marked, skip
t))
(--sort
(string<
(mu4e-message-field-raw it :subject)
(mu4e-message-field-raw other :subject))
(-difference my-mu4e-patches
my-mu4e-applied-patches)))))
(setq my-mu4e-applied-patches
(-union my-mu4e-applied-patches applied-or-skipped))

(message (format "Applied %d (%d)/%d patches"
(length applied-or-skipped)
(length my-mu4e-applied-patches)
(length my-mu4e-patches)))))
--
Alex Bennée
Reply all
Reply to author
Forward
0 new messages