]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: Record thread search result object in a text property
authorAustin Clements <amdragon@MIT.EDU>
Sat, 21 Jul 2012 17:37:05 +0000 (13:37 -0400)
committerDavid Bremner <bremner@debian.org>
Tue, 24 Jul 2012 12:04:27 +0000 (09:04 -0300)
This also provides utility functions for working with this text
property that get its value, find its start, and find its end.

emacs/notmuch.el

index fabb7c0d8b3accc74508ccae2f5da891daeaf238..ef1892732d09f4278547f4f8ed2f5b671908eeda 100644 (file)
@@ -401,6 +401,32 @@ Complete list of currently available key bindings:
        mode-name "notmuch-search")
   (setq buffer-read-only t))
 
+(defun notmuch-search-get-result (&optional pos)
+  "Return the result object for the thread at POS (or point).
+
+If there is no thread at POS (or point), returns nil."
+  (get-text-property (or pos (point)) 'notmuch-search-result))
+
+(defun notmuch-search-result-beginning (&optional pos)
+  "Return the point at the beginning of the thread at POS (or point).
+
+If there is no thread at POS (or point), returns nil."
+  (when (notmuch-search-get-result pos)
+    ;; We pass 1+point because previous-single-property-change starts
+    ;; searching one before the position we give it.
+    (previous-single-property-change (1+ (or pos (point)))
+                                    'notmuch-search-result nil (point-min))))
+
+(defun notmuch-search-result-end (&optional pos)
+  "Return the point at the end of the thread at POS (or point).
+
+The returned point will be just after the newline character that
+ends the result line.  If there is no thread at POS (or point),
+returns nil"
+  (when (notmuch-search-get-result pos)
+    (next-single-property-change (or pos (point)) 'notmuch-search-result
+                                nil (point-max))))
+
 (defun notmuch-search-properties-in-region (property beg end)
   (save-excursion
     (let ((output nil)
@@ -736,6 +762,7 @@ non-authors is found, assume that all of the authors match."
          (notmuch-search-insert-field (car spec) (cdr spec) result))
        (insert "\n")
        (notmuch-search-color-line beg (point) (plist-get result :tags))
+       (put-text-property beg (point) 'notmuch-search-result result)
        (put-text-property beg (point) 'notmuch-search-thread-id
                           (concat "thread:" (plist-get result :thread)))
        (put-text-property beg (point) 'notmuch-search-authors