[PATCH] emacs: add tag jump menu
Mark Walters
markwalters1009 at gmail.com
Sat Sep 17 14:09:43 PDT 2016
Add a "jump" style menu for doing tagging operations.
---
Jani suggested something like this on irc today. This is a first cut
to see if people like it. By default the tagging jump menu is bound to
k (which works in search/show/tree mode), and has the following options
a (Archive) -inbox -unread
u (Mark Read) -unread
d (Delete) +deleted
If you do ctrl-u k the it will do the reverse operation.
To customize you want the variable notmuch-tagging-keys in the group
notmuch-tag. It is only very lightly tested but seems to work. And the
docstrings will definitely need some work.
Best wishes
Mark
emacs/notmuch-lib.el | 4 ++++
emacs/notmuch-show.el | 1 +
emacs/notmuch-tag.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
emacs/notmuch-tree.el | 1 +
emacs/notmuch.el | 1 +
5 files changed, 58 insertions(+)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2f015b0..b2cdace 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -57,6 +57,10 @@
(custom-add-to-group 'notmuch-send 'message 'custom-group)
+(defgroup notmuch-tag nil
+ "Tags and tagging in Notmuch."
+ :group 'notmuch)
+
(defgroup notmuch-crypto nil
"Processing and display of cryptographic MIME parts."
:group 'notmuch)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 5a585f3..756c7dd 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1428,6 +1428,7 @@ reset based on the original query."
(define-key map "V" 'notmuch-show-view-raw-message)
(define-key map "c" 'notmuch-show-stash-map)
(define-key map "h" 'notmuch-show-toggle-visibility-headers)
+ (define-key map "k" 'notmuch-tag-jump)
(define-key map "*" 'notmuch-show-tag-all)
(define-key map "-" 'notmuch-show-remove-tag)
(define-key map "+" 'notmuch-show-add-tag)
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index ec3c964..4d2feef 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -28,6 +28,37 @@
(require 'crm)
(require 'notmuch-lib)
+(declare-function notmuch-search-tag "notmuch" tag-changes)
+(declare-function notmuch-show-tag "notmuch-show" tag-changes)
+(declare-function notmuch-tree-tag "notmuch-tree" tag-changes)
+
+(autoload 'notmuch-jump "notmuch-jump")
+
+
+(define-widget 'notmuch-tag-key-type 'list
+ "A single key tagging binding"
+ :format "%v"
+ :args '((list :inline t
+ :format "%v"
+ (key-sequence :tag "Key")
+ (repeat :tag "Tag operations" (string :format "%v" :tag "change"))
+ (checklist :inline t
+ (string :tag "Short Name")))))
+
+(defcustom notmuch-tagging-keys
+ `((,(kbd "a") ("-inbox" "-unread") "Archive")
+ (,(kbd "u") ("-unread") "Mark read")
+ (,(kbd "d") ("+deleted") "Delete"))
+ "A list of keys and corresponding tagging operations
+
+For each key you can specify a sequence of tagging operations to
+apply. By default they will appear in the tagging buffer just as
+this sequence of tags, but you can specify a short name if you
+prefer."
+ :tag "List of tagging bindings"
+ :type '(repeat notmuch-tag-key-type)
+ :group 'notmuch-tag)
+
(define-widget 'notmuch-tag-format-type 'lazy
"Customize widget for notmuch-tag-format and friends"
:type '(alist :key-type (regexp :tag "Tag")
@@ -437,6 +468,26 @@ begin with a \"+\" or a \"-\". If REVERSE is non-nil, replace all
s)))
tags))
+(defun notmuch-tag-jump (reverse)
+ (interactive "P")
+ (let (action-map)
+ (dolist (binding notmuch-tagging-keys)
+ (let* ((tag-function (case major-mode
+ (notmuch-search-mode #'notmuch-search-tag)
+ (notmuch-show-mode #'notmuch-show-tag)
+ (notmuch-tree-mode #'notmuch-tree-tag)))
+ (key (first binding))
+ (tag-change (if reverse
+ (notmuch-tag-change-list (second binding) 't)
+ (second binding)))
+ (name (if (third binding)
+ (if reverse (concat "Undo " (third binding))
+ (third binding))
+ (mapconcat #'identity tag-change " "))))
+ (push (list key name
+ `(lambda () (,tag-function ',tag-change)))
+ action-map)))
+ (notmuch-jump action-map "Tag: ")))
;;
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index d864e6d..5431384 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -276,6 +276,7 @@ FUNC."
(define-key map "P" 'notmuch-tree-prev-message)
(define-key map (kbd "M-p") 'notmuch-tree-prev-thread)
(define-key map (kbd "M-n") 'notmuch-tree-next-thread)
+ (define-key map "k" 'notmuch-tag-jump)
(define-key map "-" 'notmuch-tree-remove-tag)
(define-key map "+" 'notmuch-tree-add-tag)
(define-key map "*" 'notmuch-tree-tag-thread)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 8e14692..888672b 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -169,6 +169,7 @@ there will be called at other points of notmuch execution."
(define-key map "t" 'notmuch-search-filter-by-tag)
(define-key map "l" 'notmuch-search-filter)
(define-key map [mouse-1] 'notmuch-search-show-thread)
+ (define-key map "k" 'notmuch-tag-jump)
(define-key map "*" 'notmuch-search-tag-all)
(define-key map "a" 'notmuch-search-archive-thread)
(define-key map "-" 'notmuch-search-remove-tag)
--
2.1.4
More information about the notmuch
mailing list