* mu4e-main.el: make clicks on bookmarks work as well

This commit is contained in:
djcb
2011-12-28 18:47:39 +01:00
parent a2aed887ba
commit a051587581

View File

@ -67,16 +67,25 @@
(defun mu4e-action-str (str &optional func)
"Highlight the first occurence of [..] in STR. Also, optionally
set FUNC to be called with the STR is clicked."
(defun mu4e-action-str (str &optional func-or-shortcut)
"Highlight the first occurence of [..] in STR. If
FUNC-OR-SHORTCUT is non-nil and if it is a function, call it when
STR is clicked (using RET or mouse-2); if FUNC-OR-SHORTCUT is a
string, execute the corresponding keyboard action when it is
clicked."
(let ((newstr
(replace-regexp-in-string
"\\[\\(\\w+\\)\\]"
(lambda(m)
(format "[%s]"
(propertize (match-string 1 str) 'face 'mu4e-highlight-face))) str))
(map (make-sparse-keymap)))
(map (make-sparse-keymap))
(func (if (functionp func-or-shortcut)
func-or-shortcut
(if (stringp func-or-shortcut)
(lexical-let ((macro func-or-shortcut))
(lambda()(interactive)
(execute-kbd-macro macro)))))))
(define-key map [mouse-2] func)
(define-key map (kbd "RET") func)
(put-text-property 0 (length newstr) 'keymap map newstr)
@ -102,13 +111,14 @@ set FUNC to be called with the STR is clicked."
(mu4e-action-str "\t* [C]ompose a new message\n" 'mu4e-compose-new)
"\n"
(propertize " Bookmarks\n\n" 'face 'mu4e-title-face)
;; TODO: it's a bit uncool to hard-code the "b" shortcut...
(mapconcat
(lambda (bm)
(let* ((query (nth 0 bm)) (title (nth 1 bm)) (key (nth 2 bm)))
(mu4e-action-str
(concat "\t* [b" (make-string 1 key) "] " title))))
(concat "\t* [b" (make-string 1 key) "] " title)
(concat "b" (make-string 1 key)))))
mu4e-bookmarks "\n")
"\n"
(propertize " Misc\n\n" 'face 'mu4e-title-face)