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 9BA08431FBC for ; Tue, 11 Dec 2012 01:00:48 -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 87XO999por-f for ; Tue, 11 Dec 2012 01:00:48 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B6243431FAE for ; Tue, 11 Dec 2012 01:00:47 -0800 (PST) Received: by mail-we0-f181.google.com with SMTP id t11so1690896wey.26 for ; Tue, 11 Dec 2012 01:00:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=y/RuoVVMQ+Ef+LcIvjpvURpR3Rg2xFKstQMpTDN6RS0=; b=CgKZi/X4+Jl+TuIKwiSFxwnitPzExBc5GBnoNnh7aQjiqSXheQBWUsbCBp6S5Ycuik 8iIDxVpZyCz6dQq4Bbs5AawiTllqwoKmwLRH0reYs5+vJrEtBIqd+7z8DpWhLo3hQig+ M+vByqEVjWxZinLyLQ9lp32rJ6cPCn0kNYVy9/0gYPuOKRBeMYBfYDBTtqK8hFGueHDG diHjk/qMDlJxPt0/tHgH+b1hsdEcS8Q8lsID4nq9iUCg0gy8z5d8S9XsQqsNdJxYyYQJ 2VKJszQZiiRPCDzHkaSSllNKsGKvErt0/Moilh5UF5mLpBYMSbDvg+dBg/W5zHdnDVOL Ydsw== Received: by 10.180.102.234 with SMTP id fr10mr15387961wib.17.1355216446502; Tue, 11 Dec 2012 01:00:46 -0800 (PST) Received: from luz3.lille.inria.fr ([193.51.236.232]) by mx.google.com with ESMTPS id b1sm15376748wix.11.2012.12.11.01.00.45 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Dec 2012 01:00:45 -0800 (PST) From: Damien Cassou To: notmuch@notmuchmail.org Subject: [PATCH 2/4] emacs: Make tags in notmuch-show header-line clickable Date: Tue, 11 Dec 2012 10:00:35 +0100 Message-Id: <1355216437-21109-3-git-send-email-damien.cassou@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355216437-21109-1-git-send-email-damien.cassou@gmail.com> References: <1355216437-21109-1-git-send-email-damien.cassou@gmail.com> 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: Tue, 11 Dec 2012 09:00:48 -0000 Signed-off-by: Damien Cassou --- emacs/notmuch-tagger.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch-tagger.el b/emacs/notmuch-tagger.el index 6fcebff..38b858a 100644 --- a/emacs/notmuch-tagger.el +++ b/emacs/notmuch-tagger.el @@ -23,12 +23,64 @@ ;;; Code: ;; +(defun notmuch-tagger-header-button-present-p () + "Check if `header-button' can be loaded or is already loaded. + +`header-button' is a third-party library which facilitates the +creation of links in emacs header-line. This function tries to +`require' `header-button' and returns nil if and only if this +fails." + (require 'header-button nil t)) + +(defun notmuch-tagger-goto-target (tag) + "Show a `notmuch-search' buffer for the TAG." + (notmuch-search (concat "tag:\"" tag "\""))) + +(defun notmuch-tagger-header-button-action (button) + "Open `notmuch-search' for the tag referenced by BUTTON. +This function depends on the presence of the `header-button' +library. Please call `notmuch-tagger-header-button-present-p' to +test if the library is present before calling this function." + (let ((tag (header-button-get button 'notmuch-tagger-tag))) + (notmuch-tagger-goto-target tag))) + +(eval-after-load "header-button" + '(define-button-type 'notmuch-tagger-header-button-type + 'supertype 'header + 'action #'notmuch-tagger-header-button-action + 'follow-link t)) + +(defun notmuch-tagger-really-make-header-link (tag) + "Return a property list that presents a link to TAG. + +The returned property list will only work in the header-line. +Additionally, this function depends on the presence of the +`header-button' library. Please call +`notmuch-tagger-header-button-present-p' to test if library is +present before calling this function." + (header-button-format + tag + :type 'notmuch-tagger-header-button-type + 'notmuch-tagger-tag tag + 'help-echo (format "%s: Search other messages like this" tag))) + +(defun notmuch-tagger-make-header-link (tag) + "Return a property list to present TAG as a link to search. + +This only works if `header-button' is loaded. Simply returns tag +if not." + (if (notmuch-tagger-header-button-present-p) + (notmuch-tagger-really-make-header-link tag) + tag)) + (defun notmuch-tagger-format-tags-header-line (tags) "Format TAGS as a `mode-line-format' template. The result is suitable for inclusion in `header-line-format'." (list "(" - (notmuch-intersperse tags " ") + (notmuch-intersperse + (mapcar #'notmuch-tagger-make-header-link tags) + " ") ")")) (provide 'notmuch-tagger) -- 1.7.10.4