* mu4e-hdrs.el: use derived-mode and fix editing drafts

This commit is contained in:
djcb
2012-03-27 21:16:32 +03:00
parent c2e3eac1de
commit 8a66cfb9d9

View File

@ -353,14 +353,10 @@ after the end of the search results."
;; this last one is defined in mu4e-send.el ;; this last one is defined in mu4e-send.el
(setq mu4e-proc-compose-func 'mu4e-send-compose-handler) (setq mu4e-proc-compose-func 'mu4e-send-compose-handler)
(define-derived-mode mu4e-hdrs-mode special-mode
(defun mu4e-hdrs-mode () "mu4e:headers"
"Major mode for displaying mu4e search results. "Major mode for displaying mu4e search results.
\\{mu4e-hdrs-mode-map}." \\{mu4e-hdrs-mode-map}."
(interactive)
(kill-all-local-variables)
(use-local-map mu4e-hdrs-mode-map) (use-local-map mu4e-hdrs-mode-map)
(make-local-variable 'mu4e-last-expr) (make-local-variable 'mu4e-last-expr)
@ -374,11 +370,8 @@ after the end of the search results."
mu4e-marks-map (make-hash-table :size 16 :rehash-size 2) mu4e-marks-map (make-hash-table :size 16 :rehash-size 2)
mu4e-msg-map (make-hash-table :size 1024 :rehash-size 2 :weakness nil) mu4e-msg-map (make-hash-table :size 1024 :rehash-size 2 :weakness nil)
mu4e-thread-info-map (make-hash-table :size 512 :rehash-size 2) mu4e-thread-info-map (make-hash-table :size 512 :rehash-size 2)
major-mode 'mu4e-hdrs-mode
mode-name "mu4e: message headers"
truncate-lines t truncate-lines t
buffer-undo-list t ;; don't record undo information buffer-undo-list t ;; don't record undo information
buffer-read-only t
overwrite-mode 'overwrite-mode-binary) overwrite-mode 'overwrite-mode-binary)
(setq header-line-format (setq header-line-format
@ -397,9 +390,6 @@ after the end of the search results."
'face 'mu4e-title-face) " "))) 'face 'mu4e-title-face) " ")))
mu4e-headers-fields)))) mu4e-headers-fields))))
(put 'mu4e-hdrs-mode 'mode-class 'special)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar mu4e-msg-map nil (defvar mu4e-msg-map nil
"*internal* A map (hashtable) which maps a database (Xapian) "*internal* A map (hashtable) which maps a database (Xapian)
@ -701,7 +691,6 @@ otherwise, limit to up to `mu4e-search-results-limit'."
"Quit the current buffer." "Quit the current buffer."
(interactive) (interactive)
(when (mu4e-handle-marks) (when (mu4e-handle-marks)
(mu4e-kill-proc) ;; hmmm...
(kill-buffer) (kill-buffer)
(mu4e))) (mu4e)))
@ -833,7 +822,8 @@ a symbol, one of `reply', `forward', `edit', `new'. All but `new'
take the message at point as input. Symbol `edit' is only allowed take the message at point as input. Symbol `edit' is only allowed
for draft messages." for draft messages."
(interactive) (interactive)
(let ((compose-type (let ((mu4e-hdrs-buffer (get-buffer-create mu4e-hdrs-buffer-name))
(compose-type
(or compose-type (or compose-type
(intern (ido-completing-read "Compose type: " (intern (ido-completing-read "Compose type: "
'("reply" "forward" "edit" "new")))))) '("reply" "forward" "edit" "new"))))))
@ -843,16 +833,14 @@ for draft messages."
(if (eq compose-type 'new) (if (eq compose-type 'new)
(mu4e-send-compose-handler 'new) (mu4e-send-compose-handler 'new)
;; otherwise, we need the doc-id ;; otherwise, we need the doc-id
(let ((docid (mu4e-hdrs-get-docid)) (let ((docid (mu4e-hdrs-get-docid)))
(is-draft ))
(unless docid (error "No message at point.")) (unless docid (error "No message at point."))
;; note, the first two chars of the line (the mark margin) does *not* ;; note, the first two chars of the line (the mark margin) does *not*
;; have the 'draft property; thus, we check one char before the end of ;; have the 'draft property; thus, we check one char before the end of
;; the current line instead ;; the current line instead
(when (and (eq compose-type 'edit) (unless (or (not (eq compose-type 'edit))
(get-text-property (- (line-end-position) 1) 'draft)) (get-text-property (- (line-end-position) 1) 'draft))
(error "Editing only allowed for draft messages")) (error "Editing is only allowed for draft messages"))
;; talk to the backend ;; talk to the backend
(mu4e-proc-compose compose-type docid)))))) (mu4e-proc-compose compose-type docid))))))