rougier / mu4e-dashboard

A dashboard for mu4e (mu for emacs)
GNU General Public License v3.0
467 stars 43 forks source link

named queries? #37

Open titaniumbones opened 2 years ago

titaniumbones commented 2 years ago

Have just started using the dashboard today and it's fantastic. The only thing I don't love about it is the code duplication that is required in creating links. So for instance, I generally use bookmarks rather than mailboxes, so my standard view will look like this:

 [[mu:maildir:/inbox AND NOT (contact:notifications@github.com OR contact:noreply@github.com OR ilcontact:builds@travis-ci.com OR contact:builds@travis-ci.org) AND NOT flag:trashed][Inbox]] 

to make keyboard shortcuts and show counts, etc, I have to maintain 3 or 4 copies of this search. can you see a good way to write the query just once instead? perhaps an alist of queries matched to names?

thanks again

titaniumbones commented 2 years ago

I have a sort of partial solution, which is to parse the query before sending it to the mu find shell process. I just wrap the query let-binding in the function below. I use the built-in mu4e-bookmarks variable and the abbreviation bm: to identify a bookmark, though the user will need to customize the variable and add a new :nickname property to each bookmark. So far I like it; it makes it quite easy, for instance, to add AND flag:unread to an existing bookmark. Needs to be cleaned up a bit, and my own code right now is a bit of a jumble, but if you're interested I could provide a patch. So far I believe it does work.

(defun mu4e-dashboard-expand-bm (q)
  (let* ((bookmark-re "bm:\\(\\w+\\)")
         (match (string-match bookmark-re q))
         (nickname (match-string 1 q))
         (bms mu4e-bookmarks )
         (bookmark (if nickname (--first (equal (plist-get it :nick) nickname) bms )))
         (expansion (if bookmark (plist-get bookmark :query) ))  )
    (if expansion  
        (replace-regexp-in-string bookmark-re expansion  q)
      q)))
rougier commented 2 years ago

Many thanks for the code. There was also a discussion on the mu mailing list and Matt Price propose some code. Is your code more or less equivalent ?