* emacs updates

This commit is contained in:
Dirk-Jan C. Binnema
2011-08-03 08:18:11 +03:00
parent b39b33b82d
commit ef086db2a7
6 changed files with 595 additions and 489 deletions

View File

@ -23,7 +23,7 @@
;;; Commentary:
;; mu message has functions to display a message
;; mu message has functions to display a single message
;;; Code:
@ -38,6 +38,8 @@
"list of header fields to display in the message view")
(defconst mu-view-buffer-name " *mu-view*")
(defvar mu-view-headers-buffer nil "the headers buffer (if any)
from which this buffer was invoked (buffer local)")
(defun mu-view-header (field val val-face)
"get a header string (like 'Subject: foo')"
@ -94,32 +96,53 @@
(mu-view-body msg 'mu-body-face)
))))
(defun mu-view (path)
;; note: mu-view sets path as a text-property ('path) for the whole buffer, just
;; like mu-headers does it per-header
(defun mu-view (path parentbuf)
"display message at PATH in a new buffer; note that the action
of viewing a message may cause it to be moved/renamed; this
function returns the resulting name"
(interactive)
function returns the resulting name. PARENTBUF refers to the
buffer who invoked this view; this allows us to return there when
we quit from this view. Also, if PARENTBUF is a find buffer (ie.,
has mu-headers-mode as its major mode), this allows various
commands (navigation, marking etc.) to be applied to this
buffer."
(let ((str (mu-view-message path))
(buf (get-buffer mu-view-buffer-name)))
(buf (mu-get-new-buffer mu-view-buffer-name)))
(when str
(when buf (kill-buffer buf))
(get-buffer-create mu-view-buffer-name)
(with-current-buffer mu-view-buffer-name
(with-current-buffer buf
(let ((inhibit-read-only t))
;; note, we set the path as a text-property
(insert (propertize str 'path path)))
(switch-to-buffer mu-view-buffer-name)
(mu-view-mode)
(goto-char (point-min))))))
(insert (propertize str 'path path))))
(switch-to-buffer buf)
(mu-view-mode)
;; these are buffer-local
(setq mu-parent-buffer parentbuf)
(setq mu-view-headers-buffer parentbuf)
(goto-char (point-min)))))
(defvar mu-view-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "q" 'mu-quit-buffer)
(define-key map "s" 'mu-find)
(define-key map "s" 'mu-headers)
(define-key map "f" 'mu-forward)
(define-key map "r" 'mu-reply)
;; navigation between messages
(define-key map "n" 'mu-view-next)
(define-key map "p" 'mu-view-prev)
(define-key map "p" 'mu-view-prev)
;; marking/unmarking
(define-key map "d" 'mu-view-mark-for-trash)
(define-key map "D" 'mu-view-mark-for-deletion)
(define-key map "m" 'mu-view-mark-for-move)
(define-key map "u" 'mu-view-unmark)
(define-key map "x" 'mu-view-marks-execute)
map)
"Keymap for \"mu-view\" buffers.")
(fset 'mu-view-mode-map mu-view-mode-map)
@ -129,19 +152,66 @@ function returns the resulting name"
(interactive)
(kill-all-local-variables)
(use-local-map mu-view-mode-map)
(make-variable-buffer-local 'mu-parent-buffer)
(make-variable-buffer-local 'mu-headers-buffer)
(setq major-mode 'mu-view-mode mode-name "*mu-view*")
(setq truncate-lines t buffer-read-only t))
(defmacro with-current-headers-buffer (&rest body)
"Execute the forms in BODY with BUFFER-OR-NAME temporarily current.
BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
The value returned is the value of the last form in BODY. See
also `with-temp-buffer'."
(declare (indent 1) (debug t))
`(if (and mu-view-headers-buffer (buffer-live-p mu-view-headers-buffer))
(save-current-buffer
(set-buffer mu-view-headers-buffer)
,@body)
(message "No headers-buffer connected")))
(defun mu-view-next ()
"move to the next message"
(interactive)
(with-current-buffer mu-find-buffer-name
(when (mu-find-next)
(mu-view (mu-get-path)))))
(with-current-headers-buffer
(when (mu-headers-next)
(mu-view (mu-get-path) (current-buffer)))))
(defun mu-view-prev ()
"move to the previous message"
(interactive)
(with-current-buffer mu-find-buffer-name
(when (mu-find-prev)
(mu-view (mu-get-path)))))
(with-current-headers-buffer
(when (mu-headers-prev)
(mu-view (mu-get-path) (current-buffer)))))
(defun mu-view-mark-for-trash ()
"mark for thrashing"
(interactive)
(with-current-headers-buffer
(mu-headers-mark 'trash)))
(defun mu-view-mark-for-deletion ()
"mark for deletion"
(interactive)
(with-current-headers-buffer
(mu-headers-mark 'delete)))
(defun mu-view-mark-for-move ()
"mark for moving"
(interactive)
(with-current-headers-buffer
(mu-headers-mark 'move)))
(defun mu-view-unmark ()
"unmark this message"
(interactive)
(with-current-headers-buffer
(mu-headers-mark 'none)))
;; we don't allow executing marks from the view buffer, to protect user from
;; accidentally deleting stuff...
(defun mu-view-marks-execute ()
"give user a warning"
(interactive)
(message "Please go back to the headers list to execute your marks"))
(provide 'mu-view)