* mm updates

This commit is contained in:
djcb
2011-11-05 12:29:07 +02:00
parent cc7a09bd93
commit 9ee6fec7ea
3 changed files with 53 additions and 55 deletions

View File

@ -208,18 +208,20 @@ after the end of the search results."
;; navigation ;; navigation
(define-key map "n" 'mm/next-header) (define-key map "n" 'mm/next-header)
(define-key map "p" 'mm/prev-header) (define-key map "p" 'mm/prev-header)
(define-key map "j" 'mm/jump-to-maildir)
;; marking/unmarking/executing ;; marking/unmarking/executing
(define-key map "m" 'mm/mark-for-move)
(define-key map (kbd "<backspace>") 'mm/mark-for-trash) (define-key map (kbd "<backspace>") 'mm/mark-for-trash)
(define-key map "d" 'mm/mark-for-trash) (define-key map "d" 'mm/mark-for-trash)
(define-key map (kbd "<delete>") 'mm/mark-for-delete) (define-key map (kbd "<delete>") 'mm/mark-for-delete)
(define-key map "D" 'mm/mark-for-delete) (define-key map "D" 'mm/mark-for-delete)
(define-key map "a" 'mm/mark-for-move-quick)
(define-key map "j" 'mm/jump-to-maildir)
(define-key map "m" 'mm/mark-for-move)
(define-key map "u" 'mm/unmark) (define-key map "u" 'mm/unmark)
(define-key map "U" 'mm/unmark-all) (define-key map "U" 'mm/unmark-all)
(define-key map "x" 'mm/execute-marks) (define-key map "x" 'mm/execute-marks)
@ -573,7 +575,10 @@ the new docid. Otherwise, return nil."
(interactive) (interactive)
(with-current-buffer mm/hdrs-buffer (with-current-buffer mm/hdrs-buffer
(when (= 0 (forward-line 1)) (when (= 0 (forward-line 1))
(or (mm/hdrs-get-docid) (mm/next-header))))) ;; skip non-headers (or (mm/hdrs-get-docid) (mm/next-header)) ;; skip non-headers
;; trick to move point, even if this function is called when this window
;; is not visible
(set-window-point (get-buffer-window mm/hdrs-buffer) (point)))))
(defun mm/prev-header () (defun mm/prev-header ()
"Move point to the previous message header. If this succeeds, "Move point to the previous message header. If this succeeds,
@ -581,11 +586,15 @@ return the new docid. Otherwise, return nil."
(interactive) (interactive)
(with-current-buffer mm/hdrs-buffer (with-current-buffer mm/hdrs-buffer
(when (= 0 (forward-line -1)) (when (= 0 (forward-line -1))
(or (mm/hdrs-get-docid) (mm/prev-header))))) ;; skip non-headers (or (mm/hdrs-get-docid) (mm/prev-header)) ;; skip non-headers
;; trick to move point, even if this function is called when this window
;; is not visible
(set-window-point (get-buffer-window mm/hdrs-buffer) (point)))))
(defun mm/jump-to-maildir () (defun mm/jump-to-maildir ()
"Show the messages in one of the standard folders." "Show the messages in maildir TARGET. If TARGET is not provided,
ask user for it."
(interactive) (interactive)
(let ((fld (mm/ask-maildir "Jump to maildir: "))) (let ((fld (mm/ask-maildir "Jump to maildir: ")))
(mm/hdrs-search (concat "maildir:" fld)))) (mm/hdrs-search (concat "maildir:" fld))))
@ -596,7 +605,7 @@ return the new docid. Otherwise, return nil."
not provided, function asks for it." not provided, function asks for it."
(interactive) (interactive)
(with-current-buffer mm/hdrs-buffer (with-current-buffer mm/hdrs-buffer
(let* ((target (or target (mm/ask-maildir "Target maildir for move: "))) (let* ((target (or target (mm/ask-maildir "Move message to: ")))
(fulltarget (concat mm/maildir target))) (fulltarget (concat mm/maildir target)))
(when (or (file-directory-p fulltarget) (when (or (file-directory-p fulltarget)
(and (yes-or-no-p (and (yes-or-no-p
@ -606,30 +615,6 @@ not provided, function asks for it."
(mm/next-header))))) (mm/next-header)))))
(defun mm/mark-for-move-quick ()
"Mark message at point (or all messages in region) for moving to
a folder; see `mm/move-quick-targets'."
(interactive)
(unless mm/move-quick-targets
(error "`mm/move-quick-targets' has not been defined"))
(let* ((fnames
(mapconcat
(lambda (item)
(concat
"["
(propertize (make-string 1 (cdr item)) 'face 'mm/view-link-face)
"]"
(car item)))
mm/move-quick-targets ", "))
(kar (read-char (concat "Move to: " fnames)))
(targetitem
(find-if (lambda (item) (= kar (cdr item))) mm/move-quick-targets))
(target (and targetitem (car targetitem))))
;; if the target is not found, we simply exit
(when target
(mm/mark-for-move target))))
(defun mm/mark-for-trash () (defun mm/mark-for-trash ()
"Mark message at point for moving to the trash "Mark message at point for moving to the trash
folder (`mm/trash-folder')." folder (`mm/trash-folder')."

View File

@ -213,8 +213,9 @@ or if not available, :body-html converted to text)."
(define-key map (kbd "<delete>") 'mm/view-mark-for-delete) (define-key map (kbd "<delete>") 'mm/view-mark-for-delete)
(define-key map "D" 'mm/view-mark-for-delete) (define-key map "D" 'mm/view-mark-for-delete)
(define-key map "a" 'mm/mark-for-move-quick) (define-key map "a" 'mm/mark-for-move-quick)
(define-key map "m" 'mm/view-mark-for-move) (define-key map "m" 'mm/view-mark-for-move)
;; misc ;; misc
(define-key map "w" 'mm/view-toggle-wrap-lines) (define-key map "w" 'mm/view-toggle-wrap-lines)
(define-key map "h" 'mm/view-toggle-hide-cited) (define-key map "h" 'mm/view-toggle-hide-cited)
@ -395,9 +396,9 @@ removing '^M' etc."
(defun mm/view-quit-buffer () (defun mm/view-quit-buffer ()
"Quit the message view and return to the headers." "Quit the message view and return to the headers."
(interactive) (interactive)
(let ((inhibit-read-only t)) (if (buffer-live-p mm/hdrs-buffer)
(kill-buffer) (switch-to-buffer mm/hdrs-buffer)
(switch-to-buffer mm/hdrs-buffer))) (kill-buffer)))
(defun mm/view-next-header () (defun mm/view-next-header ()
"View the next header." "View the next header."

View File

@ -116,17 +116,16 @@ PATH, you can specifiy the full path."
:group 'mm/folders) :group 'mm/folders)
(defcustom mm/move-quick-targets nil (defcustom mm/maildir-shortcuts nil
"A list of targets quickly moving messages towards (i.e., "A list of maildir shortcuts to enable quickly going to the
archiving or refiling). The list contains elements of the form particular for, or quickly moving messages towards them (i.e.,
(foldername . shortcut), where FOLDERNAME is a maildir (such as archiving or refiling). The list contains elements of the form
(maildir . shortcut), where MAILDIR is a maildir (such as
\"/archive/\"), and shortcut a single shortcut character. With \"/archive/\"), and shortcut a single shortcut character. With
this, in the header buffer and view buffer you can execute this, in the header buffer and view buffer you can execute
`mm/mark-for-move-quick' (or 'a', by default) followed by the designated `mm/mark-for-move-quick' (or 'm', by default) or
character for the target folder, and the message at point (or all `mm/jump-to-maildir-quick' (or 'j', by default), followed by the
the messages in the region) will be marked for moving to the target designated shortcut character for the maildir.")
folder.")
;; the headers view ;; the headers view
(defgroup mm/headers nil (defgroup mm/headers nil
@ -444,17 +443,31 @@ in which case it will be equal to `:to'.)")
(map 'list (lambda (dir) (concat "/" dir)) maildirs))) (map 'list (lambda (dir) (concat "/" dir)) maildirs)))
(defun mm/ask-maildir (prompt) (defun mm/ask-maildir (prompt)
"Ask user with PROMPT for a maildir name, if fullpath is "Ask the user for a shortcut as defined in
non-nill, return the fulpath (i.e., `mm/maildir' prepended to the `mm/maildir-shortcuts', then return the corresponding folder
chosen folder)." name. If the special shortcut 'o' (for _o_ther) is used, or if
(unless (and mm/inbox-folder mm/drafts-folder mm/sent-folder) `mm/maildir-shortcuts is not defined, let user choose from all
(error "`mm/inbox-folder', `mm/drafts-folder' and maildirs under `mm/maildir."
`mm/sent-folder' must be set")) (unless mm/maildir (error "`mm/maildir' is not defined"))
(unless mm/maildir (error "`mm/maildir' must be set")) (if (not mm/maildir-shortcuts)
(interactive) (ido-completing-read prompt (mm/get-sub-maildirs mm/maildir))
(ido-completing-read prompt (mm/get-sub-maildirs mm/maildir))) (let* ((mlist (append mm/maildir-shortcuts '(("ther" . ?o))))
(fnames
(mapconcat
(lambda (item)
(message "%S" item)
(concat
"["
(propertize (make-string 1 (cdr item)) 'face 'mm/view-link-face)
"]"
(car item)))
mlist ", "))
(kar (read-char (concat prompt fnames))))
(if (= kar ?o) ;; user chose 'other'?
(ido-completing-read prompt (mm/get-sub-maildirs mm/maildir))
(car-safe
(find-if (lambda (item) (= kar (cdr item))) mm/maildir-shortcuts))))))
(defun mm/new-buffer (bufname) (defun mm/new-buffer (bufname)
@ -528,5 +541,4 @@ Also see `mu/flags-to-string'.
(mm/string-to-flags-1 (substring str 1)))))) (mm/string-to-flags-1 (substring str 1))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(provide 'mm) (provide 'mm)