X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch-hello.el;h=9db8c9931a8fee0a25e105d00d5345def45ec47f;hb=HEAD;hp=00b78e1ed265a74d52aaf78d7479934f55a65cfb;hpb=16aa65ba2575fd504c31d9671d8c5150f8e8adf1;p=obsolete%2Fnotmuch-old diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 00b78e1e..9db8c993 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -26,7 +26,7 @@ (require 'notmuch-lib) (require 'notmuch-mua) -(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation)) +(declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line continuation)) (declare-function notmuch-poll "notmuch" ()) (defcustom notmuch-hello-recent-searches-max 10 @@ -286,6 +286,15 @@ afterwards.") (message "Saved '%s' as '%s'." search name) (notmuch-hello-update))) +(defun notmuch-hello-delete-search-from-history (widget) + (interactive) + (let ((search (widget-value + (symbol-value + (widget-get widget :notmuch-saved-search-widget))))) + (setq notmuch-search-history (delete search + notmuch-search-history)) + (notmuch-hello-update))) + (defun notmuch-hello-longest-label (searches-alist) (or (loop for elem in searches-alist maximize (length (car elem))) @@ -381,26 +390,43 @@ The result is the list of elements of the form (NAME QUERY COUNT). The values :show-empty-searches, :filter and :filter-count from options will be handled as specified for `notmuch-hello-insert-searches'." - (notmuch-remove-if-not - #'identity - (mapcar - (lambda (elem) - (let* ((name (car elem)) - (query-and-count (if (consp (cdr elem)) - ;; do we have a different query for the message count? - (cons (second elem) (third elem)) - (cons (cdr elem) (cdr elem)))) - (message-count - (string-to-number - (notmuch-saved-search-count - (notmuch-hello-filtered-query (cdr query-and-count) - (or (plist-get options :filter-count) - (plist-get options :filter))))))) - (and (or (plist-get options :show-empty-searches) (> message-count 0)) - (list name (notmuch-hello-filtered-query - (car query-and-count) (plist-get options :filter)) - message-count)))) - query-alist))) + (with-temp-buffer + (dolist (elem query-alist nil) + (let ((count-query (if (consp (cdr elem)) + ;; do we have a different query for the message count? + (third elem) + (cdr elem)))) + (insert + (notmuch-hello-filtered-query count-query + (or (plist-get options :filter-count) + (plist-get options :filter))) + "\n"))) + + (unless (= (call-process-region (point-min) (point-max) notmuch-command + t t nil "count" "--batch") 0) + (notmuch-logged-error "notmuch count --batch failed" + "Please check that the notmuch CLI is new enough to support `count +--batch'. In general we recommend running matching versions of +the CLI and emacs interface.")) + + (goto-char (point-min)) + + (notmuch-remove-if-not + #'identity + (mapcar + (lambda (elem) + (let ((name (car elem)) + (search-query (if (consp (cdr elem)) + ;; do we have a different query for the message count? + (second elem) + (cdr elem))) + (message-count (prog1 (read (current-buffer)) + (forward-line 1)))) + (and (or (plist-get options :show-empty-searches) (> message-count 0)) + (list name (notmuch-hello-filtered-query + search-query (plist-get options :filter)) + message-count)))) + query-alist)))) (defun notmuch-hello-insert-buttons (searches) "Insert buttons for SEARCHES. @@ -587,8 +613,9 @@ Complete list of currently available key bindings: (widget-insert "Recent searches: ") (widget-create 'push-button :notify (lambda (&rest ignore) - (setq notmuch-search-history nil) - (notmuch-hello-update)) + (when (y-or-n-p "Are you sure you want to clear the searches? ") + (setq notmuch-search-history nil) + (notmuch-hello-update))) "clear") (widget-insert "\n\n") (let ((start (point))) @@ -611,7 +638,12 @@ Complete list of currently available key bindings: ;; `[save]' button. 6 ;; for the `[save]' ;; button. - 1 6)) + 1 6 + ;; 1 for the space + ;; before the `[del]' + ;; button. 5 for the + ;; `[del]' button. + 1 5)) :action (lambda (widget &rest ignore) (notmuch-hello-search (widget-value widget))) search)) @@ -620,7 +652,14 @@ Complete list of currently available key bindings: :notify (lambda (widget &rest ignore) (notmuch-hello-add-saved-search widget)) :notmuch-saved-search-widget widget-symbol - "save")) + "save") + (widget-insert " ") + (widget-create 'push-button + :notify (lambda (widget &rest ignore) + (when (y-or-n-p "Are you sure you want to delete this search? ") + (notmuch-hello-delete-search-from-history widget))) + :notmuch-saved-search-widget widget-symbol + "del")) (widget-insert "\n")) (indent-rigidly start (point) notmuch-hello-indent)) nil))