abbreviations in queries

22 views
Skip to first unread message

Erik Colson

unread,
Aug 8, 2017, 6:23:49 PM8/8/17
to mu-di...@googlegroups.com
Hi,

I'm using mu4e a lot now and I'm hitting a usage speed problem.

There are mails I don want to see by default. Those mails respond to a
long query. So, I have to enter NOT ( _long_query_ ) into the search
string. I figured I could make it a bookmark and build the query upon
that. That works, except that I the rest of the query is also long.

I've been thinking about how I could enhance this.
- one option would be to use macros, but that would be an awful solution
I think
- the other one would be to modify mu4e to allow abbreviations into
search strings

Example of such a query would then be "NOT _TRASHED_ AND _PROJECT24933_"
which would expand to "NOT (flag:trashed OR maildir:"Trash") AND
(maildir:project24933 OR from:client24933 OR to:client24933)"

I'm thinking about coding this into mu4e, but before starting this I'd
like to question the group:
- Is there something I overlooked here and perhaps there is a better
solution?
- Is anyone else interested in this behavior ?

thx!
--
erik colson

Yuri D'Elia

unread,
Aug 9, 2017, 10:53:51 AM8/9/17
to mu-di...@googlegroups.com
On Wed, Aug 09 2017, Erik Colson wrote:
> Example of such a query would then be "NOT _TRASHED_ AND _PROJECT24933_"
> which would expand to "NOT (flag:trashed OR maildir:"Trash") AND
> (maildir:project24933 OR from:client24933 OR to:client24933)"
>
> I'm thinking about coding this into mu4e, but before starting this I'd
> like to question the group:
> - Is there something I overlooked here and perhaps there is a better
> solution?
> - Is anyone else interested in this behavior ?

https://groups.google.com/forum/#!topic/mu-discuss/Hv4rZ-B6hW0

I since expanded the code that I posted, but I never bothered to make it
more visible.

Maybe I should put it on melpa.

Eduardo Mercovich

unread,
Aug 10, 2017, 9:04:19 AM8/10/17
to mu-di...@googlegroups.com
Hi Yuri, hi Erik.

>> Example of such a query would then be "NOT _TRASHED_ AND
>> _PROJECT24933_" which would expand to "NOT (flag:trashed OR
>> maildir:"Trash") AND (maildir:project24933 OR from:client24933
>> OR to:client24933)" [...] before starting this I'd like to
>> question the group: [...] - Is anyone else interested in this
>> behavior ?

Me at least, for sure. :)

> https://groups.google.com/forum/#!topic/mu-discuss/Hv4rZ-B6hW0
> I since expanded the code that I posted, but I never bothered to
> make it more visible.

This is quite interesting. Would you mind to share that code, even
if it's still not ideal?

Thanks a lot...


--
Eduardo Mercovich

Donde se cruzan tus talentos
con las necesidades del mundo,
ahí está tu vocación.
(Anónimo)

Eduardo Mercovich

unread,
Aug 10, 2017, 2:24:44 PM8/10/17
to mu-di...@googlegroups.com
Hi Erik.

> [...] to modify mu4e to allow abbreviations into search strings
> Example of such a query would then be "NOT _TRASHED_ AND
> _PROJECT24933_" which would expand to "NOT (flag:trashed OR
> maildir:"Trash") AND (maildir:project24933 OR from:client24933
> OR to:client24933)" [...] Is anyone else interested in this
> behavior ?

I said yes before, but was thinking of an obvious example.
Here are a couple:

1. "me" as automagic abbrev of all mu4e-user-mail-address-list

2. "project-x" as abbrev of "date:start-end AND addressA AND
addressB AND addressN AND keywordK AND keywordL AND keywordM" and
so on.

Y would like those abbreviations quite much. :)

Does the mail-abbrev system helps? (probably not, but just in
case...).

Dirk-Jan C. Binnema

unread,
Aug 10, 2017, 4:49:27 PM8/10/17
to mu-di...@googlegroups.com
Hi Erik,
I wouldn't want to complicate mu query parsing any further.

But we could add a rewrite-function in query parsing, so a function of
your choosing would be called that got "NOT _TRASHED_ AND
_PROJECT24933_" and do any expansion you need.

That would also allow for e.g. Yuri's fragments to be handled without
advice etc.

Kind regards,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

Yuri D'Elia

unread,
Sep 16, 2017, 8:55:48 AM9/16/17
to mu-di...@googlegroups.com
On Thu, Aug 10 2017, Eduardo Mercovich wrote:
>>> Example of such a query would then be "NOT _TRASHED_ AND
>>> _PROJECT24933_" which would expand to "NOT (flag:trashed OR
>>> maildir:"Trash") AND (maildir:project24933 OR from:client24933 OR
>>> to:client24933)" [...] before starting this I'd like to question the
>>> group: [...] - Is anyone else interested in this behavior ?
>
> Me at least, for sure. :)
>
>> https://groups.google.com/forum/#!topic/mu-discuss/Hv4rZ-B6hW0
>> I since expanded the code that I posted, but I never bothered to make
>> it more visible.
>
> This is quite interesting. Would you mind to share that code, even if
> it's still not ideal?

I polished the code a bit, and it's now on melpa:

https://melpa.org/#/mu4e-query-fragments

Eduardo Mercovich

unread,
Sep 17, 2017, 12:56:09 AM9/17/17
to mu-di...@googlegroups.com
Hello Yuri.

[...]
>>> https://groups.google.com/forum/#!topic/mu-discuss/Hv4rZ-B6hW0
>>> I since expanded the code that I posted, but I never bothered
>>> to make
>>> it more visible.

>> This is quite interesting. Would you mind to share that code,
>> even if it's still not ideal?

> I polished the code a bit, and it's now on melpa:
> https://melpa.org/#/mu4e-query-fragments

Fist of all, thanks a lot for the code and the sharing. :)

I installed it and configured as this:

--8<---------------cut here---------------start------------->8---
(require 'mu4e-query-fragments)
(setq mu4e-query-fragments-list
'(("%borrados" . "maildir:/edumerco/trash OR
maildir:/gmail/trash OR
maildir:/kokori/papelera OR
maildir:/mamagrande/trash OR
maildir:/moveo/trash")
("%mi" . "edu...@mercovich.net OR
eduardo....@gmail.com OR
edu...@mamagrande.org OR
edu...@moveo-sensu.org OR
edu...@kokori.cl OR
edu...@lofsur.cl OR
eduardo....@inspiro.com.ar OR
edum...@gaiasur.com.ar
")))
--8<---------------cut here---------------end--------------->8---

%borrados are all the trash maildirs (equivalent in english to
%Trashed)

%mi are all my addresses (equivalent in english to "me" as Google
uses it)

However, when I try to search for "to:%mi date:3d..." to test, I
get:

--8<---------------cut here---------------start------------->8---
error in process filter: Error 1: error in quoting
--8<---------------cut here---------------end--------------->8---

Any idea what may be happening?
Thanks a lot... :)

Erik Colson

unread,
Sep 17, 2017, 5:31:52 AM9/17/17
to mu-di...@googlegroups.com

Yuri D'Elia <wav...@thregr.org> writes:

> I polished the code a bit, and it's now on melpa:
>
> https://melpa.org/#/mu4e-query-fragments

Installed, tested and works awesome.

thanks!
--
erik colson

Yuri D'Elia

unread,
Sep 17, 2017, 9:06:34 AM9/17/17
to mu-di...@googlegroups.com
On Sat, Sep 16 2017, Eduardo Mercovich wrote:
> However, when I try to search for "to:%mi date:3d..." to test, I get:
>
> --8<---------------cut here---------------start------------->8---
> error in process filter: Error 1: error in quoting
> --8<---------------cut here---------------end--------------->8---
>
> Any idea what may be happening?

This is expanded to to:(maildir:/.. maildir:/), which is not valid
syntax (to: expects addresses).

You can do directly "%mi AND date:3d..".

Yuri D'Elia

unread,
Sep 17, 2017, 9:09:02 AM9/17/17
to mu-di...@googlegroups.com
Mh, I should have re-read the query.
For the to: case, you should repeat to: for each address.

For example, to match anything addressed to me, I have:

("%me" . "to:addr1 OR to:addr2 ...")

Eduardo Mercovich

unread,
Sep 22, 2017, 3:18:20 PM9/22/17
to mu-di...@googlegroups.com
Hell Yuri.

Sorry the dalay, a lot of work travel.

[...]

>> This is expanded to to:(maildir:/.. maildir:/), which is not
>> valid syntax (to: expects addresses).

> Mh, I should have re-read the query. For the to: case, you
> should repeat to: for each address.
> For example, to match anything addressed to me, I have:

> ("%me" . "to:addr1 OR to:addr2 ...")

Ok, so I configured fragments as

--8<---------------cut here---------------start------------->8---
(setq mu4e-query-fragments-list
'(("%borrados" . "maildir:/edumerco/trash OR
maildir:/gmail/trash OR
maildir:/kokori/papelera OR
maildir:/mamagrande/trash OR
maildir:/moveo/trash")
("%mi" . "to:edu...@mercovich.net OR
to:eduardo....@gmail.com OR
to:edu...@mamagrande.org OR
to:edu...@moveo-sensu.org OR
to:edu...@kokori.cl OR
to:edu...@lofsur.cl OR
to:eduardo....@inspiro.com.ar OR
to:edum...@gaiasur.com.ar
")))
;; (setq mu4e-query-fragments-append "AND NOT %borrados")
--8<---------------cut here---------------end--------------->8---

Upon searching "%mi date:1w..." I get

--8<---------------cut here---------------start------------->8---
error in process filter: mu4e-error-handler: Error 1: error in
quoting
error in process filter: Error 1: error in quoting
--8<---------------cut here---------------end--------------->8---

I'm sure I'm making something wrong here since your code works on
other contexts... what could it be?

Thanks a lot both for sharing your code and helping to make it
work. :)

Yuri D'Elia

unread,
Sep 22, 2017, 5:48:48 PM9/22/17
to mu-di...@googlegroups.com
On Fri, Sep 22 2017, Eduardo Mercovich wrote:
> ("%mi" . "to:edu...@mercovich.net OR
> to:eduardo....@gmail.com OR to:edu...@mamagrande.org
> OR to:edu...@moveo-sensu.org OR

Ok, I assumed this was some wrapping issue, but... you don't have actual
newlines in the expanded string... right? ;)

Filter those out.

I'll add some sanitization for this.

Eduardo Mercovich

unread,
Sep 22, 2017, 10:50:52 PM9/22/17
to mu-di...@googlegroups.com
Hello Yuri.

[...]
>> to:edu...@moveo-sensu.org OR [...]

> Ok, I assumed this was some wrapping issue, but... you don't
> have actual newlines in the expanded string... right? ;)

Ops, yes I have. Sorry... :(
I read that spaces were no issue in lisp, and -wrongly- I assumed
that in this way was clearer to read what was in that list.

> Filter those out.

I did it and now works perfectly. :D

Thanks a lot, and sorry for the silly error...

> I'll add some sanitization for this.

Again, thanks a lot for it.
My searches here are much cleaner now. And easier. :)))

Best regards...

Yuri D'Elia

unread,
Sep 23, 2017, 8:24:44 AM9/23/17
to mu-di...@googlegroups.com
On Sat, Sep 23 2017, Eduardo Mercovich wrote:
> I read that spaces were no issue in lisp, and -wrongly- I assumed that
> in this way was clearer to read what was in that list.

It normally doesn't, and Xapian by itself is insensitive to whitespace.
But I guess it breaks somewhere down the line.
Reply all
Reply to author
Forward
0 new messages