5 Commits a276477ea4 ... 9fa154e114

Author SHA1 Message Date
  Pierre Neidhardt 9fa154e114 readme: Fix screenshot display 2 years ago
  Pierre Neidhardt 1c9102878d Don't display nil as sender name when not provided 2 years ago
  Pierre Neidhardt 06b5840235 Sort linear threads chronologically 2 years ago
  Pierre Neidhardt f8ca2ea784 Use "linear" and "tree" in printing function names 2 years ago
  Pierre Neidhardt e8af7162c5 One use mu4e-conversation-own-name defcustom if non-nil 2 years ago
2 changed files with 47 additions and 24 deletions
  1. 45 23
      mu4e-conversation.el
  2. 2 1
      readme.org

+ 45 - 23
mu4e-conversation.el

@@ -39,21 +39,26 @@
 (require 'rx)
 (require 'outline)
 
-(defvar mu4e-conversation-my-name "Me")
-
 (defvar mu4e-conversation--thread-headers nil)
 (defvar mu4e-conversation--thread nil)
 (defvar mu4e-conversation--current-message nil)
 
-(defvar mu4e-conversation-print-message-function 'mu4e-conversation-print-message
-  "Function that takes a message and insert it's content in the current buffer.
-The second argument is the message index in
-`mu4e-conversation--thread', counting from 0.")
+(defvar mu4e-conversation-print-message-function 'mu4e-conversation-print-message-linear
+  "Function that insert the formatted content of a message in the current buffer.
+The argument is the message index in `mu4e-conversation--thread',
+counting from 0.")
 
 (defgroup mu4e-conversation nil
   "Settings for the mu4e conversation view."
   :group 'mu4e)
 
+(defcustom mu4e-conversation-own-name "Me"
+  "Name to display instead of your own name.
+This applies to addresses matching `mu4e-user-mail-address-list'.
+If nil, the name value is not substituted."
+  :type 'string
+  :group 'mu4e-conversation)
+
 (defface mu4e-conversation-unread
   '((t :weight bold))
   "Face for unread messages."
@@ -115,6 +120,8 @@ If 0, don't use colors.
 If less than 0, don't limit the number of colors."
   :type 'integer
   :group 'mu4e-conversation)
+
+;; TODO: Maybe we need multiple maps: a common one, and one for each view.
 (defcustom mu4e-conversation-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "[") 'mu4e-conversation-previous-message)
@@ -165,19 +172,28 @@ messages.  A negative COUNT goes backwards."
 (defun mu4e-conversation-toggle-view ()
   "Switch between tree and linear view."
   (interactive)
-  (mu4e-conversation-show
+  (mu4e-conversation-show-thread
    (if (eq major-mode 'org-mode)
-       'mu4e-conversation-print-message
-     'mu4e-conversation-print-org-message)))
+       'mu4e-conversation-print-message-linear
+     'mu4e-conversation-print-message-tree)))
 
-(defun mu4e-conversation-show (&optional print-function)
+(defun mu4e-conversation-show-thread (&optional print-function)
   "Display the thread in the `mu4e-conversation--buffer-name' buffer."
   ;; See the docstring of `mu4e-message-field-raw'.
   (switch-to-buffer (get-buffer-create mu4e~view-buffer-name))
   (view-mode 0)
   (erase-buffer)
-  (let ((current-message-pos 0)
-        (index 0))
+  (let* ((current-message-pos 0)
+         (index 0)
+         (filter (lambda (seq) (if (eq mu4e-conversation-print-message-function 'mu4e-conversation-print-message-linear)
+                                   ;; In linear view, it makes more sense to sort messages chronologically.
+                                   (sort seq
+                                         (lambda (msg1 msg2)
+                                           (time-less-p (mu4e-message-field msg1 :date)
+                                                        (mu4e-message-field msg2 :date))))
+                                 seq)))
+         (mu4e-conversation--thread (funcall filter mu4e-conversation--thread))
+         (mu4e-conversation--thread-headers (funcall filter mu4e-conversation--thread-headers)))
     (dolist (msg mu4e-conversation--thread)
       (when (= (mu4e-message-field msg :docid)
                (mu4e-message-field mu4e-conversation--current-message :docid))
@@ -229,7 +245,17 @@ E-mails whose sender is in `mu4e-user-mail-address-list' are skipped."
           (setq face-index (1+ face-index)))))
     (gethash sender-key sender-faces)))
 
-(defun mu4e-conversation-print-message (index)
+(defun mu4e-conversation--from-name (message)
+  "Return a string describing the sender (the 'from' field) of MESSAGE."
+  (let* ((from (car (mu4e-message-field message :from)))
+         (from-me-p (member (cdr from) mu4e-user-mail-address-list)))
+    (if (and mu4e-conversation-own-name from-me-p)
+        mu4e-conversation-own-name
+      (concat (car from)
+              (when (car from) " ")
+              (format "<%s>" (cdr from))))))
+
+(defun mu4e-conversation-print-message-linear (index)
   "Insert formatted message found at INDEX in `mu4e-conversation--thread'."
   ;; See the docstring of `mu4e-message-field-raw'.
   (unless (eq major-mode 'mu4e-view-mode)
@@ -243,14 +269,12 @@ E-mails whose sender is in `mu4e-user-mail-address-list' are skipped."
                           (and (/= 0 mu4e-conversation-max-colors) (mu4e-conversation--get-message-face index))
                           'default)))
     (insert (propertize (format "%s, %s %s\n"
-                                (if from-me-p
-                                    mu4e-conversation-my-name
-                                  (format "%s <%s>" (car from) (cdr from)))
+                                (mu4e-conversation--from-name msg)
                                 (current-time-string (mu4e-message-field msg :date))
                                 (mu4e-message-field msg :flags))
                         'face 'mu4e-conversation-header
                         'msg msg)
-            (or (mu4e~view-construct-attachments-header msg) "")
+            (or (mu4e~view-construct-attachments-header msg) "") ; TODO: Append newline?
             ;; TODO: Add button to display trimmed quote.
             ;; TODO: `mu4e-compose-reply' does not work when point is at end-of-buffer.
             (let ((s (propertize (mu4e-message-body-text msg) 'msg msg)))
@@ -259,7 +283,7 @@ E-mails whose sender is in `mu4e-user-mail-address-list' are skipped."
                 (add-face-text-property 0 (length s) 'mu4e-conversation-unread nil s))
               s))))
 
-(defun mu4e-conversation-print-org-message (index)
+(defun mu4e-conversation-print-message-tree (index)
   "Insert formatted message found at INDEX in `mu4e-conversation--thread'."
   ;; See the docstring of `mu4e-message-field-raw'.
   (unless (eq major-mode 'org-mode)
@@ -274,11 +298,9 @@ E-mails whose sender is in `mu4e-user-mail-address-list' are skipped."
     (insert (format "%s %s%s, %s %s\n"
                     org-level
                     (if (memq 'unread (mu4e-message-field msg :flags))
-                      "UNREAD "
+                        "UNREAD "
                       "")
-                    (if from-me-p
-                        mu4e-conversation-my-name
-                      (format "%s <%s>" (car from) (cdr from)))
+                    (mu4e-conversation--from-name msg)
                     (current-time-string (mu4e-message-field msg :date))
                     (mu4e-message-field msg :flags))
             ;; TODO: Put quote in subsection / property?
@@ -300,7 +322,7 @@ E-mails whose sender is in `mu4e-user-mail-address-list' are skipped."
       (unless (window-live-p viewwin)
         (mu4e-error "Cannot get a conversation window"))
       (select-window viewwin))
-    (mu4e-conversation-show)))
+    (mu4e-conversation-show-thread)))
 
 (defun mu4e-conversation-header-handler (msg)
   "Store thread messages.

+ 2 - 1
readme.org

@@ -29,6 +29,7 @@ command (e.g. ~mu4e-headers-next~, ~helm-mu~), call
 
 * Screenshots
 
-[[mu4e-conversation/src/master/mu4e-conversation-linear.png][Linear view]]
+  #+ATTR_HTML: :width 800px
+  [[./mu4e-conversation/src/master/mu4e-conversation-linear.png]]
 
 [[mu4e-conversation/src/master/mu4e-conversation-tree.png][Tree view]]