From aea2f58c77fcc669f3db13dc9b28b06f13b8eccd Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 14 May 2022 20:45:33 +0300 Subject: [PATCH] mu4e: add command mu4e-sexp-at-point Add command ~mu4e-sexp-at-point~ for showing/hiding the s-expression for the message-at-point. Useful for development / debugging. Bound to ~,~ in headers and view mode. --- NEWS.org | 4 ++++ mu4e/mu4e-headers.el | 2 ++ mu4e/mu4e-message.el | 27 +++++++++++++++++---------- mu4e/mu4e-view.el | 1 + 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/NEWS.org b/NEWS.org index be7e1678..0517215e 100644 --- a/NEWS.org +++ b/NEWS.org @@ -119,6 +119,10 @@ - Removed header-fields ~:attachments~, ~:signature~, ~:encryption~ and ~:user-agent~. They're obsolete with the Gnus-based message viewer. + - Add command ~mu4e-sexp-at-point~ for showing/hiding the s-expression for the + message-at-point. Useful for development / debugging. Bound to ~,~ in headers + and view mode. + - undo is now supported across message-saves - a lot of the internals have been changed: diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index e8824fbc..65b4da5f 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -932,6 +932,8 @@ after the end of the search results." (define-key map "t" 'mu4e-headers-mark-subthread) (define-key map "T" 'mu4e-headers-mark-thread) + (define-key map "," #'mu4e-sexp-at-point) + ;; navigation between messages (define-key map "p" 'mu4e-headers-prev) (define-key map "n" 'mu4e-headers-next) diff --git a/mu4e/mu4e-message.el b/mu4e/mu4e-message.el index 7298f419..8868ce79 100644 --- a/mu4e/mu4e-message.el +++ b/mu4e/mu4e-message.el @@ -30,6 +30,7 @@ (require 'mu4e-contacts) (require 'flow-fill) (require 'shr) +(require 'pp) (declare-function mu4e-error "mu4e-helpers") (declare-function mu4e-warn "mu4e-helpers") @@ -47,9 +48,9 @@ (defsubst mu4e-message-field-raw (msg field) "Retrieve FIELD from message plist MSG. -FIELD is one of :from, :to, :cc, :bcc, :subject, :data, -:message-id, :path, :maildir, :priority, :attachments, -:references, :in-reply-to, :body-txt, :body-html + +See \"mu fields\" for the full list of field, in particular the +\"sexp\" column. Returns nil if the field does not exist. @@ -66,13 +67,6 @@ A message plist looks something like: :maildir \"/INBOX\" :priority normal :flags (seen) - :attachments - ((:index 2 :name \"photo.jpg\" :mime-type \"image/jpeg\" :size 147331) - (:index 3 :name \"book.pdf\" :mime-type \"application/pdf\" :size 192220)) - :references (\"238C8384574032D81EE81AF0114E4E74@123213.mail.example.com\" - \"6BDC23465F79238203498230942D81EE81AF0114E4E74@123213.mail.example.com\") - :in-reply-to \"238203498230942D81EE81AF0114E4E74@123213.mail.example.com\" - :body-txt \"Hi Tom, ...\" \)). Some notes on the format: - The address fields are lists of plist (:name NAME :email EMAIL), @@ -228,6 +222,19 @@ If MSG is nil, use `mu4e-message-at-point'." (kill-new path) (mu4e-message "Saved '%s' to kill-ring" path))) +(defconst mu4e--sexp-buffer-name " *mu4e-sexp-at-point" + "Buffer name for sexp buffers.") + +(defun mu4e-sexp-at-point () + "Show or hide the s-expression for the message-at-point, if any." + (interactive) + (if-let ((win (get-buffer-window mu4e--sexp-buffer-name))) + (delete-window win) + (when-let ((msg (mu4e-message-at-point 'noerror))) + (with-current-buffer-window mu4e--sexp-buffer-name nil nil + ;; the "pretty-printing" is not very pretty... + (insert (pp-to-string msg)))))) + ;;; (provide 'mu4e-message) ;;; mu4e-message.el ends here diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index c43bec23..bd376775 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -887,6 +887,7 @@ This is useful for advising some Gnus-functionality that does not work in mu4e." (define-key map "E" #'mu4e-compose-edit) (define-key map "." #'mu4e-view-raw-message) + (define-key map "," #'mu4e-sexp-at-point) (define-key map "|" #'mu4e-view-pipe) (define-key map "a" #'mu4e-view-action) (define-key map "A" #'mu4e-view-mime-part-action)