Re: [PATCH v4] Emacs: Force left-to-right display for message headers

Subject: Re: [PATCH v4] Emacs: Force left-to-right display for message headers

Date: Thu, 06 Aug 2020 17:50:36 +0300

To: David Bremner,

Cc: David Edmondson

From: Teemu Likonen

* 2020-08-06 09:04:50-03, David Bremner wrote:

> This causes 10 tests to fail for me. At a guess, the added
> LEFT-TO-RIGHT MARK should probably be stripped out in the test
> framework. Either that or added to test output files. The latter
> sounds easy to miss when editing.

For the first time I ran the tests and got over 60 test fails. :-) I'm
probably doing something wrong and have to study the test framework

I don't know which tests are related to the U+200E LEFT-TO-RIGHT MARK
patch but if test output files are representing the content of
notmuch-show-mode buffer then I think U+200E belongs in those expected
output files, even if the character is invisible.

But here is another idea for the whole thing: When displaying a message
in notmuch-show buffer check if message's From header has any
right-to-left characters and only if it does add invisible U+200E
character at the beginning, otherwise don't bother. This way those tests
probably won't be affected. What do you think?

Below is a quick try on the top of my previous (v4) patch. I'll do a
proper patch later.

diff --git i/emacs/notmuch-show.el w/emacs/notmuch-show.el
index 6548891f..6b7d70d9 100644
--- i/emacs/notmuch-show.el
+++ w/emacs/notmuch-show.el
@@ -465,22 +465,23 @@ unchanged ADDRESS if parsing fails."
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
-  (let ((start (point)))
-    (insert (propertize (string ?\x200e) 'invisible t)
-	    ;; Add invisible U+200E LEFT-TO-RIGHT MARK character (see
-	    ;; above) to force the header paragraph as left-to-right
-	    ;; text even if the header content started with
-	    ;; right-to-left characters.
-	    (notmuch-show-spaces-n (* notmuch-show-indent-messages-width depth))
-	    (notmuch-sanitize
-	     (notmuch-show-clean-address (plist-get headers :From)))
-	    " ("
-	    date
-	    ") ("
-	    (notmuch-tag-format-tags tags tags)
-	    ")\n")
+  (let ((start (point))
+        (from (notmuch-sanitize
+               (notmuch-show-clean-address (plist-get headers :From)))))
+    (insert (when (string-match "\\cR" from)
+              ;; If the From header has a right-to-left character add
+              ;; invisible U+200E LEFT-TO-RIGHT MARK character which
+              ;; forces the header paragraph as left-to-right text.
+              (propertize (string ?\x200e) 'invisible t))
+            (notmuch-show-spaces-n (* notmuch-show-indent-messages-width depth))
+            from
+            " ("
+            date
+            ") ("
+            (notmuch-tag-format-tags tags tags)
+            ")\n")
     (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))
 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."

/// Teemu Likonen - .-..
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450
signature.asc (application/pgp-signature)
notmuch mailing list --
To unsubscribe send an email to