* further work on split-view (WIP)

This commit is contained in:
djcb
2012-04-09 11:51:24 +03:00
parent c6116fc676
commit 344b1aea2e
2 changed files with 63 additions and 35 deletions

View File

@ -32,6 +32,8 @@
(require 'hl-line) (require 'hl-line)
(require 'mu4e-proc) (require 'mu4e-proc)
(require 'mu4e-utils) ;; utility functions
;;;; internal variables/constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; internal variables/constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar mu4e-last-expr nil "*internal* The most recent search expression.") (defvar mu4e-last-expr nil "*internal* The most recent search expression.")
@ -258,8 +260,13 @@ after the end of the search results."
;; navigation ;; navigation
(define-key map "n" 'mu4e-next-header) (define-key map "n" 'mu4e-next-header)
(define-key map "p" 'mu4e-prev-header) (define-key map "p" 'mu4e-prev-header)
;; the same
(define-key map (kbd "<M-down>") 'mu4e-next-header)
(define-key map (kbd "<M-up>") 'mu4e-prev-header)
;; switching to view mode (if it's visible)
(define-key map "y" 'mu4e-select-other-view)
;; marking/unmarking/executing ;; marking/unmarking/executing
(define-key map (kbd "<backspace>") 'mu4e-mark-for-trash) (define-key map (kbd "<backspace>") 'mu4e-mark-for-trash)
(define-key map "d" 'mu4e-mark-for-trash) (define-key map "d" 'mu4e-mark-for-trash)
@ -632,21 +639,19 @@ value of `mu4e-split-view': if it's a symbol `horizontal' or
current window. " current window. "
(interactive) (interactive)
(with-current-buffer mu4e-hdrs-buffer (with-current-buffer mu4e-hdrs-buffer
(let ((docid (mu4e--docid-at-point)) (let* ((docid (mu4e--docid-at-point))
(viewwin (get-buffer-window mu4e-view-buffer))) (viewwin (and mu4e-view-buffer
(get-buffer-window mu4e-view-buffer))))
(unless docid (error "No message at point.")) (unless docid (error "No message at point."))
;; is there a window already for the message view? ;; is there a window already for the message view?
(unless (window-live-p viewwin) (unless (window-live-p viewwin)
;; no view window yet; create one, based on the split settings etc. ;; no view window yet; create one, based on the split settings etc.
(setq viewwin (setq viewwin
(cond ;; is there are live window for the message view? (cond ;; is there are live window for the message view?
((eq mu4e-split-view 'horizontal) ;; split horizontally ((eq mu4e-split-view 'horizontal) ;; split horizontally
(split-window nil mu4e-headers-visible-lines 'below)) (split-window nil mu4e-headers-visible-lines 'below))
((eq mu4e-split-view 'vertical) ;; split vertically ((eq mu4e-split-view 'vertical) ;; split vertically
(split-window nil mu4e-headers-visible-columns 'right)) (split-window nil mu4e-headers-visible-columns 'right))
(t ;; no splitting; just use the currently selected one (t ;; no splitting; just use the currently selected one
(selected-window))))) (selected-window)))))
;; okay, now we should have a window for the message view ;; okay, now we should have a window for the message view
@ -731,7 +736,6 @@ otherwise, limit to up to `mu4e-search-results-limit'."
(defun mu4e-hdrs-kill-buffer-and-window () (defun mu4e-hdrs-kill-buffer-and-window ()
"Quit the message view and return to the main view." "Quit the message view and return to the main view."
(interactive) (interactive)
(message "KILL")
(mu4e-kill-buffer-and-window mu4e-hdrs-buffer) (mu4e-kill-buffer-and-window mu4e-hdrs-buffer)
(mu4e)) (mu4e))
@ -836,7 +840,8 @@ folder (`mu4e-trash-folder')."
(defun mu4e-unmark () (defun mu4e-unmark ()
"Unmark message at point." "Unmark message at point."
(interactive) (interactive)
(mu4e-mark 'unmark)) (with-current-buffer mu4e-hdrs-buffer
(mu4e-mark 'unmark)))
(defun mu4e-unmark-all () (defun mu4e-unmark-all ()
"Unmark all messages." "Unmark all messages."
@ -887,7 +892,7 @@ for draft messages."
(error "Editing is 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))))))
(defun mu4e-compose-reply () (defun mu4e-compose-reply ()
"Reply to the current message." "Reply to the current message."

View File

@ -27,7 +27,8 @@
;;; Code: ;;; Code:
(eval-when-compile (require 'cl)) (eval-when-compile (require 'cl))
(require 'html2text)
(require 'mu4e-utils) ;; utility functions
;; we prefer the improved fill-region ;; we prefer the improved fill-region
(require 'filladapt nil 'noerror) (require 'filladapt nil 'noerror)
(require 'comint) (require 'comint)
@ -41,7 +42,7 @@
(defvar mu4e-hdrs-buffer nil (defvar mu4e-hdrs-buffer nil
"*internal* Headers buffer connected to this view.") "*internal* Headers buffer connected to this view.")
(defvar mu4e--current-msg nil (defvar mu4e-current-msg nil
"*internal* The plist describing the current message.") "*internal* The plist describing the current message.")
(defun mu4e-view-message-with-msgid (msgid) (defun mu4e-view-message-with-msgid (msgid)
@ -111,7 +112,7 @@ marking if it still had that."
(mu4e-view-mode) (mu4e-view-mode)
(setq ;; these are buffer-local (setq ;; these are buffer-local
buffer-read-only t buffer-read-only t
mu4e--current-msg msg mu4e-current-msg msg
mu4e-hdrs-buffer hdrsbuf mu4e-hdrs-buffer hdrsbuf
mu4e-link-map (make-hash-table :size 32 :rehash-size 2 :weakness nil)) mu4e-link-map (make-hash-table :size 32 :rehash-size 2 :weakness nil))
@ -258,11 +259,16 @@ if IS-OPEN is nil, and otherwise open it."
(define-key map (kbd "<backspace>") (define-key map (kbd "<backspace>")
'(lambda () (interactive) (scroll-up -1))) '(lambda () (interactive) (scroll-up -1)))
;; navigation between messages ;; navigation between messages
(define-key map "n" 'mu4e-view-next-header)
(define-key map "p" 'mu4e-view-prev-header) (define-key map "p" 'mu4e-view-prev-header)
(define-key map "n" 'mu4e-view-next-header)
;; the same
(define-key map (kbd "<M-down>") 'mu4e-view-next-header)
(define-key map (kbd "<M-up>") 'mu4e-view-prev-header)
;; switching to view mode (if it's visible)
(define-key map "y" 'mu4e-select-other-view)
;; attachments ;; attachments
(define-key map "e" 'mu4e-view-extract-attachment) (define-key map "e" 'mu4e-view-extract-attachment)
(define-key map "o" 'mu4e-view-open-attachment) (define-key map "o" 'mu4e-view-open-attachment)
@ -284,7 +290,7 @@ if IS-OPEN is nil, and otherwise open it."
;; next 3 only warn user when attempt in the message view ;; next 3 only warn user when attempt in the message view
(define-key map "u" 'mu4e-view-unmark) (define-key map "u" 'mu4e-view-unmark)
(define-key map "U" 'mu4e-view-unmark) (define-key map "U" 'mu4e-view-unmark-all)
(define-key map "x" 'mu4e-view-marked-execute) (define-key map "x" 'mu4e-view-marked-execute)
(define-key map "H" 'mu4e-display-manual) (define-key map "H" 'mu4e-display-manual)
@ -352,7 +358,7 @@ if IS-OPEN is nil, and otherwise open it."
(use-local-map mu4e-view-mode-map) (use-local-map mu4e-view-mode-map)
(make-local-variable 'mu4e-hdrs-buffer) (make-local-variable 'mu4e-hdrs-buffer)
(make-local-variable 'mu4e--current-msg) (make-local-variable 'mu4e-current-msg)
(make-local-variable 'mu4e-link-map) (make-local-variable 'mu4e-link-map)
(make-local-variable 'mu4e-lines-wrapped) (make-local-variable 'mu4e-lines-wrapped)
@ -372,9 +378,9 @@ if IS-OPEN is nil, and otherwise open it."
(defun mu4e-view-mark-as-read-maybe () (defun mu4e-view-mark-as-read-maybe ()
"Clear the current message's New/Unread status and set it to "Clear the current message's New/Unread status and set it to
Seen; if the message is not New/Unread, do nothing." Seen; if the message is not New/Unread, do nothing."
(when mu4e--current-msg (when mu4e-current-msg
(let ((flags (plist-get mu4e--current-msg :flags)) (let ((flags (plist-get mu4e-current-msg :flags))
(docid (plist-get mu4e--current-msg :docid))) (docid (plist-get mu4e-current-msg :docid)))
;; is it a new message? ;; is it a new message?
(when (or (member 'unread flags) (member 'new flags)) (when (or (member 'unread flags) (member 'new flags))
(mu4e-proc-flag docid "+S-u-N"))))) (mu4e-proc-flag docid "+S-u-N")))))
@ -556,9 +562,9 @@ See the `org-contacts' documentation for more details."
(with-current-buffer mu4e-view-buffer-name (with-current-buffer mu4e-view-buffer-name
(unless (eq major-mode 'mu4e-view-mode) (unless (eq major-mode 'mu4e-view-mode)
(error "Not in mu4e-view mode.")) (error "Not in mu4e-view mode."))
(unless mu4e--current-msg (unless mu4e-current-msg
(error "No current message.")) (error "No current message."))
(let ((from (car-safe (plist-get mu4e--current-msg :from)))) (let ((from (car-safe (plist-get mu4e-current-msg :from))))
(cond (cond
((not from) "") ;; nothing found ((not from) "") ;; nothing found
((eq name-or-email 'name) ((eq name-or-email 'name)
@ -607,7 +613,7 @@ See the `org-contacts' documentation for more details."
"Redisplay the current message, without wrapped lines or hidden "Redisplay the current message, without wrapped lines or hidden
citations." citations."
(interactive) (interactive)
(mu4e-view mu4e--current-msg mu4e-hdrs-buffer t) (mu4e-view mu4e-current-msg mu4e-hdrs-buffer t)
(setq (setq
mu4e-lines-wrapped nil mu4e-lines-wrapped nil
mu4e-cited-hidden nil)) mu4e-cited-hidden nil))
@ -667,7 +673,7 @@ citations."
(setq retry (setq retry
(and (file-exists-p path) (and (file-exists-p path)
(not (y-or-n-p (concat "Overwrite " path "?")))))) (not (y-or-n-p (concat "Overwrite " path "?"))))))
(mu4e-proc-save (plist-get mu4e--current-msg :docid) id path))) (mu4e-proc-save (plist-get mu4e-current-msg :docid) id path)))
(defun mu4e-view-open-attachment (attnum) (defun mu4e-view-open-attachment (attnum)
"Extract the attachment with ATTNUM" "Extract the attachment with ATTNUM"
@ -677,19 +683,36 @@ citations."
(let* ((att (gethash attnum mu4e-attach-map)) (let* ((att (gethash attnum mu4e-attach-map))
(id (and att (plist-get att :index)))) (id (and att (plist-get att :index))))
(unless id (error "Not a valid attachment number")) (unless id (error "Not a valid attachment number"))
(mu4e-proc-open (plist-get mu4e--current-msg :docid) id))) (mu4e-proc-open (plist-get mu4e-current-msg :docid) id)))
(defun mu4e--in-split-view ()
"Return t if we're in split-view, nil otherwise."
(member mu4e-split-view '(horizontal vertical)))
(defun mu4e-view-unmark-all ()
"If we're in split-view, unmark all messages. Otherwise, warn
user that unmarking only works in the header list."
(interactive)
(if (mu4e--in-split-view)
(mu4e-unmark-all)
(message "Unmarking needs to be done in the header list view")))
(defun mu4e-view-unmark () (defun mu4e-view-unmark ()
"Warn user that unmarking only works in the header list." "If we're in split-view, unmark message at point. Otherwise, warn
user that unmarking only works in the header list."
(interactive) (interactive)
(message "Unmarking needs to be done in the header list view")) (if (mu4e--in-split-view)
(mu4e-unmark)
(message "Unmarking needs to be done in the header list view")))
(defun mu4e-view-marked-execute () (defun mu4e-view-marked-execute ()
"Warn user that execution can only take place in n the header "If we're in split-view, execute the marks. Otherwise, warn user
list." that execution can only take place in n the header list."
(interactive) (interactive)
(message "Execution needs to be done in the header list view")) (if (mu4e--in-split-view)
(mu4e-execute-marks)
(message "Execution needs to be done in the header list view")))
(defun mu4e-view-go-to-url (num) (defun mu4e-view-go-to-url (num)
"Go to a numbered url." "Go to a numbered url."
@ -701,17 +724,17 @@ list."
(defun mu4e-raw-view () (defun mu4e-raw-view ()
"Show the the raw text of the current message." "Show the the raw text of the current message."
(interactive) (interactive)
(unless mu4e--current-msg (unless mu4e-current-msg
(error "No current message")) (error "No current message"))
(mu4e-raw-view-message mu4e--current-msg (current-buffer))) (mu4e-raw-view-message mu4e-current-msg (current-buffer)))
(defun mu4e-view-pipe (cmd) (defun mu4e-view-pipe (cmd)
"Pipe the message through shell command CMD, and display the "Pipe the message through shell command CMD, and display the
results." results."
(interactive "sShell command: ") (interactive "sShell command: ")
(unless mu4e--current-msg (unless mu4e-current-msg
(error "No current message")) (error "No current message"))
(mu4e-view-shell-command-on-raw-message mu4e--current-msg (mu4e-view-shell-command-on-raw-message mu4e-current-msg
(current-buffer) cmd)) (current-buffer) cmd))