mirror of https://github.com/djcb/mu.git
* mu4e-mark: some cleanups
This commit is contained in:
parent
a8bb465e58
commit
b58e1c231a
|
@ -84,28 +84,28 @@ The following marks are available, and the corresponding props:
|
||||||
(t (error "Invalid mark %S" mark)))))
|
(t (error "Invalid mark %S" mark)))))
|
||||||
(unless docid (error "No message on this line"))
|
(unless docid (error "No message on this line"))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(when (mu4e~mark-header docid markkar))
|
(when (mu4e~mark-header 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,
|
||||||
;; unless we're unmarking
|
;; unless we're unmarking
|
||||||
(remhash docid mu4e~mark-map)
|
(remhash docid mu4e~mark-map)
|
||||||
;; remove possible overlays
|
;; remove possible overlays
|
||||||
(remove-overlays (line-beginning-position) (line-end-position))
|
(remove-overlays (line-beginning-position) (line-end-position))
|
||||||
|
|
||||||
;; now, let's set a mark (unless we were unmarking)
|
;; now, let's set a mark (unless we were unmarking)
|
||||||
(unless (eql mark 'unmark)
|
(unless (eql mark 'unmark)
|
||||||
(puthash docid (list mark target) mu4e~mark-map)
|
(puthash docid (list mark target) mu4e~mark-map)
|
||||||
;; when we have a target (ie., when moving), show the target folder in
|
;; when we have a target (ie., when moving), show the target folder in
|
||||||
;; an overlay
|
;; an overlay
|
||||||
(when target
|
(when target
|
||||||
(let* ((targetstr (propertize (concat "-> " target " ")
|
(let* ((targetstr (propertize (concat "-> " target " ")
|
||||||
'face 'mu4e-system-face))
|
'face 'mu4e-system-face))
|
||||||
;; mu4e-goto-docid docid t \will take us just after the docid cookie
|
;; mu4e-goto-docid docid t \will take us just after the
|
||||||
;; and then we skip the mu4e~hdrs-fringe
|
;; docid cookie and then we skip the mu4e~hdrs-fringe
|
||||||
(start (+ (length mu4e~hdrs-fringe)
|
(start (+ (length mu4e~hdrs-fringe)
|
||||||
(mu4e~goto-docid docid t)))
|
(mu4e~goto-docid docid t)))
|
||||||
(overlay (make-overlay start (+ start (length targetstr)))))
|
(overlay (make-overlay start (+ start (length targetstr)))))
|
||||||
(overlay-put overlay 'display targetstr)
|
(overlay-put overlay 'display targetstr)
|
||||||
docid))))))
|
docid)))))))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-mark-set (mark &optional target)
|
(defun mu4e-mark-set (mark &optional target)
|
||||||
|
@ -144,7 +144,7 @@ provided, function asks for it."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-mark-execute-all (&optional no-confirmation)
|
(defun mu4e-mark-execute-all ()
|
||||||
"Execute the actions for all marked messages in this
|
"Execute the actions for all marked messages in this
|
||||||
buffer. After the actions have been executed succesfully, the
|
buffer. After the actions have been executed succesfully, the
|
||||||
affected messages are *hidden* from the current header list. Since
|
affected messages are *hidden* from the current header list. Since
|
||||||
|
@ -153,29 +153,27 @@ the messages no longer matches the current one - to get that
|
||||||
certainty, we need to rerun the search, but we don't want to do
|
certainty, we need to rerun the search, but we don't want to do
|
||||||
that automatically, as it may be too slow and/or break the users
|
that automatically, as it may be too slow and/or break the users
|
||||||
flow. Therefore, we hide the message, which in practice seems to
|
flow. Therefore, we hide the message, which in practice seems to
|
||||||
work well.
|
work well."
|
||||||
|
|
||||||
If NO-CONFIRMATION is non-nil, do not ask the user for
|
|
||||||
confirmation."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (zerop (hash-table-count mu4e~mark-map))
|
(let ((marknum (hash-table-count mu4e~mark-map)))
|
||||||
(message "Nothing is marked")
|
(if (zerop marknum)
|
||||||
(when (or no-confirmation
|
(message "Nothing is marked")
|
||||||
(y-or-n-p (format "Sure you want to execute marks on %d message(s)?"
|
(when (yes-or-no-p
|
||||||
(hash-table-count mu4e~mark-map))))
|
(format "Are you sure you want to execute %d mark%s?"
|
||||||
(maphash
|
marknum (if (> marknum 1) "s" "")))
|
||||||
(lambda (docid val)
|
(maphash
|
||||||
(let ((mark (nth 0 val)) (target (nth 1 val)))
|
(lambda (docid val)
|
||||||
(case mark
|
(let ((mark (nth 0 val)) (target (nth 1 val)))
|
||||||
(move (mu4e~proc-move docid target))
|
(case mark
|
||||||
(read (mu4e~proc-move docid nil "+S-u-N"))
|
(move (mu4e~proc-move docid target))
|
||||||
(unread (mu4e~proc-move docid nil "-S+u"))
|
(read (mu4e~proc-move docid nil "+S-u-N"))
|
||||||
(trash
|
(unread (mu4e~proc-move docid nil "-S+u"))
|
||||||
(unless mu4e-trash-folder
|
(trash
|
||||||
(error "`mu4e-trash-folder' not set"))
|
(unless mu4e-trash-folder
|
||||||
(mu4e~proc-move docid mu4e-trash-folder "+T"))
|
(error "`mu4e-trash-folder' not set"))
|
||||||
(delete (mu4e~proc-remove docid)))))
|
(mu4e~proc-move docid mu4e-trash-folder "+T"))
|
||||||
mu4e~mark-map)
|
(delete (mu4e~proc-remove docid)))))
|
||||||
|
mu4e~mark-map))
|
||||||
(mu4e-mark-unmark-all)
|
(mu4e-mark-unmark-all)
|
||||||
(message nil))))
|
(message nil))))
|
||||||
|
|
||||||
|
@ -206,26 +204,18 @@ according to the value of `mu4e-headers-leave-behavior'. This
|
||||||
function is to be called before any further action (like searching,
|
function is to be called before any further action (like searching,
|
||||||
quiting the buffer) is taken; returning t means 'take the following
|
quiting the buffer) is taken; returning t means 'take the following
|
||||||
action', return nil means 'don't do anything'"
|
action', return nil means 'don't do anything'"
|
||||||
(let ((marknum
|
(let ((marknum (if mu4e~mark-map (hash-table-count mu4e~mark-map) 0))
|
||||||
(if mu4e~mark-map (hash-table-count mu4e~mark-map) 0))
|
|
||||||
(what mu4e-headers-leave-behavior))
|
(what mu4e-headers-leave-behavior))
|
||||||
(unless (or (= marknum 0) (eq what 'ignore) (eq what 'apply))
|
(unless (zerop marknum) ;; nothing to do
|
||||||
;; if `mu4e-headers-leave-behavior' is not apply or ignore, ask the user
|
(unless (or (eq what 'ignore) (eq what 'apply))
|
||||||
(setq what
|
;; if `mu4e-headers-leave-behavior' is not apply or ignore, ask the user
|
||||||
(let ((kar (mu4e-read-option
|
(setq what
|
||||||
"There are existing marks; should we: "
|
(let ((what (mu4e-read-option
|
||||||
'(("apply marks") ("ignore marks?")))))
|
"There are existing marks; should we: "
|
||||||
(cond
|
'( ("apply marks" nil apply)
|
||||||
((= kar ?a) 'apply)
|
("ignore marks?" nil ignore)))))
|
||||||
((= kar ?i) 'ignore)
|
;; we determined what to do... now do it
|
||||||
(t nil))))) ;; cancel
|
(when (eq what 'apply)
|
||||||
;; we determined what to do... now do it
|
(mu4e-mark-execute-all))))))))
|
||||||
(cond
|
|
||||||
((= 0 marknum) t) ;; no marks, just go ahead
|
|
||||||
((eq what 'ignore) t) ;; ignore the marks, go ahead
|
|
||||||
((eq what 'apply)
|
|
||||||
(progn (mu4e-mark-execute-all t) t) t) ;; execute marks, go ahead
|
|
||||||
(t nil)))) ;; otherwise, don't do anything
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'mu4e-mark)
|
(provide 'mu4e-mark)
|
||||||
|
|
Loading…
Reference in New Issue