From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 93DCD431FBF for ; Wed, 7 May 2014 04:21:46 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 E8Cp5+8RTrMh for ; Wed, 7 May 2014 04:21:42 -0700 (PDT) Received: from mail-we0-f172.google.com (mail-we0-f172.google.com [74.125.82.172]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id CFA3C431FC3 for ; Wed, 7 May 2014 04:21:39 -0700 (PDT) Received: by mail-we0-f172.google.com with SMTP id k48so841742wev.3 for ; Wed, 07 May 2014 04:21:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RdrK3DqqSYCN3W1Z9pFqjZ0Va8HuEzQVhgWkubstlIE=; b=VuIOfuwrNu7O6CZVrsaj1SaRDurWpN+O9NWW9vHB0wqWSUl6qA9UGyOqIXNyEnC/+O fki5XzSeuRPsKV63v4t4MLXpMWIWd8wHxoBgeeEGPHp203IM73oZN5I6+A89EyuoIzgd EyE0LpfC2ZeeixVYpNbztnUkYtpftR9JEydrdA9/CRUch19M1X2UFWqHB+ZZvq5y4bpy ykKdhFGQtcLjzP4FIG/sDNjAun4wz7+9mrNv8dgZrMZNx3Z545dS9aWpeKyI2eaTJw6e /Mg0voF8KNnNVu00vozovZNjxM4LBAPVW2XoNMzw7NKjIpvPR2WQKudxp7XuQePOAEDu QcAw== X-Gm-Message-State: ALoCoQmkcypotU04eTVfPIk5jziDuM/6DJpZqupRphgSIFgTg6Y9fDYzavb/uSXPD7MUyXxKdJdK X-Received: by 10.180.74.203 with SMTP id w11mr7206384wiv.27.1399461697275; Wed, 07 May 2014 04:21:37 -0700 (PDT) Received: from hotblack-desiato.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by mx.google.com with ESMTPSA id g13sm26211391wjn.15.2014.05.07.04.21.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 May 2014 04:21:36 -0700 (PDT) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id D2BCF1088C5; Wed, 7 May 2014 12:21:34 +0100 (BST) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v2] emacs: Add support for saved search accelerators Date: Wed, 7 May 2014 12:21:34 +0100 Message-Id: <1399461694-25350-2-git-send-email-dme@dme.org> X-Mailer: git-send-email 2.0.0.rc0 In-Reply-To: <1399461694-25350-1-git-send-email-dme@dme.org> References: <1399385776-19918-1-git-send-email-dme@dme.org> <1399461694-25350-1-git-send-email-dme@dme.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: Wed, 07 May 2014 11:21:46 -0000 Extended the saved search definition to allow the inclusion of an accelerator key for the search. Bind 'j' in the common mode map as a leader for such accelerator keys. --- emacs/notmuch-hello.el | 5 ++++- emacs/notmuch-lib.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 3de5238..64d5aa1 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -85,6 +85,7 @@ searches so they still work in customize." (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v"))) (checklist :inline t :format "%v" + (group :format "%v" :inline t (const :format " Key: " :key) (key-sequence :format "%v")) (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v")) (group :format "%v" :inline t (const :format "" :sort-order) (choice :tag " Sort Order" @@ -101,6 +102,7 @@ a plist. Supported properties are :name Name of the search (required). :query Search to run (required). + :key Optional accelerator key. :count-query Optional extra query to generate the count shown. If not present then the :query property is used. @@ -551,7 +553,8 @@ with `notmuch-hello-query-counts'." (when elem (if (> column-indent 0) (widget-insert (make-string column-indent ? ))) - (let* ((name (plist-get elem :name)) + (let* ((key (plist-get elem :key)) + (name (plist-get elem :name)) (query (plist-get elem :query)) (oldest-first (case (plist-get elem :sort-order) (newest-first nil) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 2941da3..f8c5f96 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -25,6 +25,10 @@ (require 'mm-decode) (require 'cl) +(declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line continuation)) +(declare-function notmuch-saved-search-get "notmuch-hello" (saved-search field)) +(defvar notmuch-saved-searches) ;; In `notmuch-hello.el'. + (defvar notmuch-command "notmuch" "Command to run the notmuch binary.") @@ -130,6 +134,7 @@ For example, if you wanted to remove an \"inbox\" tag and add an (define-key map "m" 'notmuch-mua-new-mail) (define-key map "=" 'notmuch-refresh-this-buffer) (define-key map "G" 'notmuch-poll-and-refresh-this-buffer) + (define-key map "j" 'notmuch-jump) map) "Keymap shared by all notmuch modes.") @@ -845,6 +850,47 @@ status." (defvar notmuch-show-process-crypto nil) (make-variable-buffer-local 'notmuch-show-process-crypto) +;; Jump key support: + +(defvar notmuch-jump-search nil) +(defun notmuch-jump-map () + (let ((map (make-sparse-keymap)) + help) + (set-keymap-parent map minibuffer-local-map) + (suppress-keymap map) + (dolist (saved-search notmuch-saved-searches) + (let ((key (notmuch-saved-search-get saved-search :key))) + (when key + (define-key map key `(lambda () + (interactive) + (setq notmuch-jump-search ',saved-search) + (exit-minibuffer))) + (push (format "%s: %s" + (propertize key 'face 'minibuffer-prompt) + (notmuch-saved-search-get saved-search :name)) + help)))) + ;; Hitting ? displays a quick hint of the accelerators. + (define-key map "?" `(lambda () + (interactive) + (message "%s" + (mapconcat #'identity + ;; Reverse the list so + ;; that elements appear + ;; in the same order as + ;; `notmuch-saved-searches'. + (reverse ',help) + " ")))) + map)) + +(defun notmuch-jump () + "Read a saved search accelerator key and perform the search." + (interactive) + (setq notmuch-jump-search nil) + (read-from-minibuffer "Jump to saved search: " nil (notmuch-jump-map)) + (when notmuch-jump-search + (notmuch-search (notmuch-saved-search-get notmuch-jump-search :query) + (notmuch-saved-search-get notmuch-jump-search :oldest-first)))) + (provide 'notmuch-lib) ;; Local Variables: -- 2.0.0.rc0