[PATCH v4 0/8] emacs: JSON-based search cleanups

Mark Walters markwalters1009 at gmail.com
Sun Jul 22 08:27:53 PDT 2012


This version looks good to me +1

Best wishes

Mark

On Sat, 21 Jul 2012, Austin Clements <amdragon at MIT.EDU> wrote:
> This version fixes several bugs found in the previous version.  I
> replaced the insert-before-markers trick in
> notmuch-search-update-result with direct point manipulation.  This
> fixes the problem with authors getting unhidden when a result is
> updated with point after the authors on the line (since it no longer
> deletes the region with the invisibility overlay).  I also removed the
> scrolling hack (which was partially necessitated by
> insert-before-markers), so that archiving the last visible result will
> properly scroll the buffer instead of jumping point to the middle of
> the visible window.  As a result, the window may scroll when updating
> a multiline result, however, it will scroll to show the entire result
> (unlike an earlier version where it scrolled to cut off the result
> because of an interaction with insert-before-markers).  Finally, I
> fixed notmuch-search-last-thread so that it behaves like it did before
> when there are no results, rather than failing with an obscure error.
>
> I also updated the customize documentation and NEWS to indicate that
> multiline search results are considered experimental.
>
> Diff from v3:
>
> diff --git a/NEWS b/NEWS
> index 7b33f0d..7b1f36c 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -25,7 +25,7 @@ The formatting of tags in search results can now be customized
>    `notmuch-search-result-format` would usually break tagging from
>    search-mode.  We no longer make assumptions about the format.
>  
> -Multi-line search result formats are now supported
> +Experimental support for multi-line search result formats
>  
>    It is now possible to embed newlines in
>    `notmuch-search-result-format` to make individual search results
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index ec760dc..fd1836f 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -70,12 +70,12 @@
>  For example:
>  	(setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)
>  					     \(\"subject\" . \"%s\"\)\)\)
> -Line breaks are permitted in format strings.  Note that a line
> -break at the end of an \"authors\" field will get elided if the
> -authors list is long; place it instead at the beginning of the
> -following field.  To enter a line break when setting this
> -variable with setq, use \\n.  To enter a line break in customize,
> -press \\[quoted-insert] C-j."
> +Line breaks are permitted in format strings (though this is
> +currently experimental).  Note that a line break at the end of an
> +\"authors\" field will get elided if the authors list is long;
> +place it instead at the beginning of the following field.  To
> +enter a line break when setting this variable with setq, use \\n.
> +To enter a line break in customize, press \\[quoted-insert] C-j."
>    :type '(alist :key-type (string) :value-type (string))
>    :group 'notmuch-search)
>  
> @@ -310,7 +310,8 @@ For a mouse binding, return nil."
>    (interactive)
>    (goto-char (point-max))
>    (forward-line -2)
> -  (goto-char (notmuch-search-result-beginning)))
> +  (let ((beg (notmuch-search-result-beginning)))
> +    (when beg (goto-char beg))))
>  
>  (defun notmuch-search-first-thread ()
>    "Select the first thread in the search results."
> @@ -599,30 +600,31 @@ This function advances the next thread when finished."
>  
>  (defun notmuch-search-update-result (result &optional pos)
>    "Replace the result object of the thread at POS (or point) by
> -RESULT and redraw it."
> +RESULT and redraw it.
> +
> +This will keep point in a reasonable location.  However, if there
> +are enclosing save-excursions and the saved point is in the
> +result being updated, the point will be restored to the beginning
> +of the result."
>    (let ((start (notmuch-search-result-beginning pos))
>  	(end (notmuch-search-result-end pos))
>  	(init-point (point))
> -	(init-start (window-start))
>  	(inhibit-read-only t))
>      ;; Delete the current thread
>      (delete-region start end)
>      ;; Insert the updated thread
>      (notmuch-search-show-result result start)
> -    ;; There may have been markers pointing into the text we just
> -    ;; replaced.  For the most part, there's nothing we can do about
> -    ;; this, but we can fix markers that were at point (which includes
> -    ;; point itself and any save-excursions for which point hasn't
> -    ;; moved) by re-inserting the text that should come before point
> -    ;; before markers.
> +    ;; If point was inside the old result, make an educated guess
> +    ;; about where to place it now.  Unfortunately, this won't work
> +    ;; with save-excursion (or any other markers that would be nice to
> +    ;; preserve, such as the window start), but there's nothing we can
> +    ;; do about that without a way to retrieve markers in a region.
>      (when (and (>= init-point start) (<= init-point end))
>        (let* ((new-end (notmuch-search-result-end start))
>  	     (new-point (if (= init-point end)
>  			    new-end
>  			  (min init-point (- new-end 1)))))
> -	(insert-before-markers (delete-and-extract-region start new-point))))
> -    ;; We also may have shifted the window scroll.  Fix it.
> -    (set-window-start (selected-window) init-start)))
> +	(goto-char new-point)))))
>  
>  (defun notmuch-search-process-sentinel (proc msg)
>    "Add a message to let user know when \"notmuch search\" exits"


More information about the notmuch mailing list