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 EBD96429E25 for ; Fri, 23 Dec 2011 19:48:02 -0800 (PST) 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 0DGIGIfFU8sl for ; Fri, 23 Dec 2011 19:48:01 -0800 (PST) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 7F79C429E26 for ; Fri, 23 Dec 2011 19:48:01 -0800 (PST) Received: by wibhq2 with SMTP id hq2so4263920wib.26 for ; Fri, 23 Dec 2011 19:48:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer; bh=oY82o7LylFAewpy5yxV5y4zpMoecmULBLzOmhDB6Mlw=; b=Z0l5emhWQ5ix6qqGyCnHNG1C+ZXQKE+lRz2AFkc5tGUhBdVOedHZIp9l0dQwPXIWRh 2/yiBczaNIwx6KyKc1/BDI8bc3ecfqfn/WCDRJ037W7fk7dA/u1J1YV6JZZ31wGpMfRp D2DQh9S/cZPcGnL7i2KJYmXh9U+rJA8Tb8GB0= Received: by 10.180.19.74 with SMTP id c10mr37386068wie.8.1324698480230; Fri, 23 Dec 2011 19:48:00 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id fg15sm15920365wbb.7.2011.12.23.19.47.59 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Dec 2011 19:47:59 -0800 (PST) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH 1/3] emacs: use a single history for all searches Date: Sat, 24 Dec 2011 07:47:14 +0400 Message-Id: <1324698436-8532-1-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.7.3 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, 24 Dec 2011 03:48:03 -0000 There are two ways to do search in Emacs UI: search widget in notmuch-hello buffer and `notmuch-search' function bound to "s". Before the change, these search mechanisms used different history lists. The patch makes notmuch-hello search use the same history list as `notmuch-search' function. --- emacs/notmuch-hello.el | 35 +++++++++++++++-------------------- emacs/notmuch.el | 8 +++----- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 333d4c1..ba34ac5 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -32,8 +32,11 @@ (defvar notmuch-hello-search-bar-marker nil "The position of the search bar within the notmuch-hello buffer.") -(defcustom notmuch-recent-searches-max 10 - "The number of recent searches to store and display." +(defvar notmuch-query-history nil + "Variable to store history for notmuch queries.") + +(defcustom notmuch-hello-recent-searches-max 10 + "The number of recent searches to display." :type 'integer :group 'notmuch) @@ -154,15 +157,9 @@ International Bureau of Weights and Measures." (defvar notmuch-hello-url "http://notmuchmail.org" "The `notmuch' web site.") -(defvar notmuch-hello-recent-searches nil) - (defun notmuch-hello-remember-search (search) - (setq notmuch-hello-recent-searches - (delete search notmuch-hello-recent-searches)) - (push search notmuch-hello-recent-searches) - (if (> (length notmuch-hello-recent-searches) - notmuch-recent-searches-max) - (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-searches)))) + (let ((history-delete-duplicates t)) + (add-to-history 'notmuch-query-history search))) (defun notmuch-hello-nice-number (n) (let (result) @@ -512,18 +509,18 @@ Complete list of currently available key bindings: (put-text-property (1- (point)) (point) 'invisible t) (widget-insert "\n") - (when notmuch-hello-recent-searches + (when notmuch-query-history (widget-insert "\nRecent searches: ") (widget-create 'push-button :notify (lambda (&rest ignore) - (setq notmuch-hello-recent-searches nil) + (setq notmuch-query-history nil) (notmuch-hello-update)) "clear") (widget-insert "\n\n") - (let ((start (point)) - (nth 0)) - (mapc (lambda (search) - (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth)))) + (let ((start (point))) + (loop for i from 1 to notmuch-hello-recent-searches-max + for search in notmuch-query-history do + (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i)))) (set widget-symbol (widget-create 'editable-field ;; Don't let the search boxes be @@ -550,9 +547,7 @@ Complete list of currently available key bindings: (notmuch-hello-add-saved-search widget)) :notmuch-saved-search-widget widget-symbol "save")) - (widget-insert "\n") - (setq nth (1+ nth))) - notmuch-hello-recent-searches) + (widget-insert "\n")) (indent-rigidly start (point) notmuch-hello-indent))) (when alltags-alist @@ -581,7 +576,7 @@ Complete list of currently available key bindings: (let ((start (point))) (widget-insert "\n\n") (widget-insert "Type a search query and hit RET to view matching threads.\n") - (when notmuch-hello-recent-searches + (when notmuch-query-history (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n") (widget-insert "Save recent searches with the `save' button.\n")) (when notmuch-saved-searches diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 270f983..546f306 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,9 +72,6 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) -(defvar notmuch-query-history nil - "Variable to store minibuffer history for notmuch queries") - (defun notmuch-select-tag-with-completion (prompt &rest search-terms) (let ((tag-list (with-output-to-string @@ -902,8 +899,9 @@ PROMPT is the string to prompt with." (t (list string))))))) ;; this was simpler than convincing completing-read to accept spaces: (define-key keymap (kbd "") 'minibuffer-complete) - (read-from-minibuffer prompt nil keymap nil - 'notmuch-query-history nil nil)))) + (let ((history-delete-duplicates t)) + (read-from-minibuffer prompt nil keymap nil + 'notmuch-query-history nil nil))))) ;;;###autoload (defun notmuch-search (query &optional oldest-first target-thread target-line continuation) -- 1.7.7.3