* mu4e: allow functions for special folders, implement for marking (WIP)

This commit is contained in:
djcb 2012-09-27 12:01:26 +03:00
parent 58b6be1d97
commit bd0cba007b
4 changed files with 53 additions and 57 deletions

View File

@ -403,6 +403,7 @@ after the end of the search results."
;; literal value. ;; literal value.
(mu4e~headers-defun-mark-func trash) (mu4e~headers-defun-mark-func trash)
(mu4e~headers-defun-mark-func delete) (mu4e~headers-defun-mark-func delete)
(mu4e~headers-defun-mark-func move)
(mu4e~headers-defun-mark-func read) (mu4e~headers-defun-mark-func read)
(mu4e~headers-defun-mark-func unread) (mu4e~headers-defun-mark-func unread)
(mu4e~headers-defun-mark-func flag) (mu4e~headers-defun-mark-func flag)
@ -468,18 +469,18 @@ after the end of the search results."
;; marking/unmarking ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; marking/unmarking ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key map (kbd "<backspace>") 'mu4e~headers-mark-trash) (define-key map (kbd "<backspace>") 'mu4e~headers-mark-trash)
(define-key map (kbd "d") 'mu4e~headers-mark-trash) (define-key map (kbd "d") 'mu4e~headers-mark-trash)
(define-key map (kbd "<delete>") 'mu4e~headers-mark-delete) (define-key map (kbd "<delete>") 'mu4e~headers-mark-delete)
(define-key map (kbd "<deletechar>") 'mu4e~headers-mark-delete) (define-key map (kbd "<deletechar>") 'mu4e~headers-mark-delete)
(define-key map (kbd "D") 'mu4e~headers-mark-delete) (define-key map (kbd "D") 'mu4e~headers-mark-delete)
(define-key map (kbd "m") 'mu4e~headers-mark-move)
(define-key map (kbd "o") 'mu4e~headers-mark-unread) (define-key map (kbd "o") 'mu4e~headers-mark-unread)
(define-key map (kbd "r") 'mu4e~headers-mark-read) (define-key map (kbd "r") 'mu4e~headers-mark-read)
(define-key map (kbd "u") 'mu4e~headers-mark-unmark) (define-key map (kbd "u") 'mu4e~headers-mark-unmark)
(define-key map (kbd "+") 'mu4e~headers-mark-flag) (define-key map (kbd "+") 'mu4e~headers-mark-flag)
(define-key map (kbd "-") 'mu4e~headers-mark-unflag) (define-key map (kbd "-") 'mu4e~headers-mark-unflag)
(define-key map (kbd "&") 'mu4e-headers-mark-custom) (define-key map (kbd "&") 'mu4e-headers-mark-custom)
(define-key map "m" 'mu4e-headers-mark-for-move-and-next)
(define-key map (kbd "*") 'mu4e~headers-mark-deferred) (define-key map (kbd "*") 'mu4e~headers-mark-deferred)
(define-key map (kbd "<kp-multiply>") 'mu4e~headers-mark-deferred) (define-key map (kbd "<kp-multiply>") 'mu4e~headers-mark-deferred)
@ -531,7 +532,7 @@ after the end of the search results."
(define-key menumap [mark-trash] (define-key menumap [mark-trash]
'("Mark for trash" . mu4e~headers-mark-trash)) '("Mark for trash" . mu4e~headers-mark-trash))
(define-key menumap [mark-move] (define-key menumap [mark-move]
'("Mark for move" . mu4e-headers-mark-for-move-and-next)) '("Mark for move" . mu4e~headers-mark-move))
(define-key menumap [sepa1] '("--")) (define-key menumap [sepa1] '("--"))
(define-key menumap [compose-new] '("Compose new" . mu4e-compose-new)) (define-key menumap [compose-new] '("Compose new" . mu4e-compose-new))
@ -1243,14 +1244,7 @@ region if there is a region, then move to the next message."
(interactive) (interactive)
(mu4e-mark-set mark) (mu4e-mark-set mark)
(mu4e-headers-next)) (mu4e-headers-next))
(defun mu4e-headers-mark-for-move-and-next ()
"Set mark MARK on the message at point or on all messages in the
region if there is a region, then move to the next message."
(interactive)
(mu4e-mark-for-move-set)
(mu4e-headers-next))
(defun mu4e~headers-quit-buffer () (defun mu4e~headers-quit-buffer ()
"Quit the mu4e-headers buffer. This is a rather complex function, "Quit the mu4e-headers buffer. This is a rather complex function,
to ensure we don't disturb other windows." to ensure we don't disturb other windows."

View File

@ -84,16 +84,17 @@ where
(defun mu4e-mark-at-point (mark &optional target) (defun mu4e-mark-at-point (mark &optional target)
"Mark (or unmark) message at point. MARK specifies the "Mark (or unmark) message at point. MARK specifies the
mark-type. For `move'-marks there is also the TARGET argument, mark-type. For `move'-marks and `trash'-marks there is also the
which specifies to which maildir the message is to be moved. The TARGET argument, which specifies to which maildir the message is to
functipn works in both headers buffers and message buffers. be moved/trashed. The function works in both headers buffers and
message buffers.
The following marks are available, and the corresponding props: The following marks are available, and the corresponding props:
MARK TARGET description MARK TARGET description
---------------------------------------------------------- ----------------------------------------------------------
`move' y move the message to some folder `move' y move the message to some folder
`trash' n move the message to `mu4e-trash-folder' `trash' y thrash the message to some folder
`delete' n remove the message `delete' n remove the message
`read' n mark the message as read `read' n mark the message as read
`unread' n mark the message as unread `unread' n mark the message as unread
@ -110,7 +111,7 @@ The following marks are available, and the corresponding props:
(markcell (markcell
(case mark (case mark
(move `("m" . ,target)) (move `("m" . ,target))
(trash '("d" . "trash")) (trash `("d" . ,target))
(delete '("D" . "delete")) (delete '("D" . "delete"))
(unread '("o" . "unread")) (unread '("o" . "unread"))
(read '("r" . "read")) (read '("r" . "read"))
@ -122,8 +123,7 @@ The following marks are available, and the corresponding props:
(markkar (car markcell)) (markkar (car markcell))
(target (cdr markcell))) (target (cdr markcell)))
(unless docid (mu4e-warn "No message on this line")) (unless docid (mu4e-warn "No message on this line"))
(unless (eq major-mode 'mu4e-headers-mode) (unless (eq major-mode 'mu4e-headers-mode) (mu4e-error "Not in headers-mode"))
(mu4e-error "Not in headers-mode"))
(save-excursion (save-excursion
(when (mu4e~headers-mark docid markkar) (when (mu4e~headers-mark docid markkar)
;; update the hash -- remove everything current, and if add the new stuff, ;; update the hash -- remove everything current, and if add the new stuff,
@ -148,30 +148,8 @@ The following marks are available, and the corresponding props:
docid))))))) docid)))))))
(defun mu4e-mark-set (mark &optional target)
"Mark the header at point, or, if region is active, mark all
headers in the region."
(interactive)
(if (use-region-p)
;; mark all messages in the region.
(save-excursion
(let ((b (region-beginning)) (e (region-end)))
(goto-char b)
(while (<= (line-beginning-position) e)
(mu4e-mark-at-point mark target)
(forward-line 1))))
;; just a single message
(mu4e-mark-at-point mark target)))
(defun mu4e-mark-restore (docid) (defun mu4e~mark-get-move-target (&optional target)
"Restore the visual mark for the message with DOCID."
(let ((markcell (gethash docid mu4e~mark-map)))
(when markcell
(save-excursion
(when (mu4e~headers-goto-docid docid)
(mu4e-mark-at-point (car markcell) (cdr markcell)))))))
(defun mu4e-mark-for-move-set (&optional target)
"Mark message at point or, if region is active, all messages in "Mark message at point or, if region is active, all messages in
the region, for moving to maildir TARGET. If target is not the region, for moving to maildir TARGET. If target is not
provided, function asks for it." provided, function asks for it."
@ -186,7 +164,37 @@ provided, function asks for it."
(and (yes-or-no-p (and (yes-or-no-p
(format "%s does not exist. Create now?" fulltarget)) (format "%s does not exist. Create now?" fulltarget))
(mu4e~proc-mkdir fulltarget))) (mu4e~proc-mkdir fulltarget)))
(mu4e-mark-set 'move target)))) target)))
(defun mu4e-mark-set (mark &optional target)
"Mark the header at point, or, if region is active, mark all
headers in the region. Optionally, provide TARGET (for moves)."
(let ((target ;; ask or check the target if it's a move
(case mark
('move (mu4e~mark-get-move-target target))
('trash (mu4e-get-trash-folder (mu4e-message-at-point))))))
(if (not (use-region-p))
;; single message
(mu4e-mark-at-point mark target)
;; mark all messages in the region.
(save-excursion
(let ((b (region-beginning)) (e (region-end)))
(goto-char b)
(while (<= (line-beginning-position) e)
;; trash folder is determined for each message
(when (eq mark 'trash) ;; determine the message-specific trash folder
(setq target (mu4e-get-trash-folder (mu4e-message-at-point))))
(mu4e-mark-at-point mark target)
(forward-line 1)))))))
(defun mu4e-mark-restore (docid)
"Restore the visual mark for the message with DOCID."
(let ((markcell (gethash docid mu4e~mark-map)))
(when markcell
(save-excursion
(when (mu4e~headers-goto-docid docid)
(mu4e-mark-at-point (car markcell) (cdr markcell)))))))
(defun mu4e~mark-get-markpair (prompt &optional allow-deferred) (defun mu4e~mark-get-markpair (prompt &optional allow-deferred)
@ -256,14 +264,11 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
;; it looses its N (new) flag ;; it looses its N (new) flag
(case mark (case mark
(move (mu4e~proc-move docid target "-N")) (move (mu4e~proc-move docid target "-N"))
(read (mu4e~proc-move docid nil "+S-u-N")) (read (mu4e~proc-move docid nil "+S-u-N"))
(unread (mu4e~proc-move docid nil "-S+u-N")) (unread (mu4e~proc-move docid nil "-S+u-N"))
(flag (mu4e~proc-move docid nil "+F-u-N")) (flag (mu4e~proc-move docid nil "+F-u-N"))
(unflag (mu4e~proc-move docid nil "-F-N")) (unflag (mu4e~proc-move docid nil "-F-N"))
(trash (trash (mu4e~proc-move docid target "+T-N"))
(unless mu4e-trash-folder
(mu4e-error "`mu4e-trash-folder' not set"))
(mu4e~proc-move docid mu4e-trash-folder "+T-N"))
(delete (mu4e~proc-remove docid)) (delete (mu4e~proc-remove docid))
(otherwise (mu4e-error "Unrecognized mark %S" mark))))) (otherwise (mu4e-error "Unrecognized mark %S" mark)))))
mu4e~mark-map)) mu4e~mark-map))

View File

@ -82,7 +82,7 @@ parameter (which may be `nil'), and return the result."
((stringp folder) folder) ((stringp folder) folder)
((functionp folder) (funcall folder msg)) ((functionp folder) (funcall folder msg))
(t (error "unsupported type for %S" folder))))) (t (error "unsupported type for %S" folder)))))
(or val (mu4e-error "%S not defined" foldervar)))) (or val (mu4e-error "%S evaluates to nil" foldervar))))
(defun mu4e-get-sent-folder (msg) (defun mu4e-get-sent-folder (msg)
"Get the sent folder. See `mu4e-sent-folder'." "Get the sent folder. See `mu4e-sent-folder'."
@ -97,8 +97,7 @@ parameter (which may be `nil'), and return the result."
(mu4e~get-folder 'mu4e-trash-folder msg)) (mu4e~get-folder 'mu4e-trash-folder msg))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -1065,9 +1065,7 @@ attachments) in response to a (mu4e~proc-extract 'temp ... )."
"Set mark on the current messages." "Set mark on the current messages."
(let ((docid (mu4e-msg-field mu4e~view-msg :docid))) (let ((docid (mu4e-msg-field mu4e~view-msg :docid)))
(mu4e~view-in-headers-context (mu4e~view-in-headers-context
(if (eq mark 'move) (mu4e-mark-at-point mark))))
(mu4e-mark-for-move-set)
(mu4e-mark-at-point mark)))))
(defun mu4e-view-mark-custom () (defun mu4e-view-mark-custom ()
"Run some custom mark function." "Run some custom mark function."