unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob 379a905d0d0cb01848453f563b1fa64a5efa9929 4529 bytes (raw)
name: emacs/notmuch-tagger.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
 
;; notmuch-tagger.el --- Library to improve the way tags are displayed
;;
;; Copyright © Damien Cassou
;;
;; This file is part of Notmuch.
;;
;; Notmuch is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Notmuch is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.
;;
;; Authors: Damien Cassou <damien.cassou@gmail.com>
;;; Commentary:
;;
;;; Code:
;;
(defun notmuch-tagger-separate-elems (list sep)
  "Return a list with all elements of LIST separated by SEP."
  (let ((first t)
        (res nil))
    (dolist (elt (reverse list) res)
      (unless first
        (push sep res))
      (setq first nil)
      (push elt res))))

(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)))

(defun notmuch-tagger-body-button-action (button)
  "Open `notmuch-search' for the tag referenced by BUTTON."
  (let ((tag (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))

(define-button-type 'notmuch-tagger-body-button-type
  'action    #'notmuch-tagger-body-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-make-body-link (tag)
  "Return a property list that presents a link to TAG.
The returned property list will work everywhere except in the
header-line. For a link that works on the header-line, prefer
`notmuch-tagger-make-header-link'."
  (let ((button (copy-sequence tag)))
    (make-text-button
     button nil
     'type 'notmuch-tagger-body-button-type
     'notmuch-tagger-tag tag
     'help-echo (format "%s: Search other messages like this" tag))
    button))

(defun notmuch-tagger-present-tags-header-line (tags)
  "Return a property list to present TAGS in emacs header-line."
  (list
   "("
   (notmuch-tagger-separate-elems
    (mapcar #'notmuch-tagger-make-header-link tags)
            " ")
   ")"))

(defun notmuch-tagger-present-tags (tags)
  "Return a property list to present TAGS in emacs.
If tags the result of this function is to be used within the
header-line, prefer `notmuch-tagger-present-tags-header-line'
instead of this function."
  (list
   "("
   (notmuch-tagger-separate-elems
    (mapcar #'notmuch-tagger-make-body-link tags)
            " ")
   ")"))

(provide 'notmuch-tagger)
;;; notmuch-tagger.el ends here

debug log:

solving 379a905 ...
found 379a905 in https://yhetil.org/notmuch/1353266322-20318-4-git-send-email-damien.cassou@gmail.com/
found 19a6c7e in https://yhetil.org/notmuch/1353266322-20318-3-git-send-email-damien.cassou@gmail.com/
found 5ca190e in https://yhetil.org/notmuch/1353266322-20318-2-git-send-email-damien.cassou@gmail.com/

applying [1/3] https://yhetil.org/notmuch/1353266322-20318-2-git-send-email-damien.cassou@gmail.com/
diff --git a/emacs/notmuch-tagger.el b/emacs/notmuch-tagger.el
new file mode 100644
index 0000000..5ca190e


applying [2/3] https://yhetil.org/notmuch/1353266322-20318-3-git-send-email-damien.cassou@gmail.com/
diff --git a/emacs/notmuch-tagger.el b/emacs/notmuch-tagger.el
index 5ca190e..19a6c7e 100644


applying [3/3] https://yhetil.org/notmuch/1353266322-20318-4-git-send-email-damien.cassou@gmail.com/
diff --git a/emacs/notmuch-tagger.el b/emacs/notmuch-tagger.el
index 19a6c7e..379a905 100644

Checking patch emacs/notmuch-tagger.el...
Applied patch emacs/notmuch-tagger.el cleanly.
Checking patch emacs/notmuch-tagger.el...
Applied patch emacs/notmuch-tagger.el cleanly.
Checking patch emacs/notmuch-tagger.el...
Applied patch emacs/notmuch-tagger.el cleanly.

index at:
100644 379a905d0d0cb01848453f563b1fa64a5efa9929	emacs/notmuch-tagger.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).