From: Mark Walters Date: Fri, 20 May 2016 20:13:01 +0000 (+0100) Subject: [PATCH 0/2] Address completion configuration X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=43089331010a2f05b0552f313839bd3dd17f0eaa;p=notmuch-archives.git [PATCH 0/2] Address completion configuration --- diff --git a/c5/72c09e4e9e28977fed9a0d3cb76281fcf1bc41 b/c5/72c09e4e9e28977fed9a0d3cb76281fcf1bc41 new file mode 100644 index 000000000..5e10c23c9 --- /dev/null +++ b/c5/72c09e4e9e28977fed9a0d3cb76281fcf1bc41 @@ -0,0 +1,265 @@ +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 6BBBD6DE0281 + for ; Fri, 20 May 2016 13:13:26 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.182 +X-Spam-Level: +X-Spam-Status: No, score=0.182 tagged_above=-999 required=5 tests=[AWL=-0.248, + DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, + 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 0FBO0F28V99r for ; + Fri, 20 May 2016 13:13:18 -0700 (PDT) +Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com + [74.125.82.48]) by arlo.cworth.org (Postfix) with ESMTPS id 0F6E66DE01CE for + ; Fri, 20 May 2016 13:13:18 -0700 (PDT) +Received: by mail-wm0-f48.google.com with SMTP id v200so2818136wmv.0 + for ; Fri, 20 May 2016 13:13:17 -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=di1RZqcqxyYRh+BASsJS1UDdmRgJtVtovHAKBWtI60E=; + b=yTjJ75N1BpirPdvPp0Pz+mtEawM9CuVH1cNpia3bDGVHmKlzkgcu2BjuJwWgfFYLUe + Y/tgL7Hb2Rk9o4NxEdMg9mbP8dbNpKONhuOLLrwGcWpkgCHiH5UfqkQqeH1ob9OPdf9w + DsyL/4IHyMSvmCz+7zplRmckGFQ8q23NyZs1Aq0FzbykkClAQItZWnNVCWN1qDVUafyH + PWNM2/OqJ7a3OnfbS+pj8eNHfLSE2TJUg5MeKcevZPJdntm1TUpXPa+nSYrJEGaXW+V9 + JgZJUtfsK50He2Th8RD5V5HZFkZ/SA2ezttjIiwavpO4Hvt57FCxwhDMfPmVvGz8ZyjU + Us8g== +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=di1RZqcqxyYRh+BASsJS1UDdmRgJtVtovHAKBWtI60E=; + b=c3iZYCTtS/hzQfbblY2ckf+9E/SFSNfpGh8aK6khySiThyjWvDcQxkOseI4PUUcMV3 + VO5bZxSkTV94trQi3NvGGFzHNEoOD/fFbIaGn71pkqX+14SV01RjSQaOHEsF5cBX1ilY + PqnUdFCg1axjQ28q5FNEnW4AsiZMnvkePU6An0D2znQYB1WknNEOJdWFr85Z+v+anP0J + etFTXF+kcg5CMK8N88FoXBra/sQBSdzoz2S4BTwcjaFnZgM33iusHevnsGNrjsA7HSNT + cQFRa/a64LUch0nZvQat+AHl/WWqqy9Ca4+KGmka8wlxuh5ezEXCdoaeTS66AlYdslOW + jsVA== +X-Gm-Message-State: + AOPr4FVQgfNV6IhgDom9MGhFxzMRJUozYUAs5FgvIJwYzBSP53n0838LkXlW/jcGkmaG0A== +X-Received: by 10.28.56.4 with SMTP id f4mr5289227wma.70.1463775196014; + Fri, 20 May 2016 13:13:16 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by smtp.gmail.com with ESMTPSA id ug8sm21346747wjc.42.2016.05.20.13.13.13 + (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Fri, 20 May 2016 13:13:13 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH 0/2] Address completion configuration +Date: Fri, 20 May 2016 21:13:01 +0100 +Message-Id: <1463775183-16234-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: Fri, 20 May 2016 20:13:26 -0000 + +These two patches allow some customization of the notmuch-address +completion. + +The first patch is very similar to the patch at +id:1463558813-23603-1-git-send-email-markwalters1009@gmail.com + +The second allows the user to use the internal completion on a case by +case basis. Typically this would be useful for users who normally use +some external command for completion, but would like to use the +internal completion when that fails. + +This necessitated some changes to the first patch: it made sense to +separate the customisation of the internal address (as this will be +also used for the case by case uses of the internal completion) from +the choice of whether to use internal or external completion by +default. I include the inter-diff of the first patch and the previous +version at +id:1463558813-23603-1-git-send-email-markwalters1009@gmail.com at the +end of this email. + +The downside is that it does mean there is an extra defcustom, but the +code is slightly cleaner. + +It might make sense to have a keybinding for company-complete +and/or notmuch-address-toggle-internal-completion in +notmuch-mesage-mode but I had no idea what bindings would make sense. + +I don't know how many people still use external completion -- but the +extra complexity on top of the previous version is fairly small. Also, +I haven't tested this heavily -- and there are quite a lot of cases. + +Best wishes + +Mark + + + + +Mark Walters (2): + emacs: address completion, allow sender/recipient and filters + emacs: address: allow internal completion on an individual basis + + emacs/notmuch-address.el | 154 ++++++++++++++++++++++++++++++++++------------- + emacs/notmuch-company.el | 10 ++- + emacs/notmuch-mua.el | 3 +- + 3 files changed, 121 insertions(+), 46 deletions(-) + + +inter-diff from id:1463558813-23603-1-git-send-email-markwalters1009@gmail.com + +diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el +index 62df8ba..3e7bdab 100644 +--- a/emacs/notmuch-address.el ++++ b/emacs/notmuch-address.el +@@ -39,34 +39,45 @@ + "t indicates that full completion address harvesting has been + finished") + +-(defcustom notmuch-address-command '(sent nil) +- "Determines how to generate address completion candidates. ++(defcustom notmuch-address-command 'internal ++ "Determines how address completion candidates are generated. + + If it is a string then that string should be an external program + which must take a single argument (searched string) and output a + list of completion candidates, one per line. + +-Alternatively, it can be a (non-nil) list, in which case internal +-completion is used; in this case the list should have form +-'(DIRECTION FILTER), where DIRECTION is either sent or received +-and specifies whether the candidates are searched in messages +-sent by the user or received by the user (note received by is +-much faster), and FILTER is either nil or a filter-string, such +-as \"date:1y..\" to append to the query. ++Alternatively, it can be the symbol 'internal, in which case ++internal completion is used; the variable ++`notmuch-address-internal-completion` can be used to customize ++this case. + +-If this variable is nil then address completion is disabled." ++Finally, if this variable is nil then address completion is ++disabled." + :type '(radio +- (list :tag "Use internal address completion" +- (radio +- :tag "Base completion on messages you have" +- :value sent +- (const :tag "sent (more accurate)" sent) +- (const :tag "received (faster)" received)) +- (radio :tag "Filter messages used for completion" +- (const :tag "Use all messages" nil) +- (string :tag "Filter query"))) ++ (const :tag "Use internal address completion" internal) + (const :tag "Disable address completion" nil) + (string :tag "Use external completion command")) ++ :group 'notmuch-send ++ :group 'notmuch-external) ++ ++(defcustom notmuch-address-internal-completion '(sent nil) ++ "Determines how internal address completion generates candidates. ++ ++This should be a list of the form '(DIRECTION FILTER), where ++ DIRECTION is either sent or received and specifies whether the ++ candidates are searched in messages sent by the user or received ++ by the user (note received by is much faster), and FILTER is ++ either nil or a filter-string, such as \"date:1y..\" to append ++ to the query." ++ :type '(list :tag "Use internal address completion" ++ (radio ++ :tag "Base completion on messages you have" ++ :value sent ++ (const :tag "sent (more accurate)" sent) ++ (const :tag "received (faster)" received)) ++ (radio :tag "Filter messages used for completion" ++ (const :tag "Use all messages" nil) ++ (string :tag "Filter query"))) + ;; We override set so that we can clear the cache when this changes + :set (lambda (symbol value) + (set-default symbol value) +@@ -108,13 +119,10 @@ to know how address selection is made by default." + + (defun notmuch-address-setup () + (let* ((use-company (and notmuch-address-use-company +- notmuch-address-command +- (listp notmuch-address-command) ++ (eq notmuch-address-command 'internal) + (require 'company nil t))) + (pair (cons notmuch-address-completion-headers-regexp +- (if use-company +- #'company-manual-begin +- #'notmuch-address-expand-name)))) ++ #'notmuch-address-expand-name))) + (when use-company + (notmuch-company-setup)) + (unless (memq pair message-completion-alist) +@@ -137,7 +145,7 @@ The candidates are taken from `notmuch-address-completions'." + elisp-based implementation or older implementation requiring + external commands." + (cond +- ((and notmuch-address-command (listp notmuch-address-command)) ++ ((eq notmuch-address-command 'internal) + (when (not notmuch-address-full-harvest-finished) + ;; First, run quick synchronous harvest based on what the user + ;; entered so far +@@ -149,7 +157,12 @@ external commands." + (process-lines notmuch-address-command original)))) + + (defun notmuch-address-expand-name () +- (when notmuch-address-command ++ (cond ++ ((and (eq notmuch-address-command 'internal) ++ notmuch-address-use-company ++ (bound-and-true-p company-mode)) ++ (company-manual-begin)) ++ (notmuch-address-command + (let* ((end (point)) + (beg (save-excursion + (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*") +@@ -175,7 +188,8 @@ external commands." + (delete-region beg end) + (insert chosen)) + (message "No matches.") +- (ding))))) ++ (ding)))) ++ (t nil))) + + ;; Copied from `w3m-which-command'. + (defun notmuch-address-locate-command (command) +@@ -232,8 +246,8 @@ Address harvesting may take some time so the address collection runs + asynchronously unless SYNCHRONOUS is t. In case of asynchronous + execution, CALLBACK is called when harvesting finishes." + +- (let* ((sent (eq (car notmuch-address-command) 'sent)) +- (config-query (cadr notmuch-address-command)) ++ (let* ((sent (eq (car notmuch-address-internal-completion) 'sent)) ++ (config-query (cadr notmuch-address-internal-completion)) + (prefix-query (when addr-prefix + (format "%s:%s*" (if sent "to" "from") addr-prefix))) + (from-or-to-me-query +diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el +index 399e138..93a4d4b 100644 +--- a/emacs/notmuch-mua.el ++++ b/emacs/notmuch-mua.el +@@ -276,8 +276,7 @@ mutiple parts get a header." + + (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]" + "Notmuch message composition mode. Mostly like `message-mode'" +- (when notmuch-address-command +- (notmuch-address-setup))) ++ (notmuch-address-setup)) + + (put 'notmuch-message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) + +