[bug] notmuch-read-tag-changes, incompatability with consult, non-standard usage of completing-read-multiple

Subject: [bug] notmuch-read-tag-changes, incompatability with consult, non-standard usage of completing-read-multiple

Date: Mon, 20 Sep 2021 01:20:44 -0700

To: notmuch@notmuchmail.org

Cc:

From: Natnael Kahssay



notmuch-read-tag-changes throws error, "Tag must be in the form of +'this_tag' or '-that_tag'" when used with consult. notmuch-read-tag-changes expects completing-read-multiple to strip crm-separator out of results. Consult's implementation of competing-read-multiple doesn't strip results.
I discussed with the author of the package here. https://github.com/minad/consult/issues/410

He states notmuch is using a non-standard and possibly tentative property of completing-read-multiple. I agree.

Below I have a version of notmuch-read-tag-changes that removes suffix crm-separator of returned candidates explicitly.
#+begin_src emacs-lisp
(defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
  "Prompt for tag changes in the minibuffer.

CURRENT-TAGS is a list of tags that are present on the message
or messages to be changed.  These are offered as tag removal
completions.  CURRENT-TAGS may contain duplicates.  PROMPT, if
non-nil, is the query string to present in the minibuffer.  It
defaults to \"Tags\".  INITIAL-INPUT, if non-nil, will be the
initial input in the minibuffer."
  (let* ((all-tag-list (notmuch-tag-completions))
     (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))
     (remove-tag-list (mapcar (apply-partially 'concat "-") current-tags))
     (tag-list (append add-tag-list remove-tag-list))
     (prompt (concat (or prompt "Tags") " (+add -drop): "))
     (crm-separator " ")
     ;; By default, space is bound to "complete word" function.
     ;; Re-bind it to insert a space instead.  Note that <tab>
     ;; still does the completion.
     (crm-local-completion-map
      (let ((map (make-sparse-keymap)))
        (set-keymap-parent map crm-local-completion-map)
        (define-key map " " 'self-insert-command)
        map)))
    (mapcar (lambda (entry)
              (substring entry 0 (- (length crm-separator))))
            (delete "" (completing-read-multiple
                prompt
                ;; Append the separator to each completion so when the
                ;; user completes a tag they can immediately begin
                ;; entering another.  `completing-read-multiple'
                ;; ultimately splits the input on crm-separator, so we
                ;; don't need to strip this back off (we just need to
                ;; delete "empty" entries caused by trailing spaces).
                (mapcar (lambda (tag-op) (concat tag-op crm-separator)) tag-list)
                nil nil initial-input
		        'notmuch-read-tag-changes-history)))))
#+end_src
signature.asc (application/pgp-signature)
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: