unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC] [PATCH v1 0/2] Improve the display of headers.
@ 2016-12-28 12:18 David Edmondson
  2016-12-28 12:18 ` [PATCH v1 1/2] emacs: show: Align the colon in header display David Edmondson
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: David Edmondson @ 2016-12-28 12:18 UTC (permalink / raw)
  To: notmuch


This is a pair of patches that attempt to make header display more
pleasant to look at. RFC!

I will update the tests if the results of the changes are considered
useful, of course.


David Edmondson (2):
  emacs: show: Align the colon in header display
  emacs: show: Wrap headers for display

 emacs/notmuch-show.el | 124 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 83 insertions(+), 41 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/2] emacs: show: Align the colon in header display
  2016-12-28 12:18 [RFC] [PATCH v1 0/2] Improve the display of headers David Edmondson
@ 2016-12-28 12:18 ` David Edmondson
  2016-12-28 12:18 ` [PATCH v1 2/2] emacs: show: Wrap headers for display David Edmondson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: David Edmondson @ 2016-12-28 12:18 UTC (permalink / raw)
  To: notmuch

When displaying headers, insert leading space so that the `:' in all
of the headers shown is aligned.
---
 emacs/notmuch-show.el | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 364004b8..677405ba 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -345,11 +345,11 @@ operation on the contents of the current buffer."
 
 (defun notmuch-show-fontify-header ()
   (let ((face (cond
-	       ((looking-at "[Tt]o:")
+	       ((looking-at " *[Tt]o:")
 		'message-header-to)
-	       ((looking-at "[Bb]?[Cc][Cc]:")
+	       ((looking-at " *[Bb]?[Cc][Cc]:")
 		'message-header-cc)
-	       ((looking-at "[Ss]ubject:")
+	       ((looking-at " *[Ss]ubject:")
 		'message-header-subject)
 	       (t
 		'message-header-other))))
@@ -362,7 +362,7 @@ operation on the contents of the current buffer."
 (defun notmuch-show-colour-headers ()
   "Apply some colouring to the current headers."
   (goto-char (point-min))
-  (while (looking-at "^[A-Za-z][-A-Za-z0-9]*:")
+  (while (looking-at "^ *[A-Za-z][-A-Za-z0-9]*:")
     (notmuch-show-fontify-header)
     (forward-line)))
 
@@ -462,7 +462,8 @@ message at DEPTH in the current thread."
 
 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."
-  (insert header ": " (notmuch-sanitize header-value) "\n"))
+  ;; `7' because `Subject' is the longest header.
+  (insert (format "%7s: %s\n" header (notmuch-sanitize header-value))))
 
 (defun notmuch-show-insert-headers (headers)
   "Insert the headers of the current message."
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 2/2] emacs: show: Wrap headers for display
  2016-12-28 12:18 [RFC] [PATCH v1 0/2] Improve the display of headers David Edmondson
  2016-12-28 12:18 ` [PATCH v1 1/2] emacs: show: Align the colon in header display David Edmondson
@ 2016-12-28 12:18 ` David Edmondson
  2016-12-29 13:52 ` [RFC] [PATCH v1 0/2] Improve the display of headers David Bremner
  2017-01-05 15:28 ` Servilio Afre Puentes
  3 siblings, 0 replies; 9+ messages in thread
From: David Edmondson @ 2016-12-28 12:18 UTC (permalink / raw)
  To: notmuch

When displaying mail headers, wrap them to the width of the window
used for display. Attempt to do so at appropriate boundaries.
---
 emacs/notmuch-show.el | 125 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 83 insertions(+), 42 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 677405ba..10f0233c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -79,10 +79,6 @@ visible for any given message."
   :type 'boolean
   :group 'notmuch-show)
 
-(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
-  "A list of functions called to decorate the headers listed in
-`notmuch-message-headers'.")
-
 (defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
   "Functions called after populating a `notmuch-show' buffer."
   :type 'hook
@@ -343,29 +339,6 @@ operation on the contents of the current buffer."
   (interactive)
   (notmuch-show-with-message-as-text 'notmuch-print-message))
 
-(defun notmuch-show-fontify-header ()
-  (let ((face (cond
-	       ((looking-at " *[Tt]o:")
-		'message-header-to)
-	       ((looking-at " *[Bb]?[Cc][Cc]:")
-		'message-header-cc)
-	       ((looking-at " *[Ss]ubject:")
-		'message-header-subject)
-	       (t
-		'message-header-other))))
-
-    (overlay-put (make-overlay (point) (re-search-forward ":"))
-		 'face 'message-header-name)
-    (overlay-put (make-overlay (point) (re-search-forward ".*$"))
-		 'face face)))
-
-(defun notmuch-show-colour-headers ()
-  "Apply some colouring to the current headers."
-  (goto-char (point-min))
-  (while (looking-at "^ *[A-Za-z][-A-Za-z0-9]*:")
-    (notmuch-show-fontify-header)
-    (forward-line)))
-
 (defun notmuch-show-spaces-n (n)
   "Return a string comprised of `n' spaces."
   (make-string n ? ))
@@ -460,25 +433,93 @@ message at DEPTH in the current thread."
 	    ")\n")
     (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))
 
+(defun notmuch-show--wrap-header (header width separator)
+  "Wrap a HEADER for display in WIDTH characters splitting at
+SEPARATOR. Returns a list of strings."
+  (let* ((split-header (split-string header separator))
+	 (n-element (length split-header))
+	 (nth 1)
+	 this-result results)
+    (mapc (lambda (element)
+	    ;; If this is not the last element, we will need a
+	    ;; separator.
+	    (let ((element-and-separator
+		   (concat element (unless (eq nth n-element) separator))))
+	      (if (> (+ (length this-result)
+			(length element-and-separator))
+		     width)
+		  ;; Adding this element to that already collected
+		  ;; would overflow the width, so record anything
+		  ;; already collected and reset the collection to
+		  ;; just this element.
+		  (if this-result
+		      (progn
+			(push this-result results)
+			(setq this-result element-and-separator))
+		    (push element-and-separator results))
+		;; Add this element to anything already collected.
+		(setq this-result (concat this-result element-and-separator)))
+	      (setq nth (+ 1 nth))))
+	  split-header)
+    ;; If anything was left in the collection buffer, record it.
+    (when this-result
+      (push this-result results))
+    (reverse results)))
+
+(defun notmuch-show--face-for-header (header)
+  "Return the face to use to highlight HEADER."
+  (cond
+   ((string= "To" header)
+    'message-header-to)
+   ((or (string= "Cc" header)
+	(string= "Bcc" header))
+    'message-header-cc)
+   ((string= "Subject" header)
+    'message-header-subject)
+   (t
+    'message-header-other)))
+
+(defun notmuch-show--separator-for-header (header)
+  "What separator should be used when splitting HEADER?"
+  (cond
+   ((or (string= "To" header)
+	(string= "Cc" header)
+	(string= "Bcc" header)
+	(string= "From" header))
+    ", ")
+   (t
+    " ")))
+
 (defun notmuch-show-insert-header (header header-value)
-  "Insert a single header."
-  ;; `7' because `Subject' is the longest header.
-  (insert (format "%7s: %s\n" header (notmuch-sanitize header-value))))
+  "Insert HEADER with value HEADER-VALUE."
+  (let* ((value-face (notmuch-show--face-for-header header))
+	 (separator (notmuch-show--separator-for-header header))
+	 ;; `9' due to the header name and `: '.
+	 (width (- (window-width) 9))
+	 (header-lines (notmuch-show--wrap-header
+			(notmuch-sanitize header-value) width separator))
+	 (first-header (car header-lines))
+	 (remaining-header-lines (cdr header-lines)))
+
+    ;; `7' because `Subject' is the longest header.
+    (insert (format "%7s: %s\n"
+		    (propertize header 'face 'message-header-name)
+		    (propertize first-header 'face value-face)))
+
+    (mapc (lambda (header)
+	    (insert (format "%7s  %s\n" ""
+			    (propertize header 'face value-face))))
+	  remaining-header-lines)))
 
 (defun notmuch-show-insert-headers (headers)
   "Insert the headers of the current message."
-  (let ((start (point)))
-    (mapc (lambda (header)
-	    (let* ((header-symbol (intern (concat ":" header)))
-		   (header-value (plist-get headers header-symbol)))
-	      (if (and header-value
-		       (not (string-equal "" header-value)))
-		  (notmuch-show-insert-header header header-value))))
-	  notmuch-message-headers)
-    (save-excursion
-      (save-restriction
-	(narrow-to-region start (point-max))
-	(run-hooks 'notmuch-show-markup-headers-hook)))))
+  (mapc (lambda (header)
+	  (let* ((header-symbol (intern (concat ":" header)))
+		 (header-value (plist-get headers header-symbol)))
+	    (if (and header-value
+		     (not (string-equal "" header-value)))
+		(notmuch-show-insert-header header header-value))))
+	notmuch-message-headers))
 
 (define-button-type 'notmuch-show-part-button-type
   'action 'notmuch-show-part-button-default
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [RFC] [PATCH v1 0/2] Improve the display of headers.
  2016-12-28 12:18 [RFC] [PATCH v1 0/2] Improve the display of headers David Edmondson
  2016-12-28 12:18 ` [PATCH v1 1/2] emacs: show: Align the colon in header display David Edmondson
  2016-12-28 12:18 ` [PATCH v1 2/2] emacs: show: Wrap headers for display David Edmondson
@ 2016-12-29 13:52 ` David Bremner
  2016-12-29 17:02   ` David Edmondson
  2017-01-05 15:28 ` Servilio Afre Puentes
  3 siblings, 1 reply; 9+ messages in thread
From: David Bremner @ 2016-12-29 13:52 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

> This is a pair of patches that attempt to make header display more
> pleasant to look at. RFC!
>
> I will update the tests if the results of the changes are considered
> useful, of course.
>

Hi David;

The wrapping seems a bit fragile. Some of the lines are wrapped to the
left column and others line up with the headers. To reproduce, try
id:87wpgjxeia.fsf@nikula.org at about 40 columns. It looks like two
different kinds of wrapping going on.

About aligning the headers I'm not sure how I feel yet.  I probably need
to use it a bit to give an informed opinion.  I agree it makes the
individual headers easier to pick out, but I have some kind of knee jerk
reaction to using up space that way. That might be my 1980s VT52
instincts kicking in uselessly though.

d

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] [PATCH v1 0/2] Improve the display of headers.
  2016-12-29 13:52 ` [RFC] [PATCH v1 0/2] Improve the display of headers David Bremner
@ 2016-12-29 17:02   ` David Edmondson
  2016-12-30  5:03     ` David Bremner
  0 siblings, 1 reply; 9+ messages in thread
From: David Edmondson @ 2016-12-29 17:02 UTC (permalink / raw)
  To: David Bremner, notmuch

On Thu, Dec 29 2016, David Bremner wrote:

> David Edmondson <dme@dme.org> writes:
>
>> This is a pair of patches that attempt to make header display more
>> pleasant to look at. RFC!
>>
>> I will update the tests if the results of the changes are considered
>> useful, of course.
>>
>
> Hi David;
>
> The wrapping seems a bit fragile. Some of the lines are wrapped to the
> left column and others line up with the headers. To reproduce, try
> id:87wpgjxeia.fsf@nikula.org at about 40 columns. It looks like two
> different kinds of wrapping going on.

This doesn't reproduce for me. Do you have any interesting settings
relating to line wrapping or truncation?

> About aligning the headers I'm not sure how I feel yet.  I probably
> need to use it a bit to give an informed opinion.  I agree it makes
> the individual headers easier to pick out, but I have some kind of
> knee jerk reaction to using up space that way. That might be my 1980s
> VT52 instincts kicking in uselessly though.

Agreed. I've been playing with another patch to hide the wrapped headers
behind a button, but that is running into difficulties with
`indent-rigidly' and invisible text...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] [PATCH v1 0/2] Improve the display of headers.
  2016-12-29 17:02   ` David Edmondson
@ 2016-12-30  5:03     ` David Bremner
  2016-12-30 12:10       ` David Edmondson
  0 siblings, 1 reply; 9+ messages in thread
From: David Bremner @ 2016-12-30  5:03 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

> On Thu, Dec 29 2016, David Bremner wrote:
>
>> David Edmondson <dme@dme.org> writes:
>>
>>> This is a pair of patches that attempt to make header display more
>>> pleasant to look at. RFC!
>>>
>>> I will update the tests if the results of the changes are considered
>>> useful, of course.
>>>
>>
>> Hi David;
>>
>> The wrapping seems a bit fragile. Some of the lines are wrapped to the
>> left column and others line up with the headers. To reproduce, try
>> id:87wpgjxeia.fsf@nikula.org at about 40 columns. It looks like two
>> different kinds of wrapping going on.
>
> This doesn't reproduce for me. Do you have any interesting settings
> relating to line wrapping or truncation?

I don't think so. I can duplicate this with ./devel/try-emacs-mua -Q
with emacs 24 and 25.

d

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] [PATCH v1 0/2] Improve the display of headers.
  2016-12-30  5:03     ` David Bremner
@ 2016-12-30 12:10       ` David Edmondson
  0 siblings, 0 replies; 9+ messages in thread
From: David Edmondson @ 2016-12-30 12:10 UTC (permalink / raw)
  To: David Bremner, notmuch

On Fri, Dec 30 2016, David Bremner wrote:

> David Edmondson <dme@dme.org> writes:
>
>> On Thu, Dec 29 2016, David Bremner wrote:
>>
>>> David Edmondson <dme@dme.org> writes:
>>>
>>>> This is a pair of patches that attempt to make header display more
>>>> pleasant to look at. RFC!
>>>>
>>>> I will update the tests if the results of the changes are considered
>>>> useful, of course.
>>>>
>>>
>>> Hi David;
>>>
>>> The wrapping seems a bit fragile. Some of the lines are wrapped to the
>>> left column and others line up with the headers. To reproduce, try
>>> id:87wpgjxeia.fsf@nikula.org at about 40 columns. It looks like two
>>> different kinds of wrapping going on.
>>
>> This doesn't reproduce for me. Do you have any interesting settings
>> relating to line wrapping or truncation?
>
> I don't think so. I can duplicate this with ./devel/try-emacs-mua -Q
> with emacs 24 and 25.

Ah, this is caused by `truncate-lines' being `nil', which is the result
of `notmuch-show-hook' including `notmuch-show-turn-on-visual-line-mode'
by default - I have never used that.

Ugh, so the implication of this is that most people are seeing horribly
wrapped headers all of the time!

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] [PATCH v1 0/2] Improve the display of headers.
  2016-12-28 12:18 [RFC] [PATCH v1 0/2] Improve the display of headers David Edmondson
                   ` (2 preceding siblings ...)
  2016-12-29 13:52 ` [RFC] [PATCH v1 0/2] Improve the display of headers David Bremner
@ 2017-01-05 15:28 ` Servilio Afre Puentes
  2017-01-05 15:36   ` David Edmondson
  3 siblings, 1 reply; 9+ messages in thread
From: Servilio Afre Puentes @ 2017-01-05 15:28 UTC (permalink / raw)
  To: David Edmondson, notmuch

Hi David,

I like the idea of aligning the headers, but won't padding with spaces
from the left break code that expects at the beginning of the line?

Servilio

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] [PATCH v1 0/2] Improve the display of headers.
  2017-01-05 15:28 ` Servilio Afre Puentes
@ 2017-01-05 15:36   ` David Edmondson
  0 siblings, 0 replies; 9+ messages in thread
From: David Edmondson @ 2017-01-05 15:36 UTC (permalink / raw)
  To: Servilio Afre Puentes, notmuch

On Thu, Jan 05 2017, Servilio Afre Puentes wrote:

> I like the idea of aligning the headers, but won't padding with spaces
> from the left break code that expects at the beginning of the line?

It would. Do you know of such code? The one piece that I noticed (that
coloured the headers) I re-worked.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-01-05 15:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-28 12:18 [RFC] [PATCH v1 0/2] Improve the display of headers David Edmondson
2016-12-28 12:18 ` [PATCH v1 1/2] emacs: show: Align the colon in header display David Edmondson
2016-12-28 12:18 ` [PATCH v1 2/2] emacs: show: Wrap headers for display David Edmondson
2016-12-29 13:52 ` [RFC] [PATCH v1 0/2] Improve the display of headers David Bremner
2016-12-29 17:02   ` David Edmondson
2016-12-30  5:03     ` David Bremner
2016-12-30 12:10       ` David Edmondson
2017-01-05 15:28 ` Servilio Afre Puentes
2017-01-05 15:36   ` David Edmondson

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).