Merge pull request #1581 from thierryvolpiatto/Fix_revert_buffer

mu4e-main: Fix revert buffer
This commit is contained in:
Dirk-Jan C. Binnema
2020-02-21 19:28:09 +02:00
committed by GitHub
4 changed files with 56 additions and 40 deletions

View File

@ -235,7 +235,8 @@ non-nil."
(setq mu4e~context-current context) (setq mu4e~context-current context)
(run-hooks 'mu4e-context-changed-hook) (run-hooks 'mu4e-context-changed-hook)
(mu4e-message "Switched context to %s" (mu4e-context-name context))) (mu4e-message "Switched context to %s" (mu4e-context-name context))
(force-mode-line-update))
context)) context))
(defun mu4e~context-autoswitch (&optional msg policy) (defun mu4e~context-autoswitch (&optional msg policy)

View File

@ -1903,7 +1903,7 @@ other windows."
;; now, all *other* windows should be gone. kill ourselves, and return ;; now, all *other* windows should be gone. kill ourselves, and return
;; to the main view ;; to the main view
(kill-buffer) (kill-buffer)
(mu4e~main-view)))) (mu4e~main-view 'refresh))))
;;; _ ;;; _
(provide 'mu4e-headers) (provide 'mu4e-headers)

View File

@ -63,19 +63,16 @@
(define-key map "A" 'mu4e-about) (define-key map "A" 'mu4e-about)
(define-key map "N" 'mu4e-news) (define-key map "N" 'mu4e-news)
(define-key map "H" 'mu4e-display-manual) (define-key map "H" 'mu4e-display-manual)
(define-key map "g" 'mu4e)
map) map)
"Keymap for the *mu4e-main* buffer.") "Keymap for the *mu4e-main* buffer.")
(fset 'mu4e-main-mode-map mu4e-main-mode-map)
(defvar mu4e-main-mode-abbrev-table nil) (defvar mu4e-main-mode-abbrev-table nil)
(define-derived-mode mu4e-main-mode special-mode "mu4e:main" (define-derived-mode mu4e-main-mode special-mode "mu4e:main"
"Major mode for the mu4e main screen. "Major mode for the mu4e main screen.
\\{mu4e-main-mode-map}." \\{mu4e-main-mode-map}."
(use-local-map mu4e-main-mode-map) (setq truncate-lines t
(setq truncate-lines t) overwrite-mode 'overwrite-mode-binary)
(setq overwrite-mode 'overwrite-mode-binary)
;; show context in mode-string ;; show context in mode-string
(make-local-variable 'global-mode-string) (make-local-variable 'global-mode-string)
@ -158,9 +155,23 @@ clicked."
;; NEW This is the old `mu4e~main-view' function but without ;; NEW This is the old `mu4e~main-view' function but without
;; buffer switching at the end. ;; buffer switching at the end.
(defun mu4e~main-view-real (_ignore-auto _noconfirm) (defun mu4e~main-view-real (_ignore-auto _noconfirm)
(let ((buf (get-buffer-create mu4e~main-buffer-name)) "The revert buffer function for `mu4e-main-mode'."
(inhibit-read-only t)) (mu4e~main-view-real-1 'refresh))
(with-current-buffer buf
(defun mu4e~main-view-real-1 (&optional refresh)
"Create `mu4e~main-buffer-name' and set it up.
When REFRESH is non nil refresh infos from server."
(let ((inhibit-read-only t)
(pos (point)))
;; Maybe refresh infos from server.
(if refresh
(mu4e~start 'mu4e~main-redraw-buffer)
(mu4e~main-redraw-buffer))))
(defun mu4e~main-redraw-buffer ()
(with-current-buffer mu4e~main-buffer-name
(let ((inhibit-read-only t)
(pos (point)))
(erase-buffer) (erase-buffer)
(insert (insert
"* " "* "
@ -202,7 +213,8 @@ clicked."
(mu4e~key-val "maildir" (mu4e-root-maildir)) (mu4e~key-val "maildir" (mu4e-root-maildir))
(mu4e~key-val "in store" (mu4e~key-val "in store"
(format "%d" (plist-get mu4e~server-props :doccount)) "messages")) (format "%d" (plist-get mu4e~server-props :doccount)) "messages"))
(mu4e-main-mode)))) (mu4e-main-mode)
(goto-char pos))))
(defun mu4e~main-view-queue () (defun mu4e~main-view-queue ()
"Display queue-related actions in the main view." "Display queue-related actions in the main view."
@ -232,20 +244,29 @@ clicked."
(count-lines (point-min) (point-max))) (count-lines (point-min) (point-max)))
(error 0))) (error 0)))
(defun mu4e~main-view () (defun mu4e~main-view (&optional refresh)
"Create the mu4e main-view, and switch to it." "Create the mu4e main-view, and switch to it.
(if (eq mu4e-split-view 'single-window)
(if (buffer-live-p (mu4e-get-headers-buffer))
(switch-to-buffer (mu4e-get-headers-buffer))
(mu4e~main-menu))
(mu4e~main-view-real nil nil)
(switch-to-buffer mu4e~main-buffer-name)
(goto-char (point-min)))
(add-to-list 'global-mode-string '(:eval (mu4e-context-label))))
;;; Commands When REFRESH is non nil refresh infos from server."
(let ((buf (get-buffer-create mu4e~main-buffer-name)))
(if (eq mu4e-split-view 'single-window)
(if (buffer-live-p (mu4e-get-headers-buffer))
(switch-to-buffer (mu4e-get-headers-buffer))
(mu4e~main-menu))
;; `mu4e~main-view' is called from `mu4e~start', so don't call it
;; a second time here i.e. do not refresh unless specified
;; explicitely with REFRESH arg.
(switch-to-buffer buf)
(with-current-buffer buf
(mu4e-main-mode)
(mu4e~main-view-real-1 refresh))
(goto-char (point-min)))
(add-to-list 'global-mode-string '(:eval (mu4e-context-label)))))
;; NEW Toggle mail sending mode without switching ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Interactive functions
;; NEW
;; Toggle mail sending mode without switching
(defun mu4e~main-toggle-mail-sending-mode () (defun mu4e~main-toggle-mail-sending-mode ()
"Toggle sending mail mode, either queued or direct." "Toggle sending mail mode, either queued or direct."
(interactive) (interactive)
@ -254,10 +275,10 @@ clicked."
(setq smtpmail-queue-mail (not smtpmail-queue-mail)) (setq smtpmail-queue-mail (not smtpmail-queue-mail))
(message (concat "Outgoing mail will now be " (message (concat "Outgoing mail will now be "
(if smtpmail-queue-mail "queued" "sent directly"))) (if smtpmail-queue-mail "queued" "sent directly")))
(unless (eq mu4e-split-view 'single-window) (unless (or (eq mu4e-split-view 'single-window)
(let ((curpos (point))) (not (buffer-live-p (get-buffer mu4e~main-buffer-name))))
(mu4e~main-view-real nil nil) (with-current-buffer mu4e~main-buffer-name
(goto-char curpos)))) (revert-buffer))))
(defun mu4e~main-menu () (defun mu4e~main-menu ()
"mu4e main view in the minibuffer." "mu4e main view in the minibuffer."

View File

@ -642,7 +642,8 @@ process."
(let* ((type (plist-get info :info)) (let* ((type (plist-get info :info))
(processed (plist-get info :processed)) (processed (plist-get info :processed))
(updated (plist-get info :updated)) (updated (plist-get info :updated))
(cleaned-up (plist-get info :cleaned-up))) (cleaned-up (plist-get info :cleaned-up))
(mainbuf (get-buffer mu4e~main-buffer-name)))
(cond (cond
((eq type 'add) t) ;; do nothing ((eq type 'add) t) ;; do nothing
((eq type 'index) ((eq type 'index)
@ -658,7 +659,9 @@ process."
(run-hooks 'mu4e-index-updated-hook)) (run-hooks 'mu4e-index-updated-hook))
(unless (and (not (string= mu4e~contacts-tstamp "0")) (unless (and (not (string= mu4e~contacts-tstamp "0"))
(zerop (plist-get info :updated))) (zerop (plist-get info :updated)))
(mu4e~request-contacts-maybe))))) (mu4e~request-contacts-maybe))
(when (and (buffer-live-p mainbuf) (get-buffer-window mainbuf))
(mu4e~main-view 'refresh)))))
((plist-get info :message) ((plist-get info :message)
(mu4e-index-message "%s" (plist-get info :message)))))) (mu4e-index-message "%s" (plist-get info :message))))))
@ -800,19 +803,10 @@ context yet, switch to the matching one, or none matches, the
first. If mu4e is already running, execute function FUNC (if first. If mu4e is already running, execute function FUNC (if
non-nil). Otherwise, check various requireme`'nts, then start mu4e. non-nil). Otherwise, check various requireme`'nts, then start mu4e.
When successful, call FUNC (if non-nil) afterwards." When successful, call FUNC (if non-nil) afterwards."
;; if we're already running, simply go to the main view
(unless (mu4e-running-p) ;; already running?
;; when it's visible, re-draw the main view when there are changes.
(add-hook 'mu4e-index-updated-hook
(lambda()
(let ((mainbuf (get-buffer mu4e~main-buffer-name)))
(when (and (buffer-live-p mainbuf) (get-buffer-window mainbuf))
(mu4e~start 'mu4e~main-view))))))
(setq mu4e-pong-func (lambda (info) (mu4e~pong-handler info func))) (setq mu4e-pong-func (lambda (info) (mu4e~pong-handler info func)))
(mu4e~proc-ping (mu4e~proc-ping
(mapcar ;; send it a list of queries we'd like to see read/unread info (mapcar
;; for. ;; send it a list of queries we'd like to see read/unread info for.
(lambda(bm) (plist-get bm :query)) (lambda(bm) (plist-get bm :query))
(seq-filter (lambda (bm) ;; exclude bookmarks that are not strings, (seq-filter (lambda (bm) ;; exclude bookmarks that are not strings,
;; and with these flags. ;; and with these flags.