From: Mark Walters <markwalters1009@gmail.com>
To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
Subject: Re: [PATCH v2 4/7] emacs: Use result text properties for search result iteration
Date: Sat, 14 Jul 2012 22:15:12 +0100 [thread overview]
Message-ID: <871ukexcwv.fsf@qmul.ac.uk> (raw)
In-Reply-To: <1342237406-32507-5-git-send-email-amdragon@mit.edu>
On Sat, 14 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:
> This simplifies the traversal of regions of results and eliminates the
> need for save-excursions (which tend to get in the way of maintaining
> point when we make changes to the buffer). It also fixes some strange
> corner cases in the old line-based code where results that bordered
> the region but were not included in it could be affected by region
> commands. Coincidentally, this also essentially enables multi-line
> search result formats; the only remaining non-multi-line-capable
> functions are notmuch-search-{next,previous}-thread, which are only
> used interactively.
Having understood how macros work (thanks to Austin's patient
explanations on irc) this looks fine. So +1 for the whole series.
Best wishes
Mark
> ---
> emacs/notmuch.el | 61 ++++++++++++++++++++++++++++++------------------------
> 1 file changed, 34 insertions(+), 27 deletions(-)
>
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index 8e1a769..92ba2c1 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -427,17 +427,33 @@ returns nil"
> (next-single-property-change (or pos (point)) 'notmuch-search-result
> nil (point-max))))
>
> +(defmacro notmuch-search-do-results (beg end pos-sym &rest body)
> + "Invoke BODY for each result between BEG and END.
> +
> +POS-SYM will be bound to the point at the beginning of the
> +current result."
> + (declare (indent 3))
> + (let ((end-sym (make-symbol "end"))
> + (first-sym (make-symbol "first")))
> + `(let ((,pos-sym (notmuch-search-result-beginning ,beg))
> + ;; End must be a marker in case body changes the text
> + (,end-sym (copy-marker ,end))
> + ;; Make sure we examine one result, even if (= beg end)
> + (,first-sym t))
> + ;; We have to be careful if the region extends beyond the
> + ;; results. In this case, pos could be null or there could be
> + ;; no result at pos.
> + (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))
> + (when (notmuch-search-get-result ,pos-sym)
> + ,@body)
> + (setq ,pos-sym (notmuch-search-result-end ,pos-sym)
> + ,first-sym nil)))))
> +
> (defun notmuch-search-properties-in-region (property beg end)
> - (save-excursion
> - (let ((output nil)
> - (last-line (line-number-at-pos end))
> - (max-line (- (line-number-at-pos (point-max)) 2)))
> - (goto-char beg)
> - (beginning-of-line)
> - (while (<= (line-number-at-pos) (min last-line max-line))
> - (setq output (cons (get-text-property (point) property) output))
> - (forward-line 1))
> - output)))
> + (let (output)
> + (notmuch-search-do-results beg end pos
> + (push (get-text-property pos property) output))
> + output))
>
> (defun notmuch-search-find-thread-id ()
> "Return the thread for the current thread"
> @@ -517,28 +533,19 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
> (plist-get (notmuch-search-get-result pos) :tags))
>
> (defun notmuch-search-get-tags-region (beg end)
> - (save-excursion
> - (let ((output nil)
> - (last-line (line-number-at-pos end))
> - (max-line (- (line-number-at-pos (point-max)) 2)))
> - (goto-char beg)
> - (while (<= (line-number-at-pos) (min last-line max-line))
> - (setq output (append output (notmuch-search-get-tags)))
> - (forward-line 1))
> - output)))
> + (let (output)
> + (notmuch-search-do-results beg end pos
> + (setq output (append output (notmuch-search-get-tags pos))))
> + output))
>
> (defun notmuch-search-tag-region (beg end &optional tag-changes)
> "Change tags for threads in the given region."
> (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))
> (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))
> - (save-excursion
> - (let ((last-line (line-number-at-pos end))
> - (max-line (- (line-number-at-pos (point-max)) 2)))
> - (goto-char beg)
> - (while (<= (line-number-at-pos) (min last-line max-line))
> - (notmuch-search-set-tags
> - (notmuch-update-tags (notmuch-search-get-tags) tag-changes))
> - (forward-line))))))
> + (notmuch-search-do-results beg end pos
> + (notmuch-search-set-tags
> + (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)
> + pos))))
>
> (defun notmuch-search-tag (&optional tag-changes)
> "Change tags for the currently selected thread or region.
> --
> 1.7.10
next prev parent reply other threads:[~2012-07-14 21:15 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-13 0:45 [PATCH 0/7] emacs: JSON-based search cleanups Austin Clements
2012-07-13 0:45 ` [PATCH 1/7] emacs: Record thread search result object in a text property Austin Clements
2012-07-13 0:45 ` [PATCH 2/7] emacs: Use text properties instead of overlays for tag coloring Austin Clements
2012-07-13 17:59 ` Mark Walters
2012-07-13 18:43 ` Austin Clements
2012-07-13 0:45 ` [PATCH 3/7] emacs: Update tags by rewriting the search result line in place Austin Clements
2012-07-13 17:57 ` Mark Walters
2012-07-13 18:33 ` Austin Clements
2012-07-13 0:45 ` [PATCH 4/7] emacs: Use result text properties for search result iteration Austin Clements
2012-07-13 0:45 ` [PATCH 5/7] emacs: Replace other search text properties with result property Austin Clements
2012-07-13 0:45 ` [PATCH 6/7] emacs: Allow custom tags formatting Austin Clements
2012-07-13 0:45 ` [PATCH 7/7] emacs: Fix navigation of multi-line search result formats Austin Clements
2012-07-13 17:21 ` Mark Walters
2012-07-13 17:53 ` Austin Clements
2012-07-13 18:02 ` Mark Walters
2012-07-13 18:12 ` [PATCH 0/7] emacs: JSON-based search cleanups Mark Walters
2012-07-14 3:28 ` Austin Clements
2012-07-14 3:43 ` [PATCH v2 " Austin Clements
2012-07-14 3:43 ` [PATCH v2 1/7] emacs: Record thread search result object in a text property Austin Clements
2012-07-14 3:43 ` [PATCH v2 2/7] emacs: Use text properties instead of overlays for tag coloring Austin Clements
2012-07-14 3:43 ` [PATCH v2 3/7] emacs: Update tags by rewriting the search result line in place Austin Clements
2012-07-14 3:43 ` [PATCH v2 4/7] emacs: Use result text properties for search result iteration Austin Clements
2012-07-14 19:31 ` Jameson Graef Rollins
2012-07-14 19:35 ` Jameson Graef Rollins
2012-07-14 19:50 ` Austin Clements
2012-07-14 20:01 ` Austin Clements
2012-07-14 21:13 ` Jameson Graef Rollins
2012-07-14 21:51 ` Austin Clements
2012-07-14 23:02 ` Jameson Graef Rollins
2012-07-14 21:15 ` Mark Walters [this message]
2012-07-14 3:43 ` [PATCH v2 5/7] emacs: Replace other search text properties with result property Austin Clements
2012-07-14 3:43 ` [PATCH v2 6/7] emacs: Allow custom tags formatting Austin Clements
2012-07-14 3:43 ` [PATCH v2 7/7] emacs: Fix navigation of multi-line search result formats Austin Clements
2012-07-14 19:06 ` [PATCH v2 0/7] emacs: JSON-based search cleanups Jameson Graef Rollins
2012-07-14 23:02 ` [PATCH v3 0/8] " Austin Clements
2012-07-14 23:02 ` [PATCH v3 1/8] emacs: Record thread search result object in a text property Austin Clements
2012-07-14 23:02 ` [PATCH v3 2/8] emacs: Use text properties instead of overlays for tag coloring Austin Clements
2012-07-14 23:02 ` [PATCH v3 3/8] emacs: Update tags by rewriting the search result line in place Austin Clements
2012-07-14 23:02 ` [PATCH v3 4/8] emacs: Use result text properties for search result iteration Austin Clements
2012-07-14 23:02 ` [PATCH v3 5/8] emacs: Replace other search text properties with result property Austin Clements
2012-07-14 23:02 ` [PATCH v3 6/8] emacs: Allow custom tags formatting Austin Clements
2012-07-14 23:02 ` [PATCH v3 7/8] emacs: Fix navigation of multi-line search result formats Austin Clements
2012-07-14 23:02 ` [PATCH v3 8/8] News for search cleanups Austin Clements
2012-07-15 8:34 ` [PATCH v3 0/8] emacs: JSON-based " Mark Walters
2012-07-15 21:14 ` Jameson Graef Rollins
2012-07-15 16:27 ` Mark Walters
2012-07-15 18:00 ` Austin Clements
2012-07-15 18:14 ` Mark Walters
2012-07-21 17:55 ` [PATCH v4] " 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=871ukexcwv.fsf@qmul.ac.uk \
--to=markwalters1009@gmail.com \
--cc=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).