* 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

@ -258,7 +258,7 @@ after the end of the search results."
(define-key map "b" 'mu4e-search-bookmark) (define-key map "b" 'mu4e-search-bookmark)
(define-key map "B" 'mu4e-search-bookmark-edit-first) (define-key map "B" 'mu4e-search-bookmark-edit-first)
(define-key map "q" 'mu4e-quit-buffer) (define-key map "q" 'mu4e-quit-buffer)
(define-key map "r" 'mu4e-rerun-search) (define-key map "r" 'mu4e-rerun-search)
@ -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,31 +370,25 @@ 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
(cons (cons
(make-string (make-string
(+ (length mu4e-hdrs-fringe) (floor (fringe-columns 'left t))) ?\s) (+ (length mu4e-hdrs-fringe) (floor (fringe-columns 'left t))) ?\s)
(map 'list (map 'list
(lambda (item) (lambda (item)
(let ((field (cdr (assoc (car item) mu4e-header-names))) (let ((field (cdr (assoc (car item) mu4e-header-names)))
(width (cdr item))) (width (cdr item)))
(concat (concat
(propertize (propertize
(if width (if width
(truncate-string-to-width field width 0 ?\s t) (truncate-string-to-width field width 0 ?\s t)
field) field)
'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
@ -696,12 +686,11 @@ otherwise, limit to up to `mu4e-search-results-limit'."
(when expr (when expr
(mu4e-hdrs-search expr current-prefix-arg))) (mu4e-hdrs-search expr current-prefix-arg)))
(defun mu4e-quit-buffer () (defun mu4e-quit-buffer ()
"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,26 +822,25 @@ 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))
(or compose-type (compose-type
(intern (ido-completing-read "Compose type: " (or compose-type
'("reply" "forward" "edit" "new")))))) (intern (ido-completing-read "Compose type: "
'("reply" "forward" "edit" "new"))))))
(with-current-buffer mu4e-hdrs-buffer (with-current-buffer mu4e-hdrs-buffer
;; 'new is special, since it takes no existing message as arg therefore, ;; 'new is special, since it takes no existing message as arg therefore,
;; we don't need to call thec backend, and call the handler *directly* ;; we don't need to call thec backend, and call the handler *directly*
(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))))))