radian-software / prescient.el

☄️ Simple but effective sorting and filtering for Emacs.
MIT License
603 stars 25 forks source link

Notmuch: narrow tags, order sets of tags #115

Closed agenbite closed 2 years ago

agenbite commented 2 years ago

Hi! I just landed in selectrum/prescient some days ago and I love it. In fact, I'd love to get frecency in almost every aspect of my computer interaction! XD

However, when using notmuch email, I find a peculiar situation that I don't know how to deal with. The thing is that notmuch is based on the idea of tagging messages (with notmuch-tag) in order to "store" them. For example, a newly arrived message from a mailing list would be tagged "inbox" when it arrives, and then I would probably want to tag it like so: "+list -inbox", so it would be removed from inbox and stored with tag "list".

I'm happy with how I'm getting my tags narrowed when I initiate the task of tagging (one after the other, of course), but I'm not so happy with how they're sorted at the beginning: I'd like to have full sets of tags in the sorting memory, so repeating a tagging would be real quick. Instead, in the list I find only individual tags, which forces me to repeat narrowing and selection if I need to apply several tags, even though they might be the same set I applied last time.

Sorry since I'm quite new to emacs and all. Do I make sense at all? Is there a way to get sets of tags (instead of tags) in the frecency ordering?

Thanks for prescient!!

okamsn commented 2 years ago

I have not used Notmuch, but if I read the code correctly, the command uses the function completing-read-multiple.

This function is used to select multiple candidates from a list of candidates. When Prescient sorts candidates, it acts upon the list of candidates provided by the command. The tags are sorted individually because the command lists them individually.

Since you are new to Emacs, if you are unaware, I will state that you can cycle through the selection histories of many completing commands using M-p and M-n (to go to the previous and next items in history, respectively). Selectrum additionally provides the command selectrum-select-from-history (M-r in the minibuffer). With it, you can use completion and sorting on that command's selection history. From testing with the command describe-face (which also use completing-read-multiple), it seems that the multiple candidates are recorded as one item in the variable face-name-history.

So, this is one option, if the Notmuch package works similarly. However, this did not work when overriding Selectrum's version of CRM with consult-completing-read-multiple, if you are using that version instead.

If you use the same combinations of tags frequently, you could probably just create a wrapping command in which you list those combinations. The website gives some examples of how to act upon sets of tags here: https://notmuchmail.org/emacstips/#index5h2

Again, I have not used Notmuch, but I guess that you would want something like the below example, substituting notmuch-show-tag with notmuch-search-tag or notmuch-tree-tag as makes sense to you. The entries in my-tag-sets will be sorted during completion, as expected.

(defvar my-tag-sets (list "+list -inbox" "+cat -dog" "-example1 -example2")
  "Preferred combinations.")

(defun my-show-common-tags ()
  "Toggle tags shown?"
  (interactive)
  (notmuch-show-tag (split-string (completing-read "Tags combo: " my-tag-sets)
                                   " " 'omit-nulls)))

Does this help?

agenbite commented 2 years ago

It does help! M-r is just what I needed! Thank you so much for taking the time to look into the code for me!

I'll have a look into the differences between completing-read-multiple, consult-completing-read-multiple and selectrum-completing-read-multiple. In my case, even though I'm also using consult, I believe the one my system is using is the later (since completing-read-multiple help page says this: This function has :override advice: ‘selectrum-completing-read-multiple’). In any case, it works! :)

Thanks again!