Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 0FBCE429E29 for ; Sat, 4 Jun 2011 13:39:45 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3h3geMVyq2sJ for ; Sat, 4 Jun 2011 13:39:44 -0700 (PDT) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 12BE5431FB6 for ; Sat, 4 Jun 2011 13:39:43 -0700 (PDT) Received: by bwg12 with SMTP id 12so2787392bwg.26 for ; Sat, 04 Jun 2011 13:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=hsaPVvihgqV45JFWCwmf+pCH0w7iPwSkjicEiy0riiA=; b=rOisKwVHmj7XoaY9rJEEtzPyOsKVCL+pt1v2jKcgzXxr1zL57ErizwyfX5nIfTRnVr jt+WbftIwRfS9nLacWpZmFobZLMczRQjzCiVPqK/19SttuLoYeSpC85CvAaH3lDuq+TD ojwBwghMUrGwOzUHb8RsdfPdIN5UHo/ZEOXGY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; b=UNzJDXE6wVf5paV6lccOonnB1ecNM7OZp7AbOTJddYPf3nSBhJXsYdqqKVaCCyajbn Gb5HQNBnHn+5yNGBZYaNq0ZcB5amzcLUoiEBjDqqUqdzU3hfo/JrdKvf4+OWF6XjEr5t brOUFdlniSDUfWCeOZTI3fHQDKmPDaIxobrVc= Received: by 10.204.84.217 with SMTP id k25mr570718bkl.54.1307219982588; Sat, 04 Jun 2011 13:39:42 -0700 (PDT) Received: from localhost (dslb-088-069-155-133.pools.arcor-ip.net [88.69.155.133]) by mx.google.com with ESMTPS id g2sm2172032bkz.23.2011.06.04.13.39.40 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Jun 2011 13:39:41 -0700 (PDT) From: Daniel Schoepe To: Austin Clements Subject: Re: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter In-Reply-To: <87mxhxjrry.fsf@gilead.invalid> References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com> <87mxhxjrry.fsf@gilead.invalid> User-Agent: Notmuch/0.5-217-gd1f0224 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Sat, 04 Jun 2011 22:39:32 +0200 Message-ID: <87k4d1jpq3.fsf@gilead.invalid> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Sat, 04 Jun 2011 20:39:45 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Sorry, forgot to actually test notmuch-search entirely with this change and not just the completion. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-emacs-Tab-completion-for-notmuch-search-and-notmuch-.patch Content-Transfer-Encoding: quoted-printable From=20cb172efc1dea2507566db587f960c073373e0159 Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Sat, 4 Jun 2011 14:17:44 +0200 Subject: [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter This patch adds completion with in the minibuffer for notmuch-search and notmuch-search-filter. =2D-- emacs/notmuch.el | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3311fe8..a2db852 100644 =2D-- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,6 +72,9 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) =20 +(defvar notmuch-completions nil + "List of completions used in notmuch-query-completions") + (defun notmuch-select-tag-with-completion (prompt &rest search-terms) (let ((tag-list (with-output-to-string @@ -882,6 +885,34 @@ characters as well as `_.+-'. (concat "*notmuch-search-" query "*")) ))) =20 +(defun notmuch-query-completions (string) + "Return possible completions for STRING." + (cond + ;; this ugly regexp is used to get the last word of the input + ;; possibly preceded by a '(' + ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string) + (mapcar (lambda (compl) + (concat (match-string-no-properties 1 string) compl)) + (all-completions (match-string-no-properties 2 string) + notmuch-completions))) + (t (list string)))) + +(defun notmuch-read-query (prompt) + "Read a notmuch-query from the minibuffer with completion. + +PROMPT is the string to prompt with." + (let ((keymap (copy-keymap minibuffer-local-map)) + (minibuffer-completion-table (completion-table-dynamic #'notmuch-query-co= mpletions))) + ;; this was simpler than convincing completing-read to accept spaces: + (define-key keymap (kbd "") 'minibuffer-complete) + (setq notmuch-completions + (append (list "folder:" "thread:" "id:" "date:" "from:" "to:" + "subject:" "attachment:") + (mapcar (lambda (tag) + (concat "tag:" tag)) + (process-lines "notmuch" "search-tags")))) + (read-from-minibuffer prompt nil keymap nil minibuffer-history nil nil= ))) + ;;;###autoload (defun notmuch-search (query &optional oldest-first target-thread target-l= ine continuation) "Run \"notmuch search\" with the given query string and display results. @@ -893,7 +924,7 @@ The optional parameters are used as follows: current if it appears in the search results. target-line: The line number to move to if the target thread does not appear in the search results." =2D (interactive "sNotmuch search: ") + (interactive (list (notmuch-read-query "Notmuch search: "))) (let ((buffer (get-buffer-create (notmuch-search-buffer-title query)))) (switch-to-buffer buffer) (notmuch-search-mode) @@ -991,7 +1022,7 @@ search." =20 Runs a new search matching only messages that match both the current search results AND the additional query string provided." =2D (interactive "sFilter search: ") + (interactive (list (notmuch-read-query "Filter search: "))) (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-rege= xp query) (concat "( " query " )") query))) =2D-=20 1.7.5.3 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJN6pgEAAoJEIaTAtce+Z+JygUP/0JhM/g994Yz/4YnNvyqYLvf nL8ca0fB8bZUwZ3K2egJJbvf6M4mtOQ1k7bjwE1sZeEF3Sjmf/ePGZo1tgF3yElk mi52c5Jg+5FdQ4un0hZ/j1eed4OgvCkrt8+qsNjRh5Jfq3z4XjeKt7yoVnwrwWzm eV7jymvcYczSk0LMmAnaHj7bwTomFHgDkqIMstLZF5yiMqe8SCMqKu9IN6crLVtS 8md4jI7myoTB69r5BUuV+cpISfVj6MCW1kbAzS2WEfs0+DlCbNksMbtSvQ/eG+z8 NZ++WxLzG1fEejOYVtwuUfeNguLv25SvRZ7HQCVdrYed5TpNFkmCvn/O0olANTU2 F2fTi/zN1uOUn0ldx4guoABBY98ZlHr+7oq3LzuOuYNmQ+vfcGk9LQmggmNWhQAG pR5xmiWB5yiAoXYgtqcexJlE2xs70IgbcMRQKUQGCPBbfgInHsFW8J2mulz3w7j5 Gp33OEAn7PGNTf8o0G7Hb3kShVmo+sBr9pfv2WAr0l/nb/QLSOBOOorzF0YVBpZT HApFKNnw3ipp2bbBSQRjUklRL/1L1siW9ltqvPRMovrKinJNwfR3BpqNtUcVkRaT jKjLJvWZ3x4gxvjbgPBpu0AxV+2JtZaqGfLCgFt+He3g4FvQj9vjZm9ds3jzQqS7 h+f+AtBk7sNgcZFn9vTe =H6kS -----END PGP SIGNATURE----- --==-=-=--