From 5f8e0b71f091836c07be67e40402c3dbd8389ba7 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 5 Jan 2025 22:41:24 +0200 Subject: [PATCH] server: make parsed queries available to mu4e Basically, make the "mu find .... --analyze" information available in mu4e, through a function mu4e-server-last-query. This is shows the query as the server saw it, as well as the parse s-expressions. This can be useful to see how some query is interpreted. --- lib/mu-server.cc | 10 ++++++++-- mu4e/mu4e-server.el | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/mu-server.cc b/lib/mu-server.cc index 6048b707..4862f7a9 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2020-2023 Dirk-Jan C. Binnema +** Copyright (C) 2020-2025 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -39,6 +39,7 @@ #include "mu-maildir.hh" #include "mu-query.hh" +#include "mu-query-parser.hh" #include "mu-store.hh" #include "utils/mu-utils.hh" @@ -703,7 +704,12 @@ Server::Private::find_handler(const Command& cmd) output_sexp(Sexp().put_props(":erase", Sexp::t_sym)); const auto bsize{static_cast(batch_size)}; const auto foundnum = output_results(*qres, bsize); - output_sexp(Sexp().put_props(":found", foundnum)); + + output_sexp(Sexp().put_props( + ":found", foundnum, + ":query", q, + ":query-sexp", parse_query(q, false/*!expand*/).to_string(), + ":query-sexp-expanded", parse_query(q, true/*expand*/).to_string())); } void diff --git a/mu4e/mu4e-server.el b/mu4e/mu4e-server.el index d1b1c155..85ba0329 100644 --- a/mu4e/mu4e-server.el +++ b/mu4e/mu4e-server.el @@ -175,7 +175,7 @@ sexp received from the server process.") (plist-get mu4e--server-props :version)) (mu4e-error "Version unknown; did you start mu4e?"))) -;;; remember queries result. +;;; remember query results. (defvar mu4e--server-query-items nil "Query items results we receive from the mu4e server. Those are the results from the counting-queries @@ -185,6 +185,22 @@ for bookmarks and maildirs.") "Get the latest server query items." mu4e--server-query-items) +(defvar mu4e--server-query nil + "Last query executed by the server. +This is a plist, see `mu4e-server-last-query' for details.") + +(defun mu4e-server-last-query () + "Get a plist with information about the last server-query. + +This has the following fields: +- :query: this is the last query the server executed (a string) +- :query-sexp: this is that last query as processed by the query engine + (an s-expression as a string) +- :query-sexp-expanded: like last-query-sexp, but with combination fields + expanded." + (cl-remf mu4e--server-query :found) ;; there's no plist-delete + mu4e--server-query) + ;; temporary (defun mu4e--server-xapian-single-threaded-p() "Are we using Xapian in single-threaded mode?" @@ -278,7 +294,7 @@ This for the few sexps we get from the mu server that support (defun mu4e--server-filter (_proc str) "Filter string STR from PROC. This processes the \"mu server\" output. It accumulates the -strings into valid sexpsv and evaluating those. +strings into valid s-expressions and evaluates those. The server output is as follows: @@ -349,6 +365,8 @@ The server output is as follows: ;; the found sexp, we receive after getting all the headers ((plist-get sexp :found) + ;; capture the query-info + (setq mu4e--server-query sexp) (funcall mu4e-found-func (plist-get sexp :found))) ;; viewing a specific message