1 ;; notmuch-hello.el --- welcome to notmuch, a frontend
3 ;; Copyright © David Edmondson
5 ;; This file is part of Notmuch.
7 ;; Notmuch is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; Notmuch is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
20 ;; Authors: David Edmondson <dme@dme.org>
22 (eval-when-compile (require 'cl))
24 (require 'wid-edit) ; For `widget-forward'.
26 (require 'notmuch-lib)
27 (require 'notmuch-mua)
29 (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))
30 (declare-function notmuch-poll "notmuch" ())
32 (defcustom notmuch-hello-recent-searches-max 10
33 "The number of recent searches to display."
35 :group 'notmuch-hello)
37 (defcustom notmuch-show-empty-saved-searches nil
38 "Should saved searches with no messages be listed?"
40 :group 'notmuch-hello)
42 (defun notmuch-sort-saved-searches (alist)
43 "Generate an alphabetically sorted saved searches alist."
44 (sort (copy-sequence alist) (lambda (a b) (string< (car a) (car b)))))
46 (defcustom notmuch-saved-search-sort-function nil
47 "Function used to sort the saved searches for the notmuch-hello view.
49 This variable controls how saved searches should be sorted. No
50 sorting (nil) displays the saved searches in the order they are
51 stored in `notmuch-saved-searches'. Sort alphabetically sorts the
52 saved searches in alphabetical order. Custom sort function should
53 be a function or a lambda expression that takes the saved
54 searches alist as a parameter, and returns a new saved searches
56 :type '(choice (const :tag "No sorting" nil)
57 (const :tag "Sort alphabetically" notmuch-sort-saved-searches)
58 (function :tag "Custom sort function"
59 :value notmuch-sort-saved-searches))
60 :group 'notmuch-hello)
62 (defvar notmuch-hello-indent 4
63 "How much to indent non-headers.")
65 (defcustom notmuch-show-logo t
66 "Should the notmuch logo be shown?"
68 :group 'notmuch-hello)
70 (defcustom notmuch-show-all-tags-list nil
71 "Should all tags be shown in the notmuch-hello view?"
73 :group 'notmuch-hello)
75 (defcustom notmuch-hello-tag-list-make-query nil
76 "Function or string to generate queries for the all tags list.
78 This variable controls which query results are shown for each tag
79 in the \"all tags\" list. If nil, it will use all messages with
80 that tag. If this is set to a string, it is used as a filter for
81 messages having that tag (equivalent to \"tag:TAG and (THIS-VARIABLE)\").
82 Finally this can be a function that will be called for each tag and
83 should return a filter for that tag, or nil to hide the tag."
84 :type '(choice (const :tag "All messages" nil)
85 (const :tag "Unread messages" "tag:unread")
86 (string :tag "Custom filter"
88 (function :tag "Custom filter function"))
89 :group 'notmuch-hello)
91 (defcustom notmuch-hello-hide-tags nil
92 "List of tags to be hidden in the \"all tags\"-section."
93 :type '(repeat string)
94 :group 'notmuch-hello)
96 (defface notmuch-hello-logo-background
99 (:background "#5f5f5f"))
102 (:background "white")))
103 "Background colour for the notmuch logo."
104 :group 'notmuch-hello
105 :group 'notmuch-faces)
107 (defcustom notmuch-column-control t
108 "Controls the number of columns for saved searches/tags in notmuch view.
110 This variable has three potential sets of values:
112 - t: automatically calculate the number of columns possible based
113 on the tags to be shown and the window width,
114 - an integer: a lower bound on the number of characters that will
115 be used to display each column,
116 - a float: a fraction of the window width that is the lower bound
117 on the number of characters that should be used for each
121 - if you would like two columns of tags, set this to 0.5.
122 - if you would like a single column of tags, set this to 1.0.
123 - if you would like tags to be 30 characters wide, set this to
125 - if you don't want to worry about all of this nonsense, leave
128 (const :tag "Automatically calculated" t)
129 (integer :tag "Number of characters")
130 (float :tag "Fraction of window"))
131 :group 'notmuch-hello)
133 (defcustom notmuch-hello-thousands-separator " "
134 "The string used as a thousands separator.
136 Typically \",\" in the US and UK and \".\" or \" \" in Europe.
137 The latter is recommended in the SI/ISO 31-0 standard and by the
138 International Bureau of Weights and Measures."
140 :group 'notmuch-hello)
142 (defcustom notmuch-hello-mode-hook nil
143 "Functions called after entering `notmuch-hello-mode'."
145 :group 'notmuch-hello
146 :group 'notmuch-hooks)
148 (defcustom notmuch-hello-refresh-hook nil
149 "Functions called after updating a `notmuch-hello' buffer."
151 :group 'notmuch-hello
152 :group 'notmuch-hooks)
154 (defvar notmuch-hello-url "http://notmuchmail.org"
155 "The `notmuch' web site.")
157 (defvar notmuch-hello-search-pos nil
158 "Position of search widget, if any.
160 This should only be set by `notmuch-hello-insert-search'.")
162 (defvar notmuch-hello-custom-section-options
163 '((:filter (string :tag "Filter for each tag"))
164 (:filter-count (string :tag "Different filter to generate message counts"))
165 (:initially-hidden (const :tag "Hide this section on startup" t))
166 (:show-empty-searches (const :tag "Show queries with no matching messages" t))
167 (:hide-if-empty (const :tag "Hide this section if all queries are empty
168 \(and not shown by show-empty-searches)" t)))
169 "Various customization-options for notmuch-hello-tags/query-section.")
171 (define-widget 'notmuch-hello-tags-section 'lazy
172 "Customize-type for notmuch-hello tag-list sections."
173 :tag "Customized tag-list section (see docstring for details)"
176 (const :tag "" notmuch-hello-insert-tags-section)
177 (string :tag "Title for this section")
181 ,(append notmuch-hello-custom-section-options
182 '((:hide-tags (repeat :tag "Tags that will be hidden"
185 (define-widget 'notmuch-hello-query-section 'lazy
186 "Customize-type for custom saved-search-like sections"
187 :tag "Customized queries section (see docstring for details)"
190 (const :tag "" notmuch-hello-insert-query-list)
191 (string :tag "Title for this section")
192 (repeat :tag "Queries"
193 (cons (string :tag "Name") (string :tag "Query")))
194 (plist :inline t :options ,notmuch-hello-custom-section-options)))
196 (defcustom notmuch-hello-sections
197 (list #'notmuch-hello-insert-header
198 #'notmuch-hello-insert-saved-searches
199 #'notmuch-hello-insert-search
200 #'notmuch-hello-insert-recent-searches
201 #'notmuch-hello-insert-alltags
202 #'notmuch-hello-insert-footer)
203 "Sections for notmuch-hello.
205 The list contains functions which are used to construct sections in
206 notmuch-hello buffer. When notmuch-hello buffer is constructed,
207 these functions are run in the order they appear in this list. Each
208 function produces a section simply by adding content to the current
209 buffer. A section should not end with an empty line, because a
210 newline will be inserted after each section by `notmuch-hello'.
212 Each function should take no arguments. If the produced section
213 includes `notmuch-hello-target' (i.e. cursor should be positioned
214 inside this section), the function should return this element's
216 Otherwise, it should return nil.
218 For convenience an element can also be a list of the form (FUNC ARG1
219 ARG2 .. ARGN) in which case FUNC will be applied to the rest of the
222 A \"Customized tag-list section\" item in the customize-interface
223 displays a list of all tags, optionally hiding some of them. It
224 is also possible to filter the list of messages matching each tag
225 by an additional filter query. Similarly, the count of messages
226 displayed next to the buttons can be generated by applying a
227 different filter to the tag query. These filters are also
228 supported for \"Customized queries section\" items."
232 (choice (function-item notmuch-hello-insert-header)
233 (function-item notmuch-hello-insert-saved-searches)
234 (function-item notmuch-hello-insert-search)
235 (function-item notmuch-hello-insert-recent-searches)
236 (function-item notmuch-hello-insert-alltags)
237 (function-item notmuch-hello-insert-footer)
238 (function-item notmuch-hello-insert-inbox)
239 notmuch-hello-tags-section
240 notmuch-hello-query-section
241 (function :tag "Custom section"))))
243 (defvar notmuch-hello-target nil
244 "Button text at position of point before rebuilding the notmuch-buffer.
246 This variable contains the text of the button, if any, the
247 point was positioned at before the notmuch-hello buffer was
248 rebuilt. This should never actually be global and is defined as a
249 defvar only for documentation purposes and to avoid a compiler
250 warning about it occurring as a free variable.")
252 (defvar notmuch-hello-hidden-sections nil
253 "List of sections titles whose contents are hidden")
255 (defvar notmuch-hello-first-run t
256 "True if `notmuch-hello' is run for the first time, set to nil
259 (defun notmuch-hello-nice-number (n)
262 (push (% n 1000) result)
264 (setq result (or result '(0)))
266 (number-to-string (car result))
267 (mapcar (lambda (elem)
268 (format "%s%03d" notmuch-hello-thousands-separator elem))
271 (defun notmuch-hello-trim (search)
273 (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)
274 (match-string 1 search)
277 (defun notmuch-hello-search (&optional search)
279 (unless (null search)
280 (setq search (notmuch-hello-trim search))
281 (let ((history-delete-duplicates t))
282 (add-to-history 'notmuch-search-history search)))
283 (notmuch-search search notmuch-search-oldest-first nil nil
284 #'notmuch-hello-search-continuation))
286 (defun notmuch-hello-add-saved-search (widget)
288 (let ((search (widget-value
290 (widget-get widget :notmuch-saved-search-widget))))
291 (name (completing-read "Name for saved search: "
292 notmuch-saved-searches)))
293 ;; If an existing saved search with this name exists, remove it.
294 (setq notmuch-saved-searches
295 (loop for elem in notmuch-saved-searches
300 (customize-save-variable 'notmuch-saved-searches
301 (add-to-list 'notmuch-saved-searches
302 (cons name search) t))
303 (message "Saved '%s' as '%s'." search name)
304 (notmuch-hello-update)))
306 (defun notmuch-hello-longest-label (searches-alist)
307 (or (loop for elem in searches-alist
308 maximize (length (car elem)))
311 (defun notmuch-hello-reflect-generate-row (ncols nrows row list)
312 (let ((len (length list)))
313 (loop for col from 0 to (- ncols 1)
314 collect (let ((offset (+ (* nrows col) row)))
317 ;; Don't forget to insert an empty slot in the
318 ;; output matrix if there is no corresponding
319 ;; value in the input matrix.
322 (defun notmuch-hello-reflect (list ncols)
323 "Reflect a `ncols' wide matrix represented by `list' along the
326 (let ((nrows (ceiling (length list) ncols)))
327 (loop for row from 0 to (- nrows 1)
328 append (notmuch-hello-reflect-generate-row ncols nrows row list))))
330 (defun notmuch-hello-widget-search (widget &rest ignore)
331 (notmuch-search (widget-get widget
332 :notmuch-search-terms)
333 notmuch-search-oldest-first
334 nil nil #'notmuch-hello-search-continuation))
336 (defun notmuch-saved-search-count (search)
337 (car (process-lines notmuch-command "count" search)))
339 (defun notmuch-hello-tags-per-line (widest)
340 "Determine how many tags to show per line and how wide they
341 should be. Returns a cons cell `(tags-per-line width)'."
344 ((integerp notmuch-column-control)
346 (/ (- (window-width) notmuch-hello-indent)
347 ;; Count is 9 wide (8 digits plus space), 1 for the space
349 (+ 9 1 (max notmuch-column-control widest)))))
351 ((floatp notmuch-column-control)
352 (let* ((available-width (- (window-width) notmuch-hello-indent))
353 (proposed-width (max (* available-width notmuch-column-control) widest)))
354 (floor available-width proposed-width)))
358 (/ (- (window-width) notmuch-hello-indent)
359 ;; Count is 9 wide (8 digits plus space), 1 for the space
363 (cons tags-per-line (/ (max 1
364 (- (window-width) notmuch-hello-indent
365 ;; Count is 9 wide (8 digits plus
366 ;; space), 1 for the space after the
368 (* tags-per-line (+ 9 1))))
371 (defun notmuch-hello-filtered-query (query filter)
372 "Constructs a query to search all messages matching QUERY and FILTER.
374 If FILTER is a string, it is directly used in the returned query.
376 If FILTER is a function, it is called with QUERY as a parameter and
377 the string it returns is used as the query. If nil is returned,
380 Otherwise, FILTER is ignored.
383 ((functionp filter) (funcall filter query))
385 (concat "(" query ") and (" filter ")"))
388 (defun notmuch-hello-query-counts (query-alist &rest options)
389 "Compute list of counts of matched messages from QUERY-ALIST.
391 QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)
392 or (NAME QUERY COUNT-QUERY). If the latter form is used,
393 COUNT-QUERY specifies an alternate query to be used to generate
394 the count for the associated query.
396 The result is the list of elements of the form (NAME QUERY COUNT).
398 The values :show-empty-searches, :filter and :filter-count from
399 options will be handled as specified for
400 `notmuch-hello-insert-searches'."
401 (notmuch-remove-if-not
405 (let* ((name (car elem))
406 (query-and-count (if (consp (cdr elem))
407 ;; do we have a different query for the message count?
408 (cons (second elem) (third elem))
409 (cons (cdr elem) (cdr elem))))
412 (notmuch-saved-search-count
413 (notmuch-hello-filtered-query (cdr query-and-count)
414 (or (plist-get options :filter-count)
415 (plist-get options :filter)))))))
416 (and (or (plist-get options :show-empty-searches) (> message-count 0))
417 (list name (notmuch-hello-filtered-query
418 (car query-and-count) (plist-get options :filter))
422 (defun notmuch-hello-insert-buttons (searches)
423 "Insert buttons for SEARCHES.
425 SEARCHES must be a list containing lists of the form (NAME QUERY COUNT), where
426 QUERY is the query to start when the button for the corresponding entry is
427 activated. COUNT should be the number of messages matching the query.
428 Such a list can be computed with `notmuch-hello-query-counts'."
429 (let* ((widest (notmuch-hello-longest-label searches))
430 (tags-and-width (notmuch-hello-tags-per-line widest))
431 (tags-per-line (car tags-and-width))
432 (widest (cdr tags-and-width))
434 (reordered-list (notmuch-hello-reflect searches tags-per-line))
435 ;; Hack the display of the buttons used.
436 (widget-push-button-prefix "")
437 (widget-push-button-suffix "")
438 (found-target-pos nil))
439 ;; dme: It feels as though there should be a better way to
440 ;; implement this loop than using an incrementing counter.
442 ;; (not elem) indicates an empty slot in the matrix.
444 (let* ((name (first elem))
445 (query (second elem))
446 (msg-count (third elem))
447 (formatted-name (format "%s " name)))
448 (widget-insert (format "%8s "
449 (notmuch-hello-nice-number msg-count)))
450 (if (string= formatted-name notmuch-hello-target)
451 (setq found-target-pos (point-marker)))
452 (widget-create 'push-button
453 :notify #'notmuch-hello-widget-search
454 :notmuch-search-terms query
456 (unless (eq (% count tags-per-line) (1- tags-per-line))
457 ;; If this is not the last tag on the line, insert
458 ;; enough space to consume the rest of the column.
459 ;; Because the button for the name is `(1+ (length
460 ;; name))' long (due to the trailing space) we can
461 ;; just insert `(- widest (length name))' spaces - the
462 ;; column separator is included in the button if
463 ;; `(equal widest (length name)'.
464 (widget-insert (make-string (max 0
465 (- widest (length name)))
467 (setq count (1+ count))
468 (if (eq (% count tags-per-line) 0)
469 (widget-insert "\n")))
472 ;; If the last line was not full (and hence did not include a
473 ;; carriage return), insert one now.
474 (unless (eq (% count tags-per-line) 0)
475 (widget-insert "\n"))
478 (defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))
480 (defun notmuch-hello-search-continuation()
481 (notmuch-hello-update t))
483 (defun notmuch-hello-update (&optional no-display)
484 "Update the current notmuch view."
485 ;; Lazy - rebuild everything.
487 (notmuch-hello no-display))
489 (defun notmuch-hello-poll-and-update ()
490 "Invoke `notmuch-poll' to import mail, then refresh the current view."
493 (notmuch-hello-update))
496 (defvar notmuch-hello-mode-map
497 (let ((map (make-sparse-keymap)))
498 (set-keymap-parent map widget-keymap)
499 (define-key map "v" (lambda () "Display the notmuch version" (interactive)
500 (message "notmuch version %s" (notmuch-version))))
501 (define-key map "?" 'notmuch-help)
502 (define-key map "q" 'notmuch-kill-this-buffer)
503 (define-key map "=" 'notmuch-hello-update)
504 (define-key map "G" 'notmuch-hello-poll-and-update)
505 (define-key map (kbd "<C-tab>") 'widget-backward)
506 (define-key map "m" 'notmuch-mua-new-mail)
507 (define-key map "s" 'notmuch-hello-search)
509 "Keymap for \"notmuch hello\" buffers.")
510 (fset 'notmuch-hello-mode-map notmuch-hello-mode-map)
512 (defun notmuch-hello-mode ()
513 "Major mode for convenient notmuch navigation. This is your entry portal into notmuch.
515 Complete list of currently available key bindings:
517 \\{notmuch-hello-mode-map}"
519 (kill-all-local-variables)
520 (use-local-map notmuch-hello-mode-map)
521 (setq major-mode 'notmuch-hello-mode
522 mode-name "notmuch-hello")
523 (run-mode-hooks 'notmuch-hello-mode-hook)
524 ;;(setq buffer-read-only t)
527 (defun notmuch-hello-generate-tag-alist (&optional hide-tags)
528 "Return an alist from tags to queries to display in the all-tags section."
529 (mapcar (lambda (tag)
530 (cons tag (format "tag:%s" tag)))
531 (notmuch-remove-if-not
533 (not (member tag hide-tags)))
534 (process-lines notmuch-command "search-tags"))))
536 (defun notmuch-hello-insert-header ()
537 "Insert the default notmuch-hello header."
538 (when notmuch-show-logo
539 (let ((image notmuch-hello-logo))
540 ;; The notmuch logo uses transparency. That can display poorly
541 ;; when inserting the image into an emacs buffer (black logo on
542 ;; a black background), so force the background colour of the
543 ;; image. We use a face to represent the colour so that
544 ;; `defface' can be used to declare the different possible
545 ;; colours, which depend on whether the frame has a light or
547 (setq image (cons 'image
549 (list :background (face-background 'notmuch-hello-logo-background)))))
550 (insert-image image))
553 (widget-insert "Welcome to ")
554 ;; Hack the display of the links used.
555 (let ((widget-link-prefix "")
556 (widget-link-suffix ""))
558 :notify (lambda (&rest ignore)
559 (browse-url notmuch-hello-url))
560 :help-echo "Visit the notmuch website."
563 (widget-insert "You have ")
565 :notify (lambda (&rest ignore)
566 (notmuch-hello-update))
568 (notmuch-hello-nice-number
569 (string-to-number (car (process-lines notmuch-command "count")))))
570 (widget-insert " messages.\n")))
573 (defun notmuch-hello-insert-saved-searches ()
574 "Insert the saved-searches section."
575 (let ((searches (notmuch-hello-query-counts
576 (if notmuch-saved-search-sort-function
577 (funcall notmuch-saved-search-sort-function
578 notmuch-saved-searches)
579 notmuch-saved-searches)
580 :show-empty-searches notmuch-show-empty-saved-searches))
583 (widget-insert "Saved searches: ")
584 (widget-create 'push-button
585 :notify (lambda (&rest ignore)
586 (customize-variable 'notmuch-saved-searches))
588 (widget-insert "\n\n")
589 (let ((start (point)))
590 (setq found-target-pos
591 (notmuch-hello-insert-buttons searches))
592 (indent-rigidly start (point) notmuch-hello-indent)
595 (defun notmuch-hello-insert-search ()
596 "Insert a search widget."
597 (widget-insert "Search: ")
598 (setq notmuch-hello-search-pos (point-marker))
599 (widget-create 'editable-field
600 ;; Leave some space at the start and end of the
602 :size (max 8 (- (window-width) notmuch-hello-indent
603 (length "Search: ")))
604 :action (lambda (widget &rest ignore)
605 (notmuch-hello-search (widget-value widget))))
606 ;; Add an invisible dot to make `widget-end-of-line' ignore
607 ;; trailing spaces in the search widget field. A dot is used
608 ;; instead of a space to make `show-trailing-whitespace'
609 ;; happy, i.e. avoid it marking the whole line as trailing
612 (put-text-property (1- (point)) (point) 'invisible t)
613 (widget-insert "\n"))
615 (defun notmuch-hello-insert-recent-searches ()
616 "Insert recent searches."
617 (when notmuch-search-history
618 (widget-insert "Recent searches: ")
619 (widget-create 'push-button
620 :notify (lambda (&rest ignore)
621 (setq notmuch-search-history nil)
622 (notmuch-hello-update))
624 (widget-insert "\n\n")
625 (let ((start (point)))
626 (loop for i from 1 to notmuch-hello-recent-searches-max
627 for search in notmuch-search-history do
628 (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))
630 (widget-create 'editable-field
631 ;; Don't let the search boxes be
632 ;; less than 8 characters wide.
639 (* 2 notmuch-hello-indent)
642 ;; `[save]' button. 6
646 :action (lambda (widget &rest ignore)
647 (notmuch-hello-search (widget-value widget)))
650 (widget-create 'push-button
651 :notify (lambda (widget &rest ignore)
652 (notmuch-hello-add-saved-search widget))
653 :notmuch-saved-search-widget widget-symbol
655 (widget-insert "\n"))
656 (indent-rigidly start (point) notmuch-hello-indent))
659 (defun notmuch-hello-insert-searches (title query-alist &rest options)
660 "Insert a section with TITLE showing a list of buttons made from QUERY-ALIST.
662 QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)
663 or (NAME QUERY COUNT-QUERY). If the latter form is used,
664 COUNT-QUERY specifies an alternate query to be used to generate
665 the count for the associated item.
667 Supports the following entries in OPTIONS as a plist:
668 :initially-hidden - if non-nil, section will be hidden on startup
669 :show-empty-searches - show buttons with no matching messages
670 :hide-if-empty - hide if no buttons would be shown
671 (only makes sense without :show-empty-searches)
672 :filter - This can be a function that takes the search query as its argument and
673 returns a filter to be used in conjuction with the query for that search or nil
674 to hide the element. This can also be a string that is used as a combined with
675 each query using \"and\".
676 :filter-count - Separate filter to generate the count displayed each search. Accepts
677 the same values as :filter. If :filter and :filter-count are specified, this
678 will be used instead of :filter, not in conjunction with it."
679 (widget-insert title ": ")
680 (if (and notmuch-hello-first-run (plist-get options :initially-hidden))
681 (add-to-list 'notmuch-hello-hidden-sections title))
682 (let ((is-hidden (member title notmuch-hello-hidden-sections))
685 (widget-create 'push-button
686 :notify `(lambda (widget &rest ignore)
687 (setq notmuch-hello-hidden-sections
688 (delete ,title notmuch-hello-hidden-sections))
689 (notmuch-hello-update))
691 (widget-create 'push-button
692 :notify `(lambda (widget &rest ignore)
693 (add-to-list 'notmuch-hello-hidden-sections
695 (notmuch-hello-update))
699 (when (not is-hidden)
700 (let ((searches (apply 'notmuch-hello-query-counts query-alist options)))
701 (when (or (not (plist-get options :hide-if-empty))
705 (notmuch-hello-insert-buttons searches))
706 (indent-rigidly start (point) notmuch-hello-indent))))
709 (defun notmuch-hello-insert-tags-section (&optional title &rest options)
710 "Insert a section displaying all tags with message counts.
712 TITLE defaults to \"All tags\".
713 Allowed options are those accepted by `notmuch-hello-insert-searches' and the
716 :hide-tags - List of tags that should be excluded."
717 (apply 'notmuch-hello-insert-searches
718 (or title "All tags")
719 (notmuch-hello-generate-tag-alist (plist-get options :hide-tags))
722 (defun notmuch-hello-insert-inbox ()
723 "Show an entry for each saved search and inboxed messages for each tag"
724 (notmuch-hello-insert-searches "What's in your inbox"
726 (notmuch-saved-searches)
727 (notmuch-hello-generate-tag-alist))
728 :filter "tag:inbox"))
730 (defun notmuch-hello-insert-alltags ()
731 "Insert a section displaying all tags and associated message counts"
732 (notmuch-hello-insert-tags-section
734 :initially-hidden (not notmuch-show-all-tags-list)
735 :hide-tags notmuch-hello-hide-tags
736 :filter notmuch-hello-tag-list-make-query))
738 (defun notmuch-hello-insert-footer ()
739 "Insert the notmuch-hello footer."
740 (let ((start (point)))
741 (widget-insert "Type a search query and hit RET to view matching threads.\n")
742 (when notmuch-search-history
743 (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")
744 (widget-insert "Save recent searches with the `save' button.\n"))
745 (when notmuch-saved-searches
746 (widget-insert "Edit saved searches with the `edit' button.\n"))
747 (widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")
748 (widget-insert "`=' to refresh this screen. `s' to search messages. `q' to quit.\n")
750 :notify (lambda (&rest ignore)
751 (customize-variable 'notmuch-hello-sections))
752 :button-prefix "" :button-suffix ""
754 (widget-insert " this page.")
755 (let ((fill-column (- (window-width) notmuch-hello-indent)))
756 (center-region start (point)))))
759 (defun notmuch-hello (&optional no-display)
760 "Run notmuch and display saved searches, known tags, etc."
763 ;; Jump through a hoop to get this value from the deprecated variable
764 ;; name (`notmuch-folders') or from the default value.
765 (unless notmuch-saved-searches
766 (setq notmuch-saved-searches (notmuch-saved-searches)))
769 (set-buffer "*notmuch-hello*")
770 (switch-to-buffer "*notmuch-hello*"))
772 (let ((notmuch-hello-target (if (widget-at)
773 (widget-value (widget-at))
777 (widget-value (widget-at)))
779 (inhibit-read-only t))
781 ;; Delete all editable widget fields. Editable widget fields are
782 ;; tracked in a buffer local variable `widget-field-list' (and
783 ;; others). If we do `erase-buffer' without properly deleting the
784 ;; widgets, some widget-related functions are confused later.
785 (mapc 'widget-delete widget-field-list)
789 (unless (eq major-mode 'notmuch-hello-mode)
790 (notmuch-hello-mode))
792 (let ((all (overlay-lists)))
793 ;; Delete all the overlays.
794 (mapc 'delete-overlay (car all))
795 (mapc 'delete-overlay (cdr all)))
797 (let (final-target-pos)
800 (let ((point-before (point))
801 (result (if (functionp section)
803 (apply (car section) (cdr section)))))
804 (if (and (not final-target-pos) (integer-or-marker-p result))
805 (setq final-target-pos result))
806 ;; don't insert a newline when the previous section didn't show
808 (unless (eq (point) point-before)
809 (widget-insert "\n"))))
810 notmuch-hello-sections)
813 (when final-target-pos
814 (goto-char final-target-pos)
819 (when notmuch-hello-search-pos
820 (goto-char notmuch-hello-search-pos)))))
821 (run-hooks 'notmuch-hello-refresh-hook)
822 (setq notmuch-hello-first-run nil))
824 (defun notmuch-folder ()
825 "Deprecated function for invoking notmuch---calling `notmuch' is preferred now."
831 (provide 'notmuch-hello)