unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/4] emacs: Record part p-list in a text property
Date: Mon, 27 May 2013 16:46:32 -0400	[thread overview]
Message-ID: <1369687594-31774-3-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1369687594-31774-1-git-send-email-amdragon@mit.edu>

This is similar to what we already do with the message p-list, though
we apply the part's text property to the whole part's text, in
contrast with the message p-list, which is (rather obscurely) only
applied to the first character.
---
 emacs/notmuch-lib.el  |   16 ++++++++++++++++
 emacs/notmuch-show.el |   13 ++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 790136e..09ce25e 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -360,6 +360,22 @@ OBJECT."
    below
    string))
 
+(defun notmuch-put-text-property-if-nil (start end property value
+					       &optional object)
+  "Like `put-text-property', but only set the property where it is nil."
+  (while (< start end)
+    (let ((start-nil (text-property-any start end property nil object)))
+      (if (null start-nil)
+	  ;; There are no more nil regions; exit the loop
+	  (setq start end)
+	;; Find the end of the nil region
+	(let ((end-nil
+	       (or (text-property-not-all start-nil end property nil object)
+		   end)))
+	  ;; Set the property
+	  (put-text-property start-nil end-nil property value object)
+	  (setq start end-nil))))))
+
 (defun notmuch-logged-error (msg &optional extra)
   "Log MSG and EXTRA to *Notmuch errors* and signal MSG.
 
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index a080134..acd0b55 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -900,7 +900,10 @@ If HIDE is non-nil then initially hide this part."
     ;; Ensure that the part ends with a carriage return.
     (unless (bolp)
       (insert "\n"))
-    (notmuch-show-create-part-overlays msg beg (point) hide)))
+    (notmuch-show-create-part-overlays msg beg (point) hide)
+    ;; Record part information.  Since we already inserted subparts,
+    ;; don't override exiting :notmuch-part properties.
+    (notmuch-put-text-property-if-nil beg (point) :notmuch-part part)))
 
 (defun notmuch-show-insert-body (msg body depth)
   "Insert the body BODY at depth DEPTH in the current thread."
@@ -1404,6 +1407,14 @@ Some useful entries are:
     (notmuch-show-move-to-message-top)
     (get-text-property (point) :notmuch-message-properties)))
 
+(defun notmuch-show-get-part-properties ()
+  "Return the properties of the part containing point.
+
+This is the part property list retrieved from the CLI.  Signals
+an error if there is no part containing point."
+  (or (get-text-property (point) :notmuch-part)
+      (error "No message part here")))
+
 (defun notmuch-show-set-prop (prop val &optional props)
   (let ((inhibit-read-only t)
 	(props (or props
-- 
1.7.10.4

  parent reply	other threads:[~2013-05-27 20:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27 20:46 [PATCH 0/4] emacs: Part command improvements Austin Clements
2013-05-27 20:46 ` [PATCH 1/4] emacs: Retain text properties when toggling buttons Austin Clements
2013-05-27 20:46 ` Austin Clements [this message]
2013-05-27 22:19   ` [PATCH 2/4] emacs: Record part p-list in a text property Mark Walters
2013-05-27 20:46 ` [PATCH 3/4] emacs: Simplify MIME part command implementation Austin Clements
2013-05-27 20:46 ` [PATCH 4/4] emacs: Bind MIME part commands to "." submap Austin Clements
2013-05-27 22:30 ` [PATCH 0/4] emacs: Part command improvements Mark Walters
2013-05-30  1:01   ` Austin Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369687594-31774-3-git-send-email-amdragon@mit.edu \
    --to=amdragon@mit.edu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).