From 913ff4ac053b7b6134031c3194c49e35e90e8105 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Thu, 30 Oct 2014 18:03:16 +0000 Subject: [PATCH] [PATCH v1] emacs: Improved header display. --- b8/2fd8cae072f584bcb43449cdba52839a512cb7 | 160 ++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 b8/2fd8cae072f584bcb43449cdba52839a512cb7 diff --git a/b8/2fd8cae072f584bcb43449cdba52839a512cb7 b/b8/2fd8cae072f584bcb43449cdba52839a512cb7 new file mode 100644 index 000000000..7938d5d63 --- /dev/null +++ b/b8/2fd8cae072f584bcb43449cdba52839a512cb7 @@ -0,0 +1,160 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 9F4F9431FC2 + for ; Thu, 30 Oct 2014 11:03:25 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.699 +X-Spam-Level: +X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id P8MI7zUCVgVs for ; + Thu, 30 Oct 2014 11:03:20 -0700 (PDT) +Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com + [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id AEE4E431FCB + for ; Thu, 30 Oct 2014 11:03:20 -0700 (PDT) +Received: by mail-wi0-f169.google.com with SMTP id n3so1855209wiv.4 + for ; Thu, 30 Oct 2014 11:03:18 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:user-agent:from:to:subject:date:message-id; + bh=i3+w0Q4I4jLdsg9c5Zz7H7VaP//JDuMmenU7xX9fFzA=; + b=Lk1+oAudFEpwyKwuRfC8sAvxkKI8gyX2DRHXSK8zDZ9Ceey3KxSURAe6RYhZRHsASV + RF46u1uyV3bqnvZREu99qGcaVH58G8wYqbEcJ0C5SJtxmuNqAq/FQ3/3AFi1tVpSQwJw + +JGjT2r5+k28Zh/H2H2IJ1Y/O8padxDvc+yPokgYkHMunmwmjZ9qurSWs3fTh4OlcOL5 + rSVrn6/+Mq2mzE8wgVDFTYH0zk7gXeRPuck6k17NTq6dcc4xOdIDu+Ek6oa+gCI6ooqh + RqGAY8VTA6/u5Cuw+BO8K7QYobI18XPT26M5G5Zxgfk2Nx+AwN30CGApQ/rlvC9qHiju + Yonw== +X-Gm-Message-State: + ALoCoQma+A9kFWeDtjhFO+L4QRF0ECDTEl9kT4A24ExkgvfROJEPXfxEJreYmyGYx5f3rG7AJgnZ +X-Received: by 10.181.8.98 with SMTP id dj2mr21658488wid.70.1414692198209; + Thu, 30 Oct 2014 11:03:18 -0700 (PDT) +Received: from disaster-area.hh.sledj.net + ([2a01:348:1a2:1:ea39:35ff:fe2c:a227]) + by mx.google.com with ESMTPSA id s10sm3991183wix.14.2014.10.30.11.03.17 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Thu, 30 Oct 2014 11:03:17 -0700 (PDT) +Received: from localhost (30000@localhost [local]); + by localhost (OpenSMTPD) with ESMTPA id fa989dfb; + for ; Thu, 30 Oct 2014 18:03:16 +0000 (UTC) +User-Agent: OpenSMTPD enqueuer (Demoostik) +From: David Edmondson +To: notmuch@notmuchmail.org +Subject: [PATCH v1] emacs: Improved header display. +Date: Thu, 30 Oct 2014 18:03:16 +0000 +Message-Id: <1414692196-12550-1-git-send-email-dme@dme.org> +X-Mailer: git-send-email 2.1.1 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 30 Oct 2014 18:03:25 -0000 + +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. +--- + 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 + -- 2.26.2