From: Damien Cassou <damien.cassou@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/4] emacs: Make tags in notmuch-show header-line clickable
Date: Mon, 10 Dec 2012 15:32:42 +0100 [thread overview]
Message-ID: <1355149964-27905-3-git-send-email-damien.cassou@gmail.com> (raw)
In-Reply-To: <1355149964-27905-1-git-send-email-damien.cassou@gmail.com>
Signed-off-by: Damien Cassou <damien.cassou@gmail.com>
---
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..0d4d471 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
next prev parent reply other threads:[~2012-12-10 14:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-10 14:32 [PATCH v3] emacs: display tags in notmuch-show with links Damien Cassou
2012-12-10 14:32 ` [PATCH 1/4] emacs: Add a thread's tags to notmuch-show header-line Damien Cassou
2012-12-10 14:32 ` Damien Cassou [this message]
2012-12-10 14:32 ` [PATCH 3/4] emacs: Make all tags in `notmuch-show' clickable Damien Cassou
2012-12-10 14:32 ` [PATCH 4/4] emacs: Add unit-tests for clickable tags Damien Cassou
2012-12-10 16:05 ` [PATCH v3] emacs: display tags in notmuch-show with links Mark Walters
-- strict thread matches above, loose matches on Subject: below --
2012-12-11 9:00 Damien Cassou
2012-12-11 9:00 ` [PATCH 2/4] emacs: Make tags in notmuch-show header-line clickable Damien Cassou
2012-12-13 13:09 [PATCH v5] emacs: display tags in notmuch-show with links Damien Cassou
2012-12-13 13:09 ` [PATCH 2/4] emacs: Make tags in notmuch-show header-line clickable Damien Cassou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1355149964-27905-3-git-send-email-damien.cassou@gmail.com \
--to=damien.cassou@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).