From: Mark Walters Date: Tue, 17 May 2016 21:01:05 +0000 (+0100) Subject: [WIP PATCH] Allow user to sort address completion by count X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7aed9769db6d6887cf8e04e7bfb01bd1cec9bea3;p=notmuch-archives.git [WIP PATCH] Allow user to sort address completion by count --- diff --git a/cd/545a196d6a160a1adbde2afe0f47340843bb44 b/cd/545a196d6a160a1adbde2afe0f47340843bb44 new file mode 100644 index 000000000..cdbbee88d --- /dev/null +++ b/cd/545a196d6a160a1adbde2afe0f47340843bb44 @@ -0,0 +1,177 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id A78C46DE0217 + for ; Tue, 17 May 2016 14:01:20 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.313 +X-Spam-Level: +X-Spam-Status: No, score=-0.313 tagged_above=-999 required=5 tests=[AWL=0.257, + DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, + RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id itGiU1RcJdSJ for ; + Tue, 17 May 2016 14:01:12 -0700 (PDT) +Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com + [74.125.82.52]) by arlo.cworth.org (Postfix) with ESMTPS id 7BDCB6DE01D0 for + ; Tue, 17 May 2016 14:01:12 -0700 (PDT) +Received: by mail-wm0-f52.google.com with SMTP id g17so50596952wme.1 + for ; Tue, 17 May 2016 14:01:12 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id; + bh=4SHzLp1cGCQCZ8uhtjhfDOa5cFbJA8TTkwrUPqSO0I8=; + b=bKQg3Yi/PPHUs8HOZ7h26zHycA1LcbzFufsyu6mKJFGDEcmw2+2AcN2NbXRwwhvheX + cW2N+FXC1TUt6Vw4HGVFErLFZtFCuKQ1UQqnujqzp+KhOrP8Tur6YtqrHfymO/8a0XyJ + SZ0QQZx3qJrBVPdZp8Jn4ZmHN1o+zv+jsG9HP9V2m5O6sGtbWWTn/rwDbKRalAsdd1nx + h1QNmuaMW9wM+Nex0B+OfvlL1t5DiNCxeyPk8qiuaOZZkL4bGc49Zty38PdTPDvIT0KA + b99XQLCPqDETvmpVDSbTTXdlkWzqYk9AiUB9F969qz8Ilid6r9mG1sUE5wjUCANvgvfm + ZlKw== +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id; + bh=4SHzLp1cGCQCZ8uhtjhfDOa5cFbJA8TTkwrUPqSO0I8=; + b=jIkIeZAoj6wcjDq9sTLM1zzKSs+oRZ/8XzkM39yqMSuHvgLyp0Eq9eKAn37PxxmUdj + 3brt0Or1U3EDZrEdcSAAbwcsBXEvYtlsf+H8NRKGAy4Ouv3POaBM3P8Sfbs+nQvlhVJ6 + +r73gWo1HrtJQsNfcqsnS+s3Dn1Ubi3ZU6CDIr0tIIN6BH0IW23J6eNhloDWnTZ/H9pa + TMBTntL6IBK4qZdgBrpvTCP1TgSQNu78od/PXuCXEo3UPZo5td4avMYRC+Oifp9lbLqD + MPwruq7DtzQ7ave7yfy+MQC34BTN046eVovNwaeZAReqVCYgBPP8QePamdDdDAEH/pUT + 4MuA== +X-Gm-Message-State: + AOPr4FXJ7av0F57mNu4R2L/QaeCK67IF6MXGW/ptZQtpdt5sJGTQAC9vbY3a8E1MyVE4aQ== +X-Received: by 10.194.89.33 with SMTP id bl1mr1757936wjb.43.1463518870382; + Tue, 17 May 2016 14:01:10 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by smtp.gmail.com with ESMTPSA id xt9sm5032582wjb.17.2016.05.17.14.01.09 + (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Tue, 17 May 2016 14:01:09 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [WIP PATCH] Allow user to sort address completion by count +Date: Tue, 17 May 2016 22:01:05 +0100 +Message-Id: <1463518865-23317-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 2.1.4 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 17 May 2016 21:01:20 -0000 + +--- + +This is a wip patch which allows the user to sort the address +completions by count. It seems to work but is not heavily +tested. However, I won't have time to work on this for a bit so, since +there was some discussion on irc about this, I thought it worth +posting. + +Best wishes + +Mark + + + + emacs/notmuch-address.el | 33 ++++++++++++++++++++++++++++----- + emacs/notmuch-company.el | 3 ++- + 2 files changed, 30 insertions(+), 6 deletions(-) + +diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el +index aafbe5f..0df8a48 100644 +--- a/emacs/notmuch-address.el ++++ b/emacs/notmuch-address.el +@@ -51,6 +51,12 @@ to know how address selection is made by default." + :group 'notmuch-send + :group 'notmuch-external) + ++(defcustom notmuch-address-sort 't ++ "Sort to use for returned address completions" ++ :type 'sexp ++ :group 'notmuch-send ++ :group 'notmuch-external) ++ + (defvar notmuch-address-last-harvest 0 + "Time of last address harvest") + +@@ -102,9 +108,23 @@ The candidates are taken from `notmuch-address-completions'." + (re (regexp-quote substring))) + (maphash (lambda (key val) + (when (string-match re key) +- (push key candidates))) ++ (push (cons key val) candidates))) + notmuch-address-completions) +- candidates)) ++ ++ (let ((sorted-candidates ++ (cond ((eq notmuch-address-sort 'alphabetical) ++ (sort candidates (lambda (a b) (string< (car a) (car b))))) ++ ((eq notmuch-address-sort 'count) ++ (sort candidates (lambda (a b) (> (cdr a) (cdr b))))) ++ ((null notmuch-address-sort) candidates) ++ (t ++ (sort candidates ++ (lambda (a b) ++ (or (> (cdr a) (cdr b)) ++ (and (= (cdr a) (cdr b)) ++ (string< (car a) (car b)))))))))) ++ ++ (mapcar 'car sorted-candidates)))) + + (defun notmuch-address-options (original) + "Returns a list of completion candidates. Uses either +@@ -171,8 +191,10 @@ external commands." + (throw 'found-command bin)))))))) + + (defun notmuch-address-harvest-addr (result) +- (let ((name-addr (plist-get result :name-addr))) +- (puthash name-addr t notmuch-address-completions))) ++ (let ((name-addr (plist-get result :name-addr)) ++ (count (plist-get result :count))) ++ (message "Putting name %s with count %s" name-addr count) ++ (puthash name-addr count notmuch-address-completions))) + + (defun notmuch-address-harvest-handle-result (obj) + (notmuch-address-harvest-addr obj)) +@@ -201,12 +223,13 @@ time so the address collection runs asynchronously unless + SYNCHRONOUS is t. In case of asynchronous execution, CALLBACK is + called when harvesting finishes." + (let* ((from-me-query (mapconcat (lambda (x) (concat "from:" x)) (notmuch-user-emails) " or ")) +- (query (if filter-query ++ (query (if (stringp filter-query) + (format "(%s) and (%s)" from-me-query filter-query) + from-me-query)) + (args `("address" "--format=sexp" "--format-version=2" + "--output=recipients" + "--deduplicate=address" ++ "--output=count" + ,query))) + (if synchronous + (mapc #'notmuch-address-harvest-addr +diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el +index b881d6d..bf3c6d8 100644 +--- a/emacs/notmuch-company.el ++++ b/emacs/notmuch-company.el +@@ -80,7 +80,8 @@ + (match (if (string-match notmuch-company-last-prefix arg) + (match-end 0) + 0)) +- (no-cache t)))) ++ (no-cache t) ++ (sorted t)))) + + + (provide 'notmuch-company) +-- +2.1.4 +