unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/2] contrib: pick: allow target message
@ 2013-01-10 10:41 Mark Walters
  2013-01-10 10:41 ` [PATCH 1/2] contrib: pick: move save-excursion closer to message insertion Mark Walters
  2013-01-10 10:41 ` [PATCH 2/2] contrib: pick: add a target message for pick Mark Walters
  0 siblings, 2 replies; 5+ messages in thread
From: Mark Walters @ 2013-01-10 10:41 UTC (permalink / raw)
  To: notmuch

These two patches allow the caller of pick to specify a target message
that pick should jump to when it appears. This is used by refresh-view
(to keep the same current message) and by the entry from show
(notmuch-pick-from-show-current-thread).

It would be easy to add functionality so that, if no target-message is
specified, pick goes to the first matching message.

In the future this should be used to remove the horrible hack in
notmuch-pick-show-match-message-with-wait.

Best wishes

Mark



Mark Walters (2):
  contrib: pick: move save-excursion closer to message insertion
  contrib: pick: add a target message for pick

 contrib/notmuch-pick/notmuch-pick.el |   43 ++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 12 deletions(-)

-- 
1.7.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] contrib: pick: move save-excursion closer to message insertion
  2013-01-10 10:41 [PATCH 0/2] contrib: pick: allow target message Mark Walters
@ 2013-01-10 10:41 ` Mark Walters
  2013-05-20 18:04   ` David Bremner
  2013-01-10 10:41 ` [PATCH 2/2] contrib: pick: add a target message for pick Mark Walters
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Walters @ 2013-01-10 10:41 UTC (permalink / raw)
  To: notmuch

Pick keeps point roughly at the top of the buffer while inserting
messages at the end as they come in (from the async
parser). Previously the save-excursion to do this was done once for
each thread inserted: now it is done for each individual message.

The advantage is that the message insertion code can decide where to
leave point. In the next patch point will be left on the target message.

Note notmuch-pick-insert-msg is unchanged as that is used by the tag
display update code.
---
 contrib/notmuch-pick/notmuch-pick.el |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/contrib/notmuch-pick/notmuch-pick.el b/contrib/notmuch-pick/notmuch-pick.el
index d75a66a..d597126 100644
--- a/contrib/notmuch-pick/notmuch-pick.el
+++ b/contrib/notmuch-pick/notmuch-pick.el
@@ -638,6 +638,11 @@ unchanged ADDRESS if parsing fails."
   (notmuch-pick-set-message-properties msg)
   (insert "\n"))
 
+(defun notmuch-pick-goto-and-insert-msg (msg)
+  "Insert msg at the end of the buffer."
+  (save-excursion
+    (goto-char (point-max))
+    (notmuch-pick-insert-msg msg)))
 (defun notmuch-pick-insert-tree (tree depth tree-status first last)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
@@ -659,7 +664,7 @@ unchanged ADDRESS if parsing fails."
 	(push "├" tree-status)))
 
       (push (concat (if replies "┬" "─") "►") tree-status)
-      (notmuch-pick-insert-msg (plist-put msg :tree-status tree-status))
+      (notmuch-pick-goto-and-insert-msg (plist-put msg :tree-status tree-status))
       (pop tree-status)
       (pop tree-status)
 
@@ -678,12 +683,10 @@ unchanged ADDRESS if parsing fails."
 	  do (notmuch-pick-insert-tree tree depth tree-status (eq count 1) (eq count n)))))
 
 (defun notmuch-pick-insert-forest-thread (forest-thread)
-  (save-excursion
-    (goto-char (point-max))
-    (let (tree-status)
-      ;; Reset at the start of each main thread.
-      (setq notmuch-pick-previous-subject nil)
-      (notmuch-pick-insert-thread forest-thread 0 tree-status))))
+  (let (tree-status)
+    ;; Reset at the start of each main thread.
+    (setq notmuch-pick-previous-subject nil)
+    (notmuch-pick-insert-thread forest-thread 0 tree-status)))
 
 (defun notmuch-pick-insert-forest (forest)
   (mapc 'notmuch-pick-insert-forest-thread forest))
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] contrib: pick: add a target message for pick
  2013-01-10 10:41 [PATCH 0/2] contrib: pick: allow target message Mark Walters
  2013-01-10 10:41 ` [PATCH 1/2] contrib: pick: move save-excursion closer to message insertion Mark Walters
@ 2013-01-10 10:41 ` Mark Walters
  2013-01-10 11:14   ` [PATCH (corrected)] " Mark Walters
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Walters @ 2013-01-10 10:41 UTC (permalink / raw)
  To: notmuch

This adds a target message for pick which it will jump to when (if) it
appears. It adds the target to notmuch-pick-from-show-current-query so
that pick goes straight to the message that was current in the show
view and it adds target to notmuch-pick-refresh-view so that the
current message is preserved.
---
 contrib/notmuch-pick/notmuch-pick.el |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/contrib/notmuch-pick/notmuch-pick.el b/contrib/notmuch-pick/notmuch-pick.el
index d597126..974223d 100644
--- a/contrib/notmuch-pick/notmuch-pick.el
+++ b/contrib/notmuch-pick/notmuch-pick.el
@@ -155,6 +155,8 @@
 ;; The context of the search: i.e., useful but can be dropped.
 (defvar notmuch-pick-query-context nil)
 (make-variable-buffer-local 'notmuch-pick-query-context)
+(defvar notmuch-pick-target-msg nil)
+(make-variable-buffer-local 'notmuch-pick-target-msg)
 (defvar notmuch-pick-buffer-name nil)
 (make-variable-buffer-local 'notmuch-pick-buffer-name)
 ;; This variable is the window used for the message pane. It is set
@@ -328,7 +330,9 @@ Does NOT change the database."
 (defun notmuch-pick-from-show-current-query ()
   "Call notmuch pick with the current query"
   (interactive)
-  (notmuch-pick notmuch-show-thread-id notmuch-show-query-context))
+  (notmuch-pick notmuch-show-thread-id
+		notmuch-show-query-context
+		(notmuch-show-get-message-id)))
 
 ;; This function should be in notmuch.el but be we trying to minimise
 ;; impact on the rest of the codebase.
@@ -344,6 +348,7 @@ Does NOT change the database."
   (interactive)
   (notmuch-pick (notmuch-search-find-thread-id)
                 notmuch-search-query-string
+		nil
                 (notmuch-prettify-subject (notmuch-search-find-subject)))
   (notmuch-pick-show-match-message-with-wait))
 
@@ -506,9 +511,13 @@ will be reversed."
   (let ((inhibit-read-only t)
 	(basic-query notmuch-pick-basic-query)
 	(query-context notmuch-pick-query-context)
+	(target (notmuch-pick-get-message-id))
 	(buffer-name notmuch-pick-buffer-name))
     (erase-buffer)
-    (notmuch-pick-worker basic-query query-context (get-buffer buffer-name))))
+    (notmuch-pick-worker basic-query
+			 query-context
+			 target
+			 (get-buffer buffer-name))))
 
 (defmacro with-current-notmuch-pick-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
@@ -639,10 +648,16 @@ unchanged ADDRESS if parsing fails."
   (insert "\n"))
 
 (defun notmuch-pick-goto-and-insert-msg (msg)
-  "Insert msg at the end of the buffer."
+  "Insert msg at the end of the buffer. Move point to msg if it is the target"
   (save-excursion
     (goto-char (point-max))
     (notmuch-pick-insert-msg msg)))
+  (let ((msg-id (notmuch-id-to-query (plist-get msg :id))))
+    (when (string= msg-id notmuch-pick-target-msg)
+      (setq notmuch-pick-target-msg "found")
+      (goto-char (point-max))
+      (forward-line -1))))
+
 (defun notmuch-pick-insert-tree (tree depth tree-status first last)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
@@ -762,12 +777,13 @@ Complete list of currently available key bindings:
 					 'notmuch-pick-show-error
 					 results-buf)))))
 
-(defun notmuch-pick-worker (basic-query &optional query-context buffer)
+(defun notmuch-pick-worker (basic-query &optional query-context target buffer)
   (interactive)
   (notmuch-pick-mode)
   (setq notmuch-pick-basic-query basic-query)
   (setq notmuch-pick-query-context query-context)
   (setq notmuch-pick-buffer-name (buffer-name buffer))
+  (setq notmuch-pick-target-msg target)
 
   (erase-buffer)
   (goto-char (point-min))
@@ -799,7 +815,7 @@ Complete list of currently available key bindings:
 	  (insert "End of search results.\n"))))))
 
 
-(defun notmuch-pick (&optional query query-context buffer-name show-first-match)
+(defun notmuch-pick (&optional query query-context target buffer-name show-first-match)
   "Run notmuch pick with the given `query' and display the results"
   (interactive "sNotmuch pick: ")
   (if (null query)
@@ -813,7 +829,7 @@ Complete list of currently available key bindings:
     ;; Don't track undo information for this buffer
     (set 'buffer-undo-list t)
 
-    (notmuch-pick-worker query query-context buffer)
+    (notmuch-pick-worker query query-context target buffer)
 
     (setq truncate-lines t)
     (when show-first-match
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH (corrected)] contrib: pick: add a target message for pick
  2013-01-10 10:41 ` [PATCH 2/2] contrib: pick: add a target message for pick Mark Walters
@ 2013-01-10 11:14   ` Mark Walters
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2013-01-10 11:14 UTC (permalink / raw)
  To: notmuch

This adds a target message for pick which it will jump to when (if) it
appears. It adds the target to notmuch-pick-from-show-current-query so
that pick goes straight to the message that was current in the show
view and it adds target to notmuch-pick-refresh-view so that the
current message is preserved.
---
The previous version had an extra ). The version I was testing had the
fix but git didn't; oh well.

Best wishes

Mark



 contrib/notmuch-pick/notmuch-pick.el |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/contrib/notmuch-pick/notmuch-pick.el b/contrib/notmuch-pick/notmuch-pick.el
index d597126..128fabf 100644
--- a/contrib/notmuch-pick/notmuch-pick.el
+++ b/contrib/notmuch-pick/notmuch-pick.el
@@ -155,6 +155,8 @@
 ;; The context of the search: i.e., useful but can be dropped.
 (defvar notmuch-pick-query-context nil)
 (make-variable-buffer-local 'notmuch-pick-query-context)
+(defvar notmuch-pick-target-msg nil)
+(make-variable-buffer-local 'notmuch-pick-target-msg)
 (defvar notmuch-pick-buffer-name nil)
 (make-variable-buffer-local 'notmuch-pick-buffer-name)
 ;; This variable is the window used for the message pane. It is set
@@ -328,7 +330,9 @@ Does NOT change the database."
 (defun notmuch-pick-from-show-current-query ()
   "Call notmuch pick with the current query"
   (interactive)
-  (notmuch-pick notmuch-show-thread-id notmuch-show-query-context))
+  (notmuch-pick notmuch-show-thread-id
+		notmuch-show-query-context
+		(notmuch-show-get-message-id)))
 
 ;; This function should be in notmuch.el but be we trying to minimise
 ;; impact on the rest of the codebase.
@@ -344,6 +348,7 @@ Does NOT change the database."
   (interactive)
   (notmuch-pick (notmuch-search-find-thread-id)
                 notmuch-search-query-string
+		nil
                 (notmuch-prettify-subject (notmuch-search-find-subject)))
   (notmuch-pick-show-match-message-with-wait))
 
@@ -506,9 +511,13 @@ will be reversed."
   (let ((inhibit-read-only t)
 	(basic-query notmuch-pick-basic-query)
 	(query-context notmuch-pick-query-context)
+	(target (notmuch-pick-get-message-id))
 	(buffer-name notmuch-pick-buffer-name))
     (erase-buffer)
-    (notmuch-pick-worker basic-query query-context (get-buffer buffer-name))))
+    (notmuch-pick-worker basic-query
+			 query-context
+			 target
+			 (get-buffer buffer-name))))
 
 (defmacro with-current-notmuch-pick-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
@@ -639,10 +648,16 @@ unchanged ADDRESS if parsing fails."
   (insert "\n"))
 
 (defun notmuch-pick-goto-and-insert-msg (msg)
-  "Insert msg at the end of the buffer."
+  "Insert msg at the end of the buffer. Move point to msg if it is the target"
   (save-excursion
     (goto-char (point-max))
-    (notmuch-pick-insert-msg msg)))
+    (notmuch-pick-insert-msg msg))
+  (let ((msg-id (notmuch-id-to-query (plist-get msg :id))))
+    (when (string= msg-id notmuch-pick-target-msg)
+      (setq notmuch-pick-target-msg "found")
+      (goto-char (point-max))
+      (forward-line -1))))
+
 (defun notmuch-pick-insert-tree (tree depth tree-status first last)
   "Insert the message tree TREE at depth DEPTH in the current thread."
   (let ((msg (car tree))
@@ -762,12 +777,13 @@ Complete list of currently available key bindings:
 					 'notmuch-pick-show-error
 					 results-buf)))))
 
-(defun notmuch-pick-worker (basic-query &optional query-context buffer)
+(defun notmuch-pick-worker (basic-query &optional query-context target buffer)
   (interactive)
   (notmuch-pick-mode)
   (setq notmuch-pick-basic-query basic-query)
   (setq notmuch-pick-query-context query-context)
   (setq notmuch-pick-buffer-name (buffer-name buffer))
+  (setq notmuch-pick-target-msg target)
 
   (erase-buffer)
   (goto-char (point-min))
@@ -799,7 +815,7 @@ Complete list of currently available key bindings:
 	  (insert "End of search results.\n"))))))
 
 
-(defun notmuch-pick (&optional query query-context buffer-name show-first-match)
+(defun notmuch-pick (&optional query query-context target buffer-name show-first-match)
   "Run notmuch pick with the given `query' and display the results"
   (interactive "sNotmuch pick: ")
   (if (null query)
@@ -813,7 +829,7 @@ Complete list of currently available key bindings:
     ;; Don't track undo information for this buffer
     (set 'buffer-undo-list t)
 
-    (notmuch-pick-worker query query-context buffer)
+    (notmuch-pick-worker query query-context target buffer)
 
     (setq truncate-lines t)
     (when show-first-match
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] contrib: pick: move save-excursion closer to message insertion
  2013-01-10 10:41 ` [PATCH 1/2] contrib: pick: move save-excursion closer to message insertion Mark Walters
@ 2013-05-20 18:04   ` David Bremner
  0 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2013-05-20 18:04 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

> Pick keeps point roughly at the top of the buffer while inserting
> messages at the end as they come in (from the async
> parser). Previously the save-excursion to do this was done once for
> each thread inserted: now it is done for each individual message.

pushed this, and revised #2

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-05-20 18:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-10 10:41 [PATCH 0/2] contrib: pick: allow target message Mark Walters
2013-01-10 10:41 ` [PATCH 1/2] contrib: pick: move save-excursion closer to message insertion Mark Walters
2013-05-20 18:04   ` David Bremner
2013-01-10 10:41 ` [PATCH 2/2] contrib: pick: add a target message for pick Mark Walters
2013-01-10 11:14   ` [PATCH (corrected)] " Mark Walters

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).