[PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority . target-pos)
authorTomi Ollila <tomi.ollila@iki.fi>
Tue, 24 Apr 2012 21:11:10 +0000 (00:11 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:42 +0000 (09:46 -0800)
17/6460384fda6c7d17a4ba61678dc05581ac30f5 [new file with mode: 0644]

diff --git a/17/6460384fda6c7d17a4ba61678dc05581ac30f5 b/17/6460384fda6c7d17a4ba61678dc05581ac30f5
new file mode 100644 (file)
index 0000000..a746880
--- /dev/null
@@ -0,0 +1,146 @@
+Return-Path: <too@guru.guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id F3D69431FAE\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Apr 2012 14:11:18 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id aLC4oUfjwofD for <notmuch@notmuchmail.org>;\r
+       Tue, 24 Apr 2012 14:11:18 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66])\r
+       by olra.theworths.org (Postfix) with ESMTP id 89266431FAF\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Apr 2012 14:11:17 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+       id 2862A68058; Wed, 25 Apr 2012 00:11:13 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority\r
+       . target-pos)\r
+Date: Wed, 25 Apr 2012 00:11:10 +0300\r
+Message-Id: <1335301870-11572-3-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 1.7.6.1\r
+In-Reply-To: <1335301870-11572-1-git-send-email-tomi.ollila@iki.fi>\r
+References: <1335301870-11572-1-git-send-email-tomi.ollila@iki.fi>\r
+Cc: Tomi Ollila <too@iki.fi>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 24 Apr 2012 21:11:19 -0000\r
+\r
+From: Tomi Ollila <too@iki.fi>\r
+\r
+In order to figure out cursor position on notmuch-hello buffer, whatever\r
+sections there are inserted, a following method is introduced:\r
+\r
+While inserting sections, notmuch-hello () holds up 2 variables;\r
+final-target-pos-pri and final-target-pos, initial values -1 and 0,\r
+respectively.\r
+In case the insert function in question returns cons cell and the\r
+car is integer and it's value creater than final-target-pos-pri --\r
+and cdr is integer or marker, final-target-pos is updated to \r
+this (cdr) value (and final-target-pos-pri is updated to car value).\r
+\r
+Pre-defined priority values are thought as:\r
+\r
+'notmuch-hello-insert-header' & 'notmuch-hello-insert-footer' use 0\r
+by default (in case these have no spesific reason to promote themselves)\r
+All other sections uses 1 by default.\r
+In case any of these sections know (for some reason) cursor should be\r
+positioned inside their sections these use 2.\r
+In case these definitely know the cursor should be positioned inside\r
+their section (over some known widget (same that cursor was over before\r
+reresh)) these use priority value of 10.\r
+\r
+This patch just converts 'notmuch-hello-insert-saved-searches' to use\r
+this scheme -- as it previously  was the only one updating\r
+'notmuch-hello-target'.\r
+---\r
+\r
+This change is pretty simple; If this scheme is generally accepted\r
+I'll complete the work; Either just as planned above or with chances\r
+acquired by constructive discussion.\r
+\r
+I'm currently using this -- works good when cursor is over \r
+saved-searches section; Otherwise cursor jumps over [inbox] widget\r
+(which us currenly first (second) in saved-search section. This\r
+is expected behaviour until all sections are converted.\r
+\r
+ emacs/notmuch-hello.el |   26 +++++++++++++++-----------\r
+ 1 files changed, 15 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index c2cda19..2fdce03 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -204,11 +204,10 @@ function produces a section simply by adding content to the current\r
+ buffer.  A section should not end with an empty line, because a\r
+ newline will be inserted after each section by `notmuch-hello'.\r
\r
+-Each function should take no arguments.  If the produced section\r
+-includes `notmuch-hello-target' (i.e. cursor should be positioned\r
+-inside this section), the function should return this element's\r
+-position.\r
+-Otherwise, it should return nil.\r
++Each function should take no arguments. The return value should\r
++either be nil, or a cons cell containing priority value and a\r
++suggested cursor position inside this section. Finally cursor will be\r
++positioned to a position which had highest priority value.\r
\r
+ For convenience an element can also be a list of the form (FUNC ARG1\r
+ ARG2 .. ARGN) in which case FUNC will be applied to the rest of the\r
+@@ -568,9 +567,11 @@ Complete list of currently available key bindings:\r
+                              (customize-variable 'notmuch-saved-searches))\r
+                    "edit")\r
+       (widget-insert "\n\n")\r
+-      (let ((start (point)))\r
+-      (setq found-target-pos\r
+-            (notmuch-hello-insert-buttons searches))\r
++      (setq found-target-pos (cons 1 (point)))\r
++      (let ((start (point))\r
++          (target-pos (notmuch-hello-insert-buttons searches)))\r
++      (if target-pos\r
++          (setq found-target-pos (cons 10 target-pos)))\r
+       (indent-rigidly start (point) notmuch-hello-indent)\r
+       found-target-pos))))\r
\r
+@@ -775,15 +776,18 @@ following:\r
+       (mapc 'delete-overlay (car all))\r
+       (mapc 'delete-overlay (cdr all)))\r
\r
+-    (let (final-target-pos)\r
++    (let ((final-target-pos 0) (final-target-pos-pri -1))\r
+       (mapc\r
+        (lambda (section)\r
+        (let ((point-before (point))\r
+              (result (if (functionp section)\r
+                          (funcall section)\r
+                        (apply (car section) (cdr section)))))\r
+-         (if (and (not final-target-pos) (integer-or-marker-p result))\r
+-             (setq final-target-pos result))\r
++         (if (and (integerp (car-safe result))\r
++                  (> (car result) final-target-pos-pri)\r
++                  (integer-or-marker-p (cdr-safe result)))\r
++             (setq final-target-pos (cdr result)\r
++                   final-target-pos-pri (car result)))\r
+          ;; don't insert a newline when the previous section didn't show\r
+          ;; anything.\r
+          (unless (eq (point) point-before)\r
+-- \r
+1.7.7.6\r
+\r