unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/3] Removed variable notmuch-hello-search-pos
@ 2012-04-24 21:11 Tomi Ollila
  2012-04-24 21:11 ` [PATCH 2/3] Moved global defvar of notmuch-hello-target to function local Tomi Ollila
  2012-04-24 21:11 ` [PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority . target-pos) Tomi Ollila
  0 siblings, 2 replies; 3+ messages in thread
From: Tomi Ollila @ 2012-04-24 21:11 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

From: Tomi Ollila <too@iki.fi>

Variable 'notmuch-hello-search-pos' was used to locate cursor to
the search bar in case no other location where to put it was known.
(In case search bar is shown -- if not cursor will be at the end
of buffer). More generic & versatile way to locace cursor follows. 

---
 emacs/notmuch-hello.el |   11 +----------
 1 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 71d37b8..8ae0aca 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -154,11 +154,6 @@ International Bureau of Weights and Measures."
 (defvar notmuch-hello-url "http://notmuchmail.org"
   "The `notmuch' web site.")
 
-(defvar notmuch-hello-search-pos nil
-  "Position of search widget, if any.
-
-This should only be set by `notmuch-hello-insert-search'.")
-
 (defvar notmuch-hello-custom-section-options
   '((:filter (string :tag "Filter for each tag"))
     (:filter-count (string :tag "Different filter to generate message counts"))
@@ -589,7 +584,6 @@ Complete list of currently available key bindings:
 (defun notmuch-hello-insert-search ()
   "Insert a search widget."
   (widget-insert "Search: ")
-  (setq notmuch-hello-search-pos (point-marker))
   (widget-create 'editable-field
 		 ;; Leave some space at the start and end of the
 		 ;; search boxes.
@@ -807,11 +801,8 @@ following:
       (when final-target-pos
 	(goto-char final-target-pos)
 	(unless (widget-at)
-	  (widget-forward 1)))
+	  (widget-forward 1)))))
 
-      (unless (widget-at)
-	(when notmuch-hello-search-pos
-	  (goto-char notmuch-hello-search-pos)))))
   (run-hooks 'notmuch-hello-refresh-hook)
   (setq notmuch-hello-first-run nil))
 
-- 
1.7.7.6

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

* [PATCH 2/3] Moved global defvar of notmuch-hello-target to function local
  2012-04-24 21:11 [PATCH 1/3] Removed variable notmuch-hello-search-pos Tomi Ollila
@ 2012-04-24 21:11 ` Tomi Ollila
  2012-04-24 21:11 ` [PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority . target-pos) Tomi Ollila
  1 sibling, 0 replies; 3+ messages in thread
From: Tomi Ollila @ 2012-04-24 21:11 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

From: Tomi Ollila <too@iki.fi>

The global defvar notmuch-hello-target was used to silence compiler
'free variable' warning. Actually the variable (when used) was always
defined in (let...), shadowing the global in when dynamically scoped.
"Moving" the defvar in function (possibly functions in future) where it
is referenced is somewhat cleaner solution.

---
 emacs/notmuch-hello.el |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 8ae0aca..c2cda19 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -235,14 +235,6 @@ supported for \"Customized queries section\" items."
 	    notmuch-hello-query-section
 	    (function :tag "Custom section"))))
 
-(defvar notmuch-hello-target nil
-  "Button text at position of point before rebuilding the notmuch-buffer.
-
-This variable contains the text of the button, if any, the
-point was positioned at before the notmuch-hello buffer was
-rebuilt. This should never actually be global and is defined as a
-defvar only for documentation purposes and to avoid a compiler
-warning about it occurring as a free variable.")
 
 (defvar notmuch-hello-hidden-sections nil
   "List of sections titles whose contents are hidden")
@@ -421,6 +413,7 @@ SEARCHES must be a list containing lists of the form (NAME QUERY COUNT), where
 QUERY is the query to start when the button for the corresponding entry is
 activated. COUNT should be the number of messages matching the query.
 Such a list can be computed with `notmuch-hello-query-counts'."
+  (defvar notmuch-hello-target) ;; dynamically bound in call path (or nil)
   (let* ((widest (notmuch-hello-longest-label searches))
 	 (tags-and-width (notmuch-hello-tags-per-line widest))
 	 (tags-per-line (car tags-and-width))
-- 
1.7.7.6

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

* [PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority . target-pos)
  2012-04-24 21:11 [PATCH 1/3] Removed variable notmuch-hello-search-pos Tomi Ollila
  2012-04-24 21:11 ` [PATCH 2/3] Moved global defvar of notmuch-hello-target to function local Tomi Ollila
@ 2012-04-24 21:11 ` Tomi Ollila
  1 sibling, 0 replies; 3+ messages in thread
From: Tomi Ollila @ 2012-04-24 21:11 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

From: Tomi Ollila <too@iki.fi>

In order to figure out cursor position on notmuch-hello buffer, whatever
sections there are inserted, a following method is introduced:

While inserting sections, notmuch-hello () holds up 2 variables;
final-target-pos-pri and final-target-pos, initial values -1 and 0,
respectively.
In case the insert function in question returns cons cell and the
car is integer and it's value creater than final-target-pos-pri --
and cdr is integer or marker, final-target-pos is updated to 
this (cdr) value (and final-target-pos-pri is updated to car value).

Pre-defined priority values are thought as:

'notmuch-hello-insert-header' & 'notmuch-hello-insert-footer' use 0
by default (in case these have no spesific reason to promote themselves)
All other sections uses 1 by default.
In case any of these sections know (for some reason) cursor should be
positioned inside their sections these use 2.
In case these definitely know the cursor should be positioned inside
their section (over some known widget (same that cursor was over before
reresh)) these use priority value of 10.

This patch just converts 'notmuch-hello-insert-saved-searches' to use
this scheme -- as it previously  was the only one updating
'notmuch-hello-target'.
---

This change is pretty simple; If this scheme is generally accepted
I'll complete the work; Either just as planned above or with chances
acquired by constructive discussion.

I'm currently using this -- works good when cursor is over 
saved-searches section; Otherwise cursor jumps over [inbox] widget
(which us currenly first (second) in saved-search section. This
is expected behaviour until all sections are converted.

 emacs/notmuch-hello.el |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index c2cda19..2fdce03 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -204,11 +204,10 @@ function produces a section simply by adding content to the current
 buffer.  A section should not end with an empty line, because a
 newline will be inserted after each section by `notmuch-hello'.
 
-Each function should take no arguments.  If the produced section
-includes `notmuch-hello-target' (i.e. cursor should be positioned
-inside this section), the function should return this element's
-position.
-Otherwise, it should return nil.
+Each function should take no arguments. The return value should
+either be nil, or a cons cell containing priority value and a
+suggested cursor position inside this section. Finally cursor will be
+positioned to a position which had highest priority value.
 
 For convenience an element can also be a list of the form (FUNC ARG1
 ARG2 .. ARGN) in which case FUNC will be applied to the rest of the
@@ -568,9 +567,11 @@ Complete list of currently available key bindings:
 			       (customize-variable 'notmuch-saved-searches))
 		     "edit")
       (widget-insert "\n\n")
-      (let ((start (point)))
-	(setq found-target-pos
-	      (notmuch-hello-insert-buttons searches))
+      (setq found-target-pos (cons 1 (point)))
+      (let ((start (point))
+	    (target-pos (notmuch-hello-insert-buttons searches)))
+	(if target-pos
+	    (setq found-target-pos (cons 10 target-pos)))
 	(indent-rigidly start (point) notmuch-hello-indent)
 	found-target-pos))))
 
@@ -775,15 +776,18 @@ following:
       (mapc 'delete-overlay (car all))
       (mapc 'delete-overlay (cdr all)))
 
-    (let (final-target-pos)
+    (let ((final-target-pos 0) (final-target-pos-pri -1))
       (mapc
        (lambda (section)
 	 (let ((point-before (point))
 	       (result (if (functionp section)
 			   (funcall section)
 			 (apply (car section) (cdr section)))))
-	   (if (and (not final-target-pos) (integer-or-marker-p result))
-	       (setq final-target-pos result))
+	   (if (and (integerp (car-safe result))
+		    (> (car result) final-target-pos-pri)
+		    (integer-or-marker-p (cdr-safe result)))
+	       (setq final-target-pos (cdr result)
+		     final-target-pos-pri (car result)))
 	   ;; don't insert a newline when the previous section didn't show
 	   ;; anything.
 	   (unless (eq (point) point-before)
-- 
1.7.7.6

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

end of thread, other threads:[~2012-04-24 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-24 21:11 [PATCH 1/3] Removed variable notmuch-hello-search-pos Tomi Ollila
2012-04-24 21:11 ` [PATCH 2/3] Moved global defvar of notmuch-hello-target to function local Tomi Ollila
2012-04-24 21:11 ` [PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority . target-pos) Tomi Ollila

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