[PATCH v1] emacs: Improved header display.

David Edmondson dme at dme.org
Fri Oct 31 00:00:59 PDT 2014


On Thu, Oct 30 2014, Jani Nikula wrote:
> On Thu, 30 Oct 2014, David Edmondson <dme at dme.org> wrote:
>> Truncate the displayed headers to the window width. Show an ellipsis
>> if the displayed header is truncated. Add a binding 'T' to toggle the
>> truncation of headers. Add the not-displayed section of the header as
>> a tooltip to the displayed section.
>
> Thanks for your efforts, David - I hate it that I'm going to sound
> ungrateful since I asked for something like this. But not quite like
> this...
>
> I think more header lines than just one should be displayed untruncated
> by default. I think it's okay to show, say, five lines of To: or Cc: and
> that'll probably cover most emails without truncation. And when the
> header does get truncated, I'd really like to see the indication more
> predominantly displayed than just ellipsis.
>
> I'm thinking of something like this, similar to notmuch-wash:
>
> ---
> To: user at example.com, user at example.com, user at example.com,
> user at example.com, user at example.com, user at example.com, user at example.com,
> user at example.com, user at example.com, user at example.com, user at example.com,
> user at example.com, user at example.com, user at example.com, user at example.com,
> [ 42 more header lines. Click/Enter to show. ]
> Cc: user at example.com
> ---

Hmm. That seems pretty ugly to me :-)

As you mentioned in #notmuch, the implementation below is also not quite
correct - it assumes that it is splitting addresses but is also used on
the non-address headers. There are also some oddities when the header
lines of collapsed messages are compressed.

If anyone else is particularly interested then I may come back to it,
but otherwise will leave it alone.

> BR,
> Jani.
>
>
>> ---
>>  emacs/notmuch-show.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++++---
>>  1 file changed, 51 insertions(+), 3 deletions(-)
>>
>> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
>> index a997482..523cef5 100644
>> --- a/emacs/notmuch-show.el
>> +++ b/emacs/notmuch-show.el
>> @@ -443,9 +443,56 @@ message at DEPTH in the current thread."
>>  	    ")\n")
>>      (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))
>>  
>> +(defun notmuch-truncate-nicely (addresses target-length)
>> +  ;; If it fits, everything is easy.
>> +  (if (< (length addresses) target-length)
>> +      (cons addresses nil)
>> +    (let* ((visible-length (- target-length (length "...")))
>> +	   (visible (substring addresses 0 visible-length))
>> +	   (invisible (substring addresses visible-length)))
>> +      ;; Try to terminate the visible string at a good break point.
>> +      (when (string-match "\\(.+\\),\\([^,]*\\)" visible)
>> +	;; Order is important (second clause is destructive on
>> +	;; `visible'.
>> +	(setq invisible (concat (match-string 2 visible) invisible)
>> +	      visible (match-string 1 visible)))
>> +      ;; `invisible' can end up with a leading space or
>> +      ;; comma-space, because the list of addresses is
>> +      ;; seperated with ", ", but we split on ",".
>> +      (setq invisible (replace-regexp-in-string "^[, ]*\\(.*\\)$" "\\1" invisible))
>> +      (cons visible invisible))))
>> +
>> +(defun notmuch-show-toggle-header-truncation ()
>> +  (interactive)
>> +  (let ((invisibility-spec-member (cons 'notmuch-show-mode t)))
>> +    (if (member invisibility-spec-member buffer-invisibility-spec)
>> +	(remove-from-invisibility-spec invisibility-spec-member)
>> +      (add-to-invisibility-spec invisibility-spec-member)))
>> +  ;; Required to have the change in visibility take effect.
>> +  (force-window-update))
>> +
>>  (defun notmuch-show-insert-header (header header-value)
>>    "Insert a single header."
>> -  (insert header ": " (notmuch-sanitize header-value) "\n"))
>> +  (let* ((header-value (notmuch-sanitize header-value))
>> +	 (header-colon (concat header ": "))
>> +	 (available-width (- (window-width) (length header-colon)))
>> +	 (v-i (notmuch-truncate-nicely header-value available-width)))
>> +
>> +    (insert header-colon)
>> +    (let ((visible (car v-i))
>> +	  (invisible (cdr v-i)))
>> +      (when invisible
>> +	(setq visible (propertize visible 'help-echo (concat "..." invisible))))
>> +      (insert visible)
>> +      (when invisible
>> +	(insert ", ")
>> +	(let ((start (point))
>> +	      overlay)
>> +	  (insert invisible)
>> +	  (setq overlay (make-overlay start (point)))
>> +	  (overlay-put overlay 'invisible 'notmuch-show-mode)
>> +	  (overlay-put overlay 'isearch-open-invisible #'delete-overlay))))
>> +    (insert "\n")))
>>  
>>  (defun notmuch-show-insert-headers (headers)
>>    "Insert the headers of the current message."
>> @@ -1328,6 +1375,7 @@ reset based on the original query."
>>      (define-key map "$" 'notmuch-show-toggle-process-crypto)
>>      (define-key map "<" 'notmuch-show-toggle-thread-indentation)
>>      (define-key map "t" 'toggle-truncate-lines)
>> +    (define-key map "T" 'notmuch-show-toggle-header-truncation)
>>      (define-key map "." 'notmuch-show-part-map)
>>      map)
>>    "Keymap for \"notmuch show\" buffers.")
>> @@ -1367,8 +1415,8 @@ All currently available key bindings:
>>    (use-local-map notmuch-show-mode-map)
>>    (setq major-mode 'notmuch-show-mode
>>  	mode-name "notmuch-show")
>> -  (setq buffer-read-only t
>> -	truncate-lines t))
>> +  (add-to-invisibility-spec (cons 'notmuch-show-mode t))
>> +  (setq buffer-read-only t))
>>  
>>  (defun notmuch-tree-from-show-current-query ()
>>    "Call notmuch tree with the current query"
>> -- 
>> 2.1.1
>>
>> _______________________________________________
>> notmuch mailing list
>> notmuch at notmuchmail.org
>> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list