From 7eac4ac9186b62bdc8f3b38005b4ecb4ed59f680 Mon Sep 17 00:00:00 2001 From: djcb Date: Sat, 22 Nov 2014 13:23:29 +0200 Subject: [PATCH] mu4e: add mu4e-headers-find-if This function can be used to jump to some message in the headers list that matches a certain pattern. --- mu4e/mu4e-headers.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 8c538b9e..adc7ff89 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -982,6 +982,24 @@ header." (when msg (funcall func msg)))))) +(defun mu4e-headers-find-if (func &optional backward) + "Move to the next header for which FUNC returns non-`nil', +starting from the current position. FUNC takes one argument, the +msg s-expression for the corresponding header. If BACKWARD is +non-`nil', search backwards." + (let ((pos) (search-func (if backward 'search-backward 'search-forward))) + (save-excursion + (while (and (null pos) + (funcall search-func mu4e~headers-docid-pre nil t)) + ;; not really sure why we need to jump to bol; we do need to, otherwise we + ;; miss lines sometimes... + (let ((msg (get-text-property (line-beginning-position) 'msg))) + (when (and msg (funcall func msg)) + (setq pos (point)))))) + (when pos + (goto-char pos)))) + + (defvar mu4e~headers-regexp-hist nil "History list of regexps used.")