* mu4e-hdrs.el: get rid of the thread-marks, no longer needed

This commit is contained in:
djcb
2012-04-11 02:08:02 +03:00
parent 86c4e7042a
commit 250026f2d6

View File

@ -43,8 +43,7 @@ message headers to put marks.")
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(with-current-buffer mu4e-hdrs-buffer (with-current-buffer mu4e-hdrs-buffer
(erase-buffer) (erase-buffer)
(when mu4e-marks-map (clrhash mu4e-marks-map)) (when mu4e-marks-map (clrhash mu4e-marks-map))))))
(when mu4e-thread-info-map (clrhash mu4e-thread-info-map))))))
(defun mu4e-hdrs-search (expr &optional full-search) (defun mu4e-hdrs-search (expr &optional full-search)
@ -70,7 +69,7 @@ results, otherwise, limit number of results to
;;; when we're starting a new search, we also kill the ;;; when we're starting a new search, we also kill the
;;; view buffer, if any ;;; view buffer, if any
(mu4e-view-kill-buffer-and-window))) (mu4e-view-kill-buffer-and-window)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; handler functions ;; handler functions
;; ;;
@ -104,6 +103,13 @@ headers."
(when (mu4e-hdrs-docid-is-marked docid) (when (mu4e-hdrs-docid-is-marked docid)
(mu4e-hdrs-mark 'unmark)) (mu4e-hdrs-mark 'unmark))
;; re-use the thread info from the old one; this is needed because
;; *update* message don't have thread info by themselves (unlike
;; search results)
;; but since we still have the search results, re-use those
(plist-put msg :thread
(mu4e--field-for-docid docid :thread))
;; first, remove the old one (otherwise, we'd have two headers with ;; first, remove the old one (otherwise, we'd have two headers with
;; the same docid... ;; the same docid...
(mu4e-hdrs-remove-handler docid) (mu4e-hdrs-remove-handler docid)
@ -163,16 +169,12 @@ into a string."
(first-child "\\ ") (first-child "\\ ")
(duplicate "= ") (duplicate "= ")
(t "| ")))))) (t "| "))))))
;; FIXME: when updating an header line, we don't know the thread
;; stuff
(defun mu4e-hdrs-header-handler (msg &optional point) (defun mu4e-hdrs-header-handler (msg &optional point)
"Create a one line description of MSG in this buffer, at POINT, "Create a one line description of MSG in this buffer, at POINT,
if provided, or at the end of the buffer otherwise." if provided, or at the end of the buffer otherwise."
(when (buffer-live-p mu4e-hdrs-buffer) (when (buffer-live-p mu4e-hdrs-buffer)
(let* ((docid (plist-get msg :docid)) (let* ((docid (plist-get msg :docid))
(thread-info
(or (plist-get msg :thread) (gethash docid mu4e-thread-info-map)))
(line (line
(mapconcat (mapconcat
(lambda (f-w) (lambda (f-w)
@ -180,7 +182,10 @@ if provided, or at the end of the buffer otherwise."
(val (plist-get msg field)) (val (plist-get msg field))
(str (str
(case field (case field
(:subject (concat (mu4e-thread-prefix thread-info) val)) (:subject
(concat ;; prefix subject with a thread indicator
(mu4e-thread-prefix (plist-get msg :thread))
val))
((:maildir :path) val) ((:maildir :path) val)
((:to :from :cc :bcc) (mu4e-hdrs-contact-str val)) ((:to :from :cc :bcc) (mu4e-hdrs-contact-str val))
;; if we (ie. `user-mail-address' is the 'From', show ;; if we (ie. `user-mail-address' is the 'From', show
@ -213,9 +218,6 @@ if provided, or at the end of the buffer otherwise."
(t ;; else (t ;; else
(propertize line 'face 'mu4e-header-face))))) (propertize line 'face 'mu4e-header-face)))))
;; store the thread info, so we can use it when updating the message
(when (and thread-info mu4e-thread-info-map)
(puthash docid thread-info mu4e-thread-info-map))
;; now, append the header line ;; now, append the header line
(mu4e-hdrs-add-header line docid point msg)))) (mu4e-hdrs-add-header line docid point msg))))
@ -235,7 +237,7 @@ after the end of the search results."
(message "Found %d matching message%s" (message "Found %d matching message%s"
count (if (= 1 count) "" "s")) count (if (= 1 count) "" "s"))
;; highlight the first message ;; highlight the first message
(mu4e-hdrs-highlight (mu4e--docid-at-point (point-min))))))))) (mu4e-hdrs-highlight (mu4e--docid-at-point (point-min)))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -254,7 +256,7 @@ after the end of the search results."
(define-key map "q" 'mu4e-hdrs-kill-buffer-and-window) (define-key map "q" 'mu4e-hdrs-kill-buffer-and-window)
(define-key map "z" 'mu4e-hdrs-kill-buffer-and-window) (define-key map "z" 'mu4e-hdrs-kill-buffer-and-window)
(define-key map "r" 'mu4e-rerun-search) (define-key map "r" 'mu4e-rerun-search)
(define-key map "g" 'mu4e-rerun-search) ;; for compatibility (define-key map "g" 'mu4e-rerun-search) ;; for compatibility
@ -264,10 +266,10 @@ after the end of the search results."
;; the same ;; the same
(define-key map (kbd "<M-down>") 'mu4e-next-header) (define-key map (kbd "<M-down>") 'mu4e-next-header)
(define-key map (kbd "<M-up>") 'mu4e-prev-header) (define-key map (kbd "<M-up>") 'mu4e-prev-header)
;; switching to view mode (if it's visible) ;; switching to view mode (if it's visible)
(define-key map "y" 'mu4e-select-other-view) (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)
@ -362,22 +364,20 @@ after the end of the search results."
(make-local-variable 'mu4e-last-expr) (make-local-variable 'mu4e-last-expr)
(make-local-variable 'mu4e-hdrs-proc) (make-local-variable 'mu4e-hdrs-proc)
(make-local-variable 'mu4e-marks-map) (make-local-variable 'mu4e-marks-map)
(make-local-variable 'mu4e-thread-info-map)
(make-local-variable 'mu4e--highlighted-docid) (make-local-variable 'mu4e--highlighted-docid)
(make-local-variable 'global-mode-string) (make-local-variable 'global-mode-string)
(make-local-variable 'hl-line-face) (make-local-variable 'hl-line-face)
(setq (setq
mu4e-marks-map (make-hash-table :size 16 :rehash-size 2) mu4e-marks-map (make-hash-table :size 16 :rehash-size 2)
mu4e-thread-info-map (make-hash-table :size 512 :rehash-size 2)
truncate-lines t truncate-lines t
buffer-undo-list t ;; don't record undo information buffer-undo-list t ;; don't record undo information
overwrite-mode 'overwrite-mode-binary overwrite-mode 'overwrite-mode-binary
hl-line-face 'mu4e-header-highlight-face) hl-line-face 'mu4e-header-highlight-face)
(hl-line-mode 1) (hl-line-mode 1)
(setq header-line-format (setq header-line-format
(cons (cons
(make-string (make-string
@ -413,7 +413,7 @@ found. Also, unhighlight any previously highlighted headers."
(hl-line-highlight))) (hl-line-highlight)))
(setq mu4e--highlighted-docid docid))) (setq mu4e--highlighted-docid docid)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e-select-headers-window-if-visible () (defun mu4e-select-headers-window-if-visible ()
"When there is a visible window for the headers buffer, make sure "When there is a visible window for the headers buffer, make sure
@ -437,7 +437,8 @@ at the beginning of lines to identify headers."
"Get the docid for the header at POINT, or at current (point) if "Get the docid for the header at POINT, or at current (point) if
nil. Returns the docid, or nil if there is none." nil. Returns the docid, or nil if there is none."
(save-excursion (save-excursion
(when point( goto-char point)) (when point
(goto-char point))
(get-text-property (line-beginning-position) 'docid))) (get-text-property (line-beginning-position) 'docid)))
(defun mu4e--goto-docid (docid &optional to-mark) (defun mu4e--goto-docid (docid &optional to-mark)
@ -465,6 +466,13 @@ docid DOCID, or nil if it cannot be found."
(setq pos (mu4e--goto-docid docid))) (setq pos (mu4e--goto-docid docid)))
pos)) pos))
(defun mu4e--field-for-docid (docid field)
"Get FIELD (a symbol, see `mu4e-headers-names') for the message
with DOCID which must be present in the headers buffer."
(save-excursion
(when (mu4e--goto-docid docid)
(mu4e-field-at-point field))))
;;;; markers mark headers for ;;;; markers mark headers for
(defun mu4e--mark-header (docid mark) (defun mu4e--mark-header (docid mark)
"(Visually) mark the header for DOCID with character MARK." "(Visually) mark the header for DOCID with character MARK."
@ -493,14 +501,14 @@ at (point-max) otherwise. If MSG is not nil, add it as the text-property `msg'."
(when (buffer-live-p mu4e-hdrs-buffer) (when (buffer-live-p mu4e-hdrs-buffer)
(with-current-buffer mu4e-hdrs-buffer (with-current-buffer mu4e-hdrs-buffer
(let ((inhibit-read-only t) (let ((inhibit-read-only t)
(is-first-header (= (point-min) (point-max)))) (is-first-header (= (point-min) (point-max))))
(save-excursion (save-excursion
(goto-char (if point point (point-max))) (goto-char (if point point (point-max)))
(insert (insert
(propertize (propertize
(concat (concat
(mu4e--docid-cookie docid) (mu4e--docid-cookie docid)
mu4e-hdrs-fringe str "\n") 'docid docid 'msg msg))))))) mu4e-hdrs-fringe str "\n") 'docid docid 'msg msg)))))))
(defun mu4e-hdrs-remove-header (docid) (defun mu4e-hdrs-remove-header (docid)
"Remove header with DOCID at POINT." "Remove header with DOCID at POINT."
@ -512,18 +520,6 @@ at (point-max) otherwise. If MSG is not nil, add it as the text-property `msg'."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; threadinfo-map ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar mu4e-thread-info-map nil
"Map (hash) of docid->threadinfo; when filling the list of
messages, we fill a map of thread info, such that when a header
changes (e.g., it's read-flag gets set) through some (:update
...) message, we can restore the thread-info (this is needed
since :update messages do not include thread info).")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; marks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; marks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar mu4e-marks-map nil (defvar mu4e-marks-map nil
@ -653,7 +649,7 @@ 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 (and mu4e-view-buffer (viewwin (and mu4e-view-buffer
(get-buffer-window mu4e-view-buffer)))) (get-buffer-window mu4e-view-buffer))))
(unless docid (error "No message at point.")) (unless docid (error "No message at point."))
@ -668,7 +664,7 @@ current window. "
((eq mu4e-split-view 'horizontal) ;; split horizontally ((eq mu4e-split-view 'horizontal) ;; split horizontally
(split-window-vertically mu4e-headers-visible-lines)) (split-window-vertically mu4e-headers-visible-lines))
((eq mu4e-split-view 'vertical) ;; split vertically ((eq mu4e-split-view 'vertical) ;; split vertically
(split-window-horizontally mu4e-headers-visible-columns)) (split-window-horizontally mu4e-headers-visible-columns))
(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
@ -753,7 +749,7 @@ otherwise, limit to up to `mu4e-search-results-limit'."
"Quit the message view and return to the main view." "Quit the message view and return to the main view."
(interactive) (interactive)
(mu4e-kill-buffer-and-window mu4e-hdrs-buffer) (mu4e-kill-buffer-and-window mu4e-hdrs-buffer)
(mu4e-main-view)) (mu4e-main-view))
(defun mu4e-rerun-search () (defun mu4e-rerun-search ()
"Rerun the search for the last search expression; if none exists, "Rerun the search for the last search expression; if none exists,
@ -763,7 +759,7 @@ do a new search."
(if mu4e-last-expr (if mu4e-last-expr
(mu4e-hdrs-search mu4e-last-expr) (mu4e-hdrs-search mu4e-last-expr)
(call-interactively 'mu4e-search)))) (call-interactively 'mu4e-search))))
(defun mu4e--hdrs-move (lines) (defun mu4e--hdrs-move (lines)
"Move point LINES lines forward (if LINES is positive) or "Move point LINES lines forward (if LINES is positive) or
backward (if LINES is negative). If this succeeds, return the new backward (if LINES is negative). If this succeeds, return the new
@ -775,18 +771,19 @@ docid. Otherwise, return nil."
(docid (mu4e--docid-at-point))) (docid (mu4e--docid-at-point)))
;; trick to move point, even if this function is called when this window ;; trick to move point, even if this function is called when this window
;; is not visible ;; is not visible
(set-window-point (get-buffer-window mu4e-hdrs-buffer) (point)) (when docid
;; attempt to highlight the new line (set-window-point (get-buffer-window mu4e-hdrs-buffer) (point))
(mu4e-hdrs-highlight docid) ;; attempt to highlight the new line
(mu4e-hdrs-highlight docid))
;; return the docid only if the move succeeded ;; return the docid only if the move succeeded
(when succeeded docid)))) (when succeeded docid))))
(defun mu4e-next-header () (defun mu4e-next-header ()
"Move point to the next message header. If this succeeds, return "Move point to the next message header. If this succeeds, return
the new docid. Otherwise, return nil." the new docid. Otherwise, return nil."
(interactive) (interactive)
(mu4e--hdrs-move 1)) (mu4e--hdrs-move 1))
(defun mu4e-prev-header () (defun mu4e-prev-header ()
"Move point to the previous message header. If this succeeds, "Move point to the previous message header. If this succeeds,
return the new docid. Otherwise, return nil." return the new docid. Otherwise, return nil."
@ -819,7 +816,7 @@ not provided, function asks for it."
(concat "/" target))) (concat "/" target)))
(fulltarget (concat mu4e-maildir target))) (fulltarget (concat mu4e-maildir target)))
(when (or (file-directory-p fulltarget) (when (or (file-directory-p fulltarget)
(and (yes-or-no-p (and (yes-or-no-p
(format "%s does not exist. Create now?" fulltarget)) (format "%s does not exist. Create now?" fulltarget))
(mu4e-proc-mkdir fulltarget))) (mu4e-proc-mkdir fulltarget)))
(mu4e-hdrs-mark 'move target) (mu4e-hdrs-mark 'move target)
@ -908,7 +905,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."