[PATCH 1/3] sorting: add the ability to sort by from and subject

classic Classic list List threaded Threaded
10 messages Options
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/3] sorting: add the ability to sort by from and subject

* add {from,subject}-{ascending,descending} sort options
---
I'm not sure if we want to eventually refactor ascending and descending
into a separate option, but I decided to keep it this way for now.

 lib/notmuch.h    | 16 ++++++++++++++++
 lib/query.cc     | 12 ++++++++++++
 notmuch-search.c |  4 ++++
 3 files changed, 32 insertions(+)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 66ecb5fc..f5764683 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -764,6 +764,22 @@ typedef enum {
      */
     NOTMUCH_SORT_NEWEST_FIRST,
     /**
+     * Sort by from: in ascending order
+     */
+    NOTMUCH_SORT_FROM_ASC,
+    /**
+     * Sort by from: in descending order
+     */
+    NOTMUCH_SORT_FROM_DESC,
+    /**
+     * Sort by subject: in ascending order
+     */
+    NOTMUCH_SORT_SUBJECT_ASC,
+    /**
+     * Sort by subject: in descending order
+     */
+    NOTMUCH_SORT_SUBJECT_DESC,
+    /**
      * Sort by message-id.
      */
     NOTMUCH_SORT_MESSAGE_ID,
diff --git a/lib/query.cc b/lib/query.cc
index 9c6ecc8d..106814a8 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -327,6 +327,18 @@ _notmuch_query_search_documents (notmuch_query_t *query,
  case NOTMUCH_SORT_NEWEST_FIRST:
     enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
     break;
+ case NOTMUCH_SORT_FROM_ASC:
+    enquire.set_sort_by_value (NOTMUCH_VALUE_FROM, FALSE);
+    break;
+ case NOTMUCH_SORT_FROM_DESC:
+    enquire.set_sort_by_value (NOTMUCH_VALUE_FROM, TRUE);
+    break;
+ case NOTMUCH_SORT_SUBJECT_ASC:
+    enquire.set_sort_by_value (NOTMUCH_VALUE_SUBJECT, FALSE);
+    break;
+ case NOTMUCH_SORT_SUBJECT_DESC:
+    enquire.set_sort_by_value (NOTMUCH_VALUE_SUBJECT, TRUE);
+    break;
  case NOTMUCH_SORT_MESSAGE_ID:
     enquire.set_sort_by_value (NOTMUCH_VALUE_MESSAGE_ID, FALSE);
     break;
diff --git a/notmuch-search.c b/notmuch-search.c
index 380e9d8f..b80647e9 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -789,6 +789,10 @@ static const notmuch_opt_desc_t common_options[] = {
     { NOTMUCH_OPT_KEYWORD, &search_context.sort, "sort", 's',
       (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
       { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
+      { "from-ascending", NOTMUCH_SORT_FROM_ASC },
+      { "from-descending", NOTMUCH_SORT_FROM_DESC },
+      { "subject-ascending", NOTMUCH_SORT_SUBJECT_ASC },
+      { "subject-descending", NOTMUCH_SORT_SUBJECT_DESC },
       { 0, 0 } } },
     { NOTMUCH_OPT_KEYWORD, &search_context.format_sel, "format", 'f',
       (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
--
2.13.2

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/3] sorting: update ruby bindings for from and subject

---
 bindings/ruby/init.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 5556b43e..ace8f666 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -104,6 +104,30 @@ Init_notmuch (void)
      */
     rb_define_const (mod, "SORT_NEWEST_FIRST", INT2FIX (NOTMUCH_SORT_NEWEST_FIRST));
     /*
+     * Document-const: Notmuch::SORT_FROM_ASC
+     *
+     * Sort query results by from in ascending order
+     */
+    rb_define_const (mod, "SORT_FROM_ASC", INT2FIX (NOTMUCH_SORT_FROM_ASC));
+    /*
+     * Document-const: Notmuch::SORT_FROM_DESC
+     *
+     * Sort query results by from in descending order
+     */
+    rb_define_const (mod, "SORT_FROM_DESC", INT2FIX (NOTMUCH_SORT_FROM_DESC));
+    /*
+     * Document-const: Notmuch::SORT_SUBJECT_ASC
+     *
+     * Sort query results by subject in ascending order
+     */
+    rb_define_const (mod, "SORT_SUBJECT_ASC", INT2FIX (NOTMUCH_SORT_SUBJECT_ASC));
+    /*
+     * Document-const: Notmuch::SORT_SUBJECT_DESC
+     *
+     * Sort query results by from in descending order
+     */
+    rb_define_const (mod, "SORT_SUBJECT_DESC", INT2FIX (NOTMUCH_SORT_SUBJECT_DESC));
+    /*
      * Document-const: Notmuch::SORT_MESSAGE_ID
      *
      * Sort query results by message id
--
2.13.2

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

[PATCH 3/3] sorting: update man page

In reply to this post by William Casarin
---
 doc/man1/notmuch-address.rst | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst
index cc31cc5a..38ae9a25 100644
--- a/doc/man1/notmuch-address.rst
+++ b/doc/man1/notmuch-address.rst
@@ -77,7 +77,11 @@ Supported options for **address** include
             frequently among the matching messages. If --output=count
             is specified, include all variants in the count.
 
-    ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
+    ``--sort=<order>``
+        Where <order> can be one of **oldest-first**, **newest-first**,
+        **subject-ascending**, **subject-descending**,
+        **from-ascending**, **from-descending**
+
         This option can be used to present results in either
         chronological order (**oldest-first**) or reverse chronological
         order (**newest-first**).
--
2.13.2

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Jani Nikula Jani Nikula
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/3] sorting: add the ability to sort by from and subject

In reply to this post by William Casarin
On Mon, 04 Sep 2017, William Casarin <[hidden email]> wrote:
> * add {from,subject}-{ascending,descending} sort options

The implementation seems simple enough, but what's the use case, really?

When thinking about the usefulness of the feature, you have to think
about what gets indexed for from: and subject: prefixes, and how they
would get sorted. (See lib/index.cc for details.)

From: J. Random Hacker <[hidden email]>
From: "Hacker, Random J." <[hidden email]>
From: [hidden email]

Subject: [notmuch] [PATCH 1/3] sorting
Subject: [PATCH 1/3] sorting
Subject: Re: [PATCH 1/3] sorting
Subject: Vast: [PATCH 1/3] sorting

With those in mind, does it still seem useful to sort by from or
subject?

If yes, consider thread sorting with some search terms, and all of the
above present in a thread. The placement of a thread in the result list
depends on which messages in the thread match the query. Even if the
matching messages are supposedly the same.

I'm not convinced.


BR,
Jani.

> ---
> I'm not sure if we want to eventually refactor ascending and descending
> into a separate option, but I decided to keep it this way for now.
>
>  lib/notmuch.h    | 16 ++++++++++++++++
>  lib/query.cc     | 12 ++++++++++++
>  notmuch-search.c |  4 ++++
>  3 files changed, 32 insertions(+)
>
> diff --git a/lib/notmuch.h b/lib/notmuch.h
> index 66ecb5fc..f5764683 100644
> --- a/lib/notmuch.h
> +++ b/lib/notmuch.h
> @@ -764,6 +764,22 @@ typedef enum {
>       */
>      NOTMUCH_SORT_NEWEST_FIRST,
>      /**
> +     * Sort by from: in ascending order
> +     */
> +    NOTMUCH_SORT_FROM_ASC,
> +    /**
> +     * Sort by from: in descending order
> +     */
> +    NOTMUCH_SORT_FROM_DESC,
> +    /**
> +     * Sort by subject: in ascending order
> +     */
> +    NOTMUCH_SORT_SUBJECT_ASC,
> +    /**
> +     * Sort by subject: in descending order
> +     */
> +    NOTMUCH_SORT_SUBJECT_DESC,
> +    /**
>       * Sort by message-id.
>       */
>      NOTMUCH_SORT_MESSAGE_ID,
> diff --git a/lib/query.cc b/lib/query.cc
> index 9c6ecc8d..106814a8 100644
> --- a/lib/query.cc
> +++ b/lib/query.cc
> @@ -327,6 +327,18 @@ _notmuch_query_search_documents (notmuch_query_t *query,
>   case NOTMUCH_SORT_NEWEST_FIRST:
>      enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
>      break;
> + case NOTMUCH_SORT_FROM_ASC:
> +    enquire.set_sort_by_value (NOTMUCH_VALUE_FROM, FALSE);
> +    break;
> + case NOTMUCH_SORT_FROM_DESC:
> +    enquire.set_sort_by_value (NOTMUCH_VALUE_FROM, TRUE);
> +    break;
> + case NOTMUCH_SORT_SUBJECT_ASC:
> +    enquire.set_sort_by_value (NOTMUCH_VALUE_SUBJECT, FALSE);
> +    break;
> + case NOTMUCH_SORT_SUBJECT_DESC:
> +    enquire.set_sort_by_value (NOTMUCH_VALUE_SUBJECT, TRUE);
> +    break;
>   case NOTMUCH_SORT_MESSAGE_ID:
>      enquire.set_sort_by_value (NOTMUCH_VALUE_MESSAGE_ID, FALSE);
>      break;
> diff --git a/notmuch-search.c b/notmuch-search.c
> index 380e9d8f..b80647e9 100644
> --- a/notmuch-search.c
> +++ b/notmuch-search.c
> @@ -789,6 +789,10 @@ static const notmuch_opt_desc_t common_options[] = {
>      { NOTMUCH_OPT_KEYWORD, &search_context.sort, "sort", 's',
>        (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
>        { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
> +      { "from-ascending", NOTMUCH_SORT_FROM_ASC },
> +      { "from-descending", NOTMUCH_SORT_FROM_DESC },
> +      { "subject-ascending", NOTMUCH_SORT_SUBJECT_ASC },
> +      { "subject-descending", NOTMUCH_SORT_SUBJECT_DESC },
>        { 0, 0 } } },
>      { NOTMUCH_OPT_KEYWORD, &search_context.format_sel, "format", 'f',
>        (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
> --
> 2.13.2
>
> _______________________________________________
> notmuch mailing list
> [hidden email]
> https://notmuchmail.org/mailman/listinfo/notmuch
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/3] sorting: add the ability to sort by from and subject

William Casarin <[hidden email]> writes:

> Jani Nikula <[hidden email]> writes:
>
>> The implementation seems simple enough, but what's the use case, really?
>
> I get all of my rss feeds sent to my inbox, I wanted to be able to group
> similar feeds (mainly by from, sometimes subject). Alternatively if
> there was a way to group by tags I could do it that way, but I don't tag
> all of my individual feeds.
>
> If this is too obscure of a use case please feel free to ignore!

A use case for the subject sort is my github tag. Since the repo name is
at the start of the subject line, it sorts by repo so I can quickly skim
across all the issues/prs in all the github repos I follow

Cheers,
William

--
https://jb55.com
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/3] sorting: add the ability to sort by from and subject

William Casarin <[hidden email]> writes:

> William Casarin <[hidden email]> writes:
>
>> Jani Nikula <[hidden email]> writes:
>>
>>> The implementation seems simple enough, but what's the use case, really?
>>
>> I get all of my rss feeds sent to my inbox, I wanted to be able to group
>> similar feeds (mainly by from, sometimes subject). Alternatively if
>> there was a way to group by tags I could do it that way, but I don't tag
>> all of my individual feeds.
>>
>> If this is too obscure of a use case please feel free to ignore!
>
> A use case for the subject sort is my github tag. Since the repo name is
> at the start of the subject line, it sorts by repo so I can quickly skim
> across all the issues/prs in all the github repos I follow

It seems worth mentioning that it's possible to preprocess values into
keys (see Xapian::Enquire::set_sort_by_key). So things like Re:
etc... could be stripped.
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/3] sorting: add the ability to sort by from and subject

David Bremner <[hidden email]> writes:

> It seems worth mentioning that it's possible to preprocess values into
> keys (see Xapian::Enquire::set_sort_by_key). So things like Re:
> etc... could be stripped.

Hmm looks like I need to create a KeyMaker class which appears to be a
glorified (Xapian::Document -> String) callback. Shouldn't be too
difficult other than the choice of algorithm. It would have to strip:

  Re: Fwd: ... etc?

Sounds like the choice algorithm could be tricky and/or error prone?
Would need lots of tests, and like Jani said, questionable worth in
these scenarios, considering I was mainly dealing with scenarios like
these:

  From: Top News - MIT Technology Review
  From: Newest questions tagged haskell - Stack Overflow

So the current implementation would only be useful for RSS feeds,
automated bots, etc. that are non-mailing-list-email use cases.

I'm working on updates to notmuch-mode right now. I'll post a patch for
that soon for people who are interested.

- William
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

[PATCH] emacs: replace oldest-first with sort-order

This generalizes notmuch-search-oldest-first to
notmuch-search-sort-order. notmuch-search-sort-order can now be one
of:

  * oldest-first
  * newest-first
  * subject-ascending
  * subject-descending
  * from-ascending
  * from-descending

Order toggling now simply inverts the corresponding option.
---
 emacs/notmuch-hello.el |  8 +++-----
 emacs/notmuch-jump.el  | 13 +++++--------
 emacs/notmuch-lib.el   | 10 ++++++++--
 emacs/notmuch-tree.el  |  2 +-
 emacs/notmuch.el       | 52 ++++++++++++++++++++++++++++----------------------
 5 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index c18d74fa..8f700f03 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -579,10 +579,8 @@ with `notmuch-hello-query-counts'."
   (widget-insert (make-string column-indent ? )))
       (let* ((name (plist-get elem :name))
      (query (plist-get elem :query))
-     (oldest-first (case (plist-get elem :sort-order)
-     (newest-first nil)
-     (oldest-first t)
-     (otherwise notmuch-search-oldest-first)))
+     (order (plist-get elem :sort-order))
+     (sort-order (if (not order) notmuch-search-sort-order order))
      (search-type (eq (plist-get elem :search-type) 'tree))
      (msg-count (plist-get elem :count)))
  (widget-insert (format "%8s "
@@ -590,7 +588,7 @@ with `notmuch-hello-query-counts'."
  (widget-create 'push-button
        :notify #'notmuch-hello-widget-search
        :notmuch-search-terms query
-       :notmuch-search-oldest-first oldest-first
+       :notmuch-search-sort-order sort-order
        :notmuch-search-type search-type
        name)
  (setq column-indent
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 3e20b8c7..5fd654fb 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -48,17 +48,14 @@ fast way to jump to a saved search from anywhere in Notmuch."
       (let* ((saved-search (notmuch-hello-saved-search-to-plist saved-search))
      (key (plist-get saved-search :key)))
  (when key
-  (let ((name (plist-get saved-search :name))
- (query (plist-get saved-search :query))
- (oldest-first
- (case (plist-get saved-search :sort-order)
-   (newest-first nil)
-   (oldest-first t)
-   (otherwise (default-value 'notmuch-search-oldest-first)))))
+  (let* ((name (plist-get saved-search :name))
+ (query (plist-get saved-search :query))
+ (order (plist-get saved-search :sort-order))
+ (sort-order (if (not order) notmuch-search-sort-order order)))
     (push (list key name
  (if (eq (plist-get saved-search :search-type) 'tree)
     `(lambda () (notmuch-tree ',query))
-  `(lambda () (notmuch-search ',query ',oldest-first))))
+  `(lambda () (notmuch-search ',query ',sort-order))))
   action-map)))))
     (setq action-map (nreverse action-map))
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 010be454..ee7b67d3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -92,14 +92,20 @@ $PATH)."
   :type 'string
   :group 'notmuch-external)
 
-(defcustom notmuch-search-oldest-first t
+(defcustom notmuch-search-sort-order 'oldest-first
   "Show the oldest mail first when searching.
 
 This variable defines the default sort order for displaying
 search results. Note that any filtered searches created by
 `notmuch-search-filter' retain the search order of the parent
 search."
-  :type 'boolean
+  :type '(choice :tag " Sort Order"
+ (const :tag "Oldest-first" oldest-first)
+ (const :tag "Newest-first" newest-first)
+ (const :tag "Subject-ascending" subject-ascending)
+ (const :tag "Subject-descending" subject-descending)
+ (const :tag "From-ascending" from-ascending)
+ (const :tag "From-descending" from-descending))
   :group 'notmuch-search)
 
 (defcustom notmuch-poll-script nil
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index c00315e8..b95ff71f 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -33,7 +33,7 @@
 (require 'notmuch-parser)
 
 (eval-when-compile (require 'cl))
-(declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line))
+(declare-function notmuch-search "notmuch" (&optional query sort-order target-thread target-line))
 (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-search-find-thread-id "notmuch" (&optional bare))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 44402f8a..334458b7 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -380,7 +380,7 @@ Complete list of currently available key bindings:
 
 \\{notmuch-search-mode-map}"
   (make-local-variable 'notmuch-search-query-string)
-  (make-local-variable 'notmuch-search-oldest-first)
+  (make-local-variable 'notmuch-search-sort-order)
   (make-local-variable 'notmuch-search-target-thread)
   (make-local-variable 'notmuch-search-target-line)
   (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
@@ -959,7 +959,7 @@ PROMPT is the string to prompt with."
 
 (put 'notmuch-search 'notmuch-doc "Search for messages.")
 ;;;###autoload
-(defun notmuch-search (&optional query oldest-first target-thread target-line no-display)
+(defun notmuch-search (&optional query sort-order target-thread target-line no-display)
   "Display threads matching QUERY in a notmuch-search buffer.
 
 If QUERY is nil, it is read interactively from the minibuffer.
@@ -982,7 +982,7 @@ the configured default sort order."
     nil
     ;; Use the default search order (if we're doing a search from a
     ;; search buffer, ignore any buffer-local overrides)
-    (default-value 'notmuch-search-oldest-first)))
+    (default-value 'notmuch-search-sort-order)))
 
   (let* ((query (or query (notmuch-read-query "Notmuch search: ")))
  (buffer (get-buffer-create (notmuch-search-buffer-title query))))
@@ -993,29 +993,26 @@ the configured default sort order."
     ;; Don't track undo information for this buffer
     (set 'buffer-undo-list t)
     (set 'notmuch-search-query-string query)
-    (set 'notmuch-search-oldest-first oldest-first)
+    (set 'notmuch-search-sort-order sort-order)
     (set 'notmuch-search-target-thread target-thread)
     (set 'notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
     (let ((proc (get-buffer-process (current-buffer)))
   (inhibit-read-only t))
       (if proc
-  (error "notmuch search process already running for query `%s'" query)
- )
+  (error "notmuch search process already running for query `%s'" query))
       (erase-buffer)
       (goto-char (point-min))
       (save-excursion
- (let ((proc (notmuch-start-notmuch
-     "notmuch-search" buffer #'notmuch-search-process-sentinel
-     "search" "--format=sexp" "--format-version=4"
-     (if oldest-first
- "--sort=oldest-first"
-       "--sort=newest-first")
-     query))
-      ;; Use a scratch buffer to accumulate partial output.
-      ;; This buffer will be killed by the sentinel, which
-      ;; should be called no matter how the process dies.
-      (parse-buf (generate-new-buffer " *notmuch search parse*")))
+ (let* ((proc (notmuch-start-notmuch
+      "notmuch-search" buffer #'notmuch-search-process-sentinel
+      "search" "--format=sexp" "--format-version=4"
+      (concat "--sort=" (symbol-name sort-order))
+      query))
+       ;; Use a scratch buffer to accumulate partial output.
+       ;; This buffer will be killed by the sentinel, which
+       ;; should be called no matter how the process dies.
+       (parse-buf (generate-new-buffer " *notmuch search parse*")))
   (process-put proc 'parse-buf parse-buf)
   (set-process-filter proc 'notmuch-search-process-filter)
   (set-process-query-on-exit-flag proc nil))))
@@ -1031,20 +1028,29 @@ thread. Otherwise, point will be moved to attempt to be in the
 same relative position within the new buffer."
   (interactive)
   (let ((target-line (line-number-at-pos))
- (oldest-first notmuch-search-oldest-first)
+ (sort-order notmuch-search-sort-order)
  (target-thread (notmuch-search-find-thread-id 'bare))
  (query notmuch-search-query-string))
     ;; notmuch-search erases the current buffer.
-    (notmuch-search query oldest-first target-thread target-line t)
+    (notmuch-search query sort-order target-thread target-line t)
     (goto-char (point-min))))
 
+(defun notmuch-toggle-order (order)
+  (case order
+    (newest-first 'oldest-first)
+    (oldest-first 'newest-first)
+    (from-ascending 'from-descending)
+    (from-descending 'from-ascending)
+    (subject-ascending 'subject-descending)
+    (subject-descending 'subject-ascending)))
+
 (defun notmuch-search-toggle-order ()
   "Toggle the current search order.
 
 This command toggles the sort order for the current search. The
-default sort order is defined by `notmuch-search-oldest-first'."
+default sort order is defined by `notmuch-search-sort-order'."
   (interactive)
-  (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))
+  (set 'notmuch-search-sort-order (notmuch-toggle-order notmuch-search-sort-order))
   (notmuch-search-refresh-view))
 
 (defun notmuch-group-disjunctive-query-string (query-string)
@@ -1068,7 +1074,7 @@ current search results AND the additional query string provided."
     (notmuch-search (if (string= grouped-original-query "*")
  grouped-query
       (concat grouped-original-query " and " grouped-query))
-    notmuch-search-oldest-first)))
+    notmuch-search-sort-order)))
 
 (defun notmuch-search-filter-by-tag (tag)
   "Filter the current search results based on a single tag.
@@ -1077,7 +1083,7 @@ Runs a new search matching only messages that match both the
 current search results AND that are tagged with the given tag."
   (interactive
    (list (notmuch-select-tag-with-completion "Filter by tag: ")))
-  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))
+  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-sort-order))
 
 ;;;###autoload
 (defun notmuch ()
--
2.13.2

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

[PATCH v2] emacs: replace oldest-first with sort-order

This generalizes notmuch-search-oldest-first to
notmuch-search-sort-order. notmuch-search-sort-order can now be one
of:

  * oldest-first
  * newest-first
  * subject-ascending
  * subject-descending
  * from-ascending
  * from-descending

Order toggling now simply inverts the corresponding option.
---

Was missing notmuch-hello changes from previous patch :(

 emacs/notmuch-hello.el | 14 ++++++++------
 emacs/notmuch-jump.el  | 13 +++++--------
 emacs/notmuch-lib.el   | 10 ++++++++--
 emacs/notmuch-tree.el  |  2 +-
 emacs/notmuch.el       | 52 ++++++++++++++++++++++++++++----------------------
 5 files changed, 51 insertions(+), 40 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index c858a20b..8f700f03 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -95,7 +95,11 @@ searches so they still work in customize."
     (choice :tag " Sort Order"
     (const :tag "Default" nil)
     (const :tag "Oldest-first" oldest-first)
-    (const :tag "Newest-first" newest-first)))
+    (const :tag "Newest-first" newest-first)
+    (const :tag "Subject-ascending" subject-ascending)
+    (const :tag "Subject-descending" subject-descending)
+    (const :tag "From-ascending" from-ascending)
+    (const :tag "From-descending" from-descending)))
      (group :format "%v" :inline t (const :format "" :search-type)
     (choice :tag " Search Type"
     (const :tag "Search mode" nil)
@@ -575,10 +579,8 @@ with `notmuch-hello-query-counts'."
   (widget-insert (make-string column-indent ? )))
       (let* ((name (plist-get elem :name))
      (query (plist-get elem :query))
-     (oldest-first (case (plist-get elem :sort-order)
-     (newest-first nil)
-     (oldest-first t)
-     (otherwise notmuch-search-oldest-first)))
+     (order (plist-get elem :sort-order))
+     (sort-order (if (not order) notmuch-search-sort-order order))
      (search-type (eq (plist-get elem :search-type) 'tree))
      (msg-count (plist-get elem :count)))
  (widget-insert (format "%8s "
@@ -586,7 +588,7 @@ with `notmuch-hello-query-counts'."
  (widget-create 'push-button
        :notify #'notmuch-hello-widget-search
        :notmuch-search-terms query
-       :notmuch-search-oldest-first oldest-first
+       :notmuch-search-sort-order sort-order
        :notmuch-search-type search-type
        name)
  (setq column-indent
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 3e20b8c7..5fd654fb 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -48,17 +48,14 @@ fast way to jump to a saved search from anywhere in Notmuch."
       (let* ((saved-search (notmuch-hello-saved-search-to-plist saved-search))
      (key (plist-get saved-search :key)))
  (when key
-  (let ((name (plist-get saved-search :name))
- (query (plist-get saved-search :query))
- (oldest-first
- (case (plist-get saved-search :sort-order)
-   (newest-first nil)
-   (oldest-first t)
-   (otherwise (default-value 'notmuch-search-oldest-first)))))
+  (let* ((name (plist-get saved-search :name))
+ (query (plist-get saved-search :query))
+ (order (plist-get saved-search :sort-order))
+ (sort-order (if (not order) notmuch-search-sort-order order)))
     (push (list key name
  (if (eq (plist-get saved-search :search-type) 'tree)
     `(lambda () (notmuch-tree ',query))
-  `(lambda () (notmuch-search ',query ',oldest-first))))
+  `(lambda () (notmuch-search ',query ',sort-order))))
   action-map)))))
     (setq action-map (nreverse action-map))
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 010be454..ee7b67d3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -92,14 +92,20 @@ $PATH)."
   :type 'string
   :group 'notmuch-external)
 
-(defcustom notmuch-search-oldest-first t
+(defcustom notmuch-search-sort-order 'oldest-first
   "Show the oldest mail first when searching.
 
 This variable defines the default sort order for displaying
 search results. Note that any filtered searches created by
 `notmuch-search-filter' retain the search order of the parent
 search."
-  :type 'boolean
+  :type '(choice :tag " Sort Order"
+ (const :tag "Oldest-first" oldest-first)
+ (const :tag "Newest-first" newest-first)
+ (const :tag "Subject-ascending" subject-ascending)
+ (const :tag "Subject-descending" subject-descending)
+ (const :tag "From-ascending" from-ascending)
+ (const :tag "From-descending" from-descending))
   :group 'notmuch-search)
 
 (defcustom notmuch-poll-script nil
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index c00315e8..b95ff71f 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -33,7 +33,7 @@
 (require 'notmuch-parser)
 
 (eval-when-compile (require 'cl))
-(declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line))
+(declare-function notmuch-search "notmuch" (&optional query sort-order target-thread target-line))
 (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-search-find-thread-id "notmuch" (&optional bare))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 44402f8a..334458b7 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -380,7 +380,7 @@ Complete list of currently available key bindings:
 
 \\{notmuch-search-mode-map}"
   (make-local-variable 'notmuch-search-query-string)
-  (make-local-variable 'notmuch-search-oldest-first)
+  (make-local-variable 'notmuch-search-sort-order)
   (make-local-variable 'notmuch-search-target-thread)
   (make-local-variable 'notmuch-search-target-line)
   (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
@@ -959,7 +959,7 @@ PROMPT is the string to prompt with."
 
 (put 'notmuch-search 'notmuch-doc "Search for messages.")
 ;;;###autoload
-(defun notmuch-search (&optional query oldest-first target-thread target-line no-display)
+(defun notmuch-search (&optional query sort-order target-thread target-line no-display)
   "Display threads matching QUERY in a notmuch-search buffer.
 
 If QUERY is nil, it is read interactively from the minibuffer.
@@ -982,7 +982,7 @@ the configured default sort order."
     nil
     ;; Use the default search order (if we're doing a search from a
     ;; search buffer, ignore any buffer-local overrides)
-    (default-value 'notmuch-search-oldest-first)))
+    (default-value 'notmuch-search-sort-order)))
 
   (let* ((query (or query (notmuch-read-query "Notmuch search: ")))
  (buffer (get-buffer-create (notmuch-search-buffer-title query))))
@@ -993,29 +993,26 @@ the configured default sort order."
     ;; Don't track undo information for this buffer
     (set 'buffer-undo-list t)
     (set 'notmuch-search-query-string query)
-    (set 'notmuch-search-oldest-first oldest-first)
+    (set 'notmuch-search-sort-order sort-order)
     (set 'notmuch-search-target-thread target-thread)
     (set 'notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
     (let ((proc (get-buffer-process (current-buffer)))
   (inhibit-read-only t))
       (if proc
-  (error "notmuch search process already running for query `%s'" query)
- )
+  (error "notmuch search process already running for query `%s'" query))
       (erase-buffer)
       (goto-char (point-min))
       (save-excursion
- (let ((proc (notmuch-start-notmuch
-     "notmuch-search" buffer #'notmuch-search-process-sentinel
-     "search" "--format=sexp" "--format-version=4"
-     (if oldest-first
- "--sort=oldest-first"
-       "--sort=newest-first")
-     query))
-      ;; Use a scratch buffer to accumulate partial output.
-      ;; This buffer will be killed by the sentinel, which
-      ;; should be called no matter how the process dies.
-      (parse-buf (generate-new-buffer " *notmuch search parse*")))
+ (let* ((proc (notmuch-start-notmuch
+      "notmuch-search" buffer #'notmuch-search-process-sentinel
+      "search" "--format=sexp" "--format-version=4"
+      (concat "--sort=" (symbol-name sort-order))
+      query))
+       ;; Use a scratch buffer to accumulate partial output.
+       ;; This buffer will be killed by the sentinel, which
+       ;; should be called no matter how the process dies.
+       (parse-buf (generate-new-buffer " *notmuch search parse*")))
   (process-put proc 'parse-buf parse-buf)
   (set-process-filter proc 'notmuch-search-process-filter)
   (set-process-query-on-exit-flag proc nil))))
@@ -1031,20 +1028,29 @@ thread. Otherwise, point will be moved to attempt to be in the
 same relative position within the new buffer."
   (interactive)
   (let ((target-line (line-number-at-pos))
- (oldest-first notmuch-search-oldest-first)
+ (sort-order notmuch-search-sort-order)
  (target-thread (notmuch-search-find-thread-id 'bare))
  (query notmuch-search-query-string))
     ;; notmuch-search erases the current buffer.
-    (notmuch-search query oldest-first target-thread target-line t)
+    (notmuch-search query sort-order target-thread target-line t)
     (goto-char (point-min))))
 
+(defun notmuch-toggle-order (order)
+  (case order
+    (newest-first 'oldest-first)
+    (oldest-first 'newest-first)
+    (from-ascending 'from-descending)
+    (from-descending 'from-ascending)
+    (subject-ascending 'subject-descending)
+    (subject-descending 'subject-ascending)))
+
 (defun notmuch-search-toggle-order ()
   "Toggle the current search order.
 
 This command toggles the sort order for the current search. The
-default sort order is defined by `notmuch-search-oldest-first'."
+default sort order is defined by `notmuch-search-sort-order'."
   (interactive)
-  (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))
+  (set 'notmuch-search-sort-order (notmuch-toggle-order notmuch-search-sort-order))
   (notmuch-search-refresh-view))
 
 (defun notmuch-group-disjunctive-query-string (query-string)
@@ -1068,7 +1074,7 @@ current search results AND the additional query string provided."
     (notmuch-search (if (string= grouped-original-query "*")
  grouped-query
       (concat grouped-original-query " and " grouped-query))
-    notmuch-search-oldest-first)))
+    notmuch-search-sort-order)))
 
 (defun notmuch-search-filter-by-tag (tag)
   "Filter the current search results based on a single tag.
@@ -1077,7 +1083,7 @@ Runs a new search matching only messages that match both the
 current search results AND that are tagged with the given tag."
   (interactive
    (list (notmuch-select-tag-with-completion "Filter by tag: ")))
-  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))
+  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-sort-order))
 
 ;;;###autoload
 (defun notmuch ()
--
2.13.2

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
William Casarin William Casarin
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] emacs: replace oldest-first with sort-order

Here's the before and after with from-ascending sorting on my rss tag:

before: https://jb55.com/s/e51db7073ccfc36d.png
after:  https://jb55.com/s/6a01cd3a0227ddfa.png

Last thing I need to add is a completing-read menu for selecting the
sort-order, since you can only set it in saved searches or with
notmuch-saved-search-sort-order at the moment.

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch