[PATCH v1] emacs: Improved header display.
David Edmondson
dme at dme.org
Thu Oct 30 11:03:16 PDT 2014
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
More information about the notmuch
mailing list