]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-hello.el
emacs: do not call `notmuch-hello-mode' on update
[notmuch] / emacs / notmuch-hello.el
index 65fde75a07d3b3ad10179315941c29ab0a26bacb..81b26059ab1a01dfbfdd5d93bd2f1a385f219511 100644 (file)
   :type 'boolean
   :group 'notmuch)
 
+(defun notmuch-sort-saved-searches (alist)
+  "Generate an alphabetically sorted saved searches alist."
+  (sort alist (lambda (a b) (string< (car a) (car b)))))
+
+(defcustom notmuch-saved-search-sort-function nil
+  "Function used to sort the saved searches for the notmuch-hello view.
+
+This variable controls how saved searches should be sorted. No
+sorting (nil) displays the saved searches in the order they are
+stored in `notmuch-saved-searches'. Sort alphabetically sorts the
+saved searches in alphabetical order. Custom sort function should
+be a function or a lambda expression that takes the saved
+searches alist as a parameter, and returns a new saved searches
+alist to be used."
+  :type '(choice (const :tag "No sorting" nil)
+                (const :tag "Sort alphabetically" notmuch-sort-saved-searches)
+                (function :tag "Custom sort function"
+                          :value notmuch-sort-saved-searches))
+  :group 'notmuch)
+
 (defvar notmuch-hello-indent 4
   "How much to indent non-headers.")
 
@@ -118,6 +138,11 @@ Typically \",\" in the US and UK and \".\" in Europe."
   :group 'notmuch
   :type 'string)
 
+(defcustom notmuch-hello-mode-hook nil
+  "Functions called after entering `notmuch-hello-mode'."
+  :group 'notmuch
+  :type 'hook)
+
 (defvar notmuch-hello-url "http://notmuchmail.org"
   "The `notmuch' web site.")
 
@@ -168,8 +193,8 @@ Typically \",\" in the US and UK and \".\" in Europe."
                collect elem))
     ;; Add the new one.
     (customize-save-variable 'notmuch-saved-searches
-                            (push (cons name search)
-                                  notmuch-saved-searches))
+                            (add-to-list 'notmuch-saved-searches
+                                         (cons name search) t))
     (message "Saved '%s' as '%s'." search name)
     (notmuch-hello-update)))
 
@@ -335,6 +360,7 @@ Complete list of currently available key bindings:
  (use-local-map notmuch-hello-mode-map)
  (setq major-mode 'notmuch-hello-mode
        mode-name "notmuch-hello")
+ (run-mode-hooks 'notmuch-hello-mode-hook)
  ;;(setq buffer-read-only t)
 )
 
@@ -377,11 +403,16 @@ Complete list of currently available key bindings:
                     (progn
                       (widget-forward 1)
                       (widget-value (widget-at)))
-                  (error nil)))))
+                  (error nil))))
+       (inhibit-read-only t))
+
+    ;; Delete all editable widget fields.  Editable widget fields are
+    ;; tracked in a buffer local variable `widget-field-list' (and
+    ;; others).  If we do `erase-buffer' without properly deleting the
+    ;; widgets, some widget-related functions are confused later.
+    (mapc 'widget-delete widget-field-list)
 
-    (kill-all-local-variables)
-    (let ((inhibit-read-only t))
-      (erase-buffer))
+    (erase-buffer)
 
     (unless (eq major-mode 'notmuch-hello-mode)
       (notmuch-hello-mode))
@@ -440,6 +471,10 @@ Complete list of currently available key bindings:
             (widest (max saved-widest alltags-widest)))
 
        (when saved-alist
+         ;; Sort saved searches if required.
+         (when notmuch-saved-search-sort-function
+           (setq saved-alist
+                 (funcall notmuch-saved-search-sort-function saved-alist)))
          (widget-insert "\nSaved searches: ")
          (widget-create 'push-button
                         :notify (lambda (&rest ignore)
@@ -462,6 +497,10 @@ Complete list of currently available key bindings:
                                       (length "Search: ")))
                       :action (lambda (widget &rest ignore)
                                 (notmuch-hello-search (widget-value widget))))
+       ;; add an invisible space to make `widget-end-of-line' ignore
+       ;; trailine spaces in the search widget field
+       (widget-insert " ")
+       (put-text-property (1- (point)) (point) 'invisible t)
        (widget-insert "\n")
 
        (when notmuch-hello-recent-searches