From 5516ab1b50235a9ad29a5e76f0b7ddd48414588d Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Wed, 25 Apr 2012 00:11:10 +0300 Subject: [PATCH] [PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority . target-pos) --- 17/6460384fda6c7d17a4ba61678dc05581ac30f5 | 146 ++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 17/6460384fda6c7d17a4ba61678dc05581ac30f5 diff --git a/17/6460384fda6c7d17a4ba61678dc05581ac30f5 b/17/6460384fda6c7d17a4ba61678dc05581ac30f5 new file mode 100644 index 000000000..a746880a7 --- /dev/null +++ b/17/6460384fda6c7d17a4ba61678dc05581ac30f5 @@ -0,0 +1,146 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id F3D69431FAE + for ; Tue, 24 Apr 2012 14:11:18 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id aLC4oUfjwofD for ; + Tue, 24 Apr 2012 14:11:18 -0700 (PDT) +Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66]) + by olra.theworths.org (Postfix) with ESMTP id 89266431FAF + for ; Tue, 24 Apr 2012 14:11:17 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 2862A68058; Wed, 25 Apr 2012 00:11:13 +0300 (EEST) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [PATCH 3/3] Make notmuch-hello-insert-saved-searches return (priority + . target-pos) +Date: Wed, 25 Apr 2012 00:11:10 +0300 +Message-Id: <1335301870-11572-3-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 1.7.6.1 +In-Reply-To: <1335301870-11572-1-git-send-email-tomi.ollila@iki.fi> +References: <1335301870-11572-1-git-send-email-tomi.ollila@iki.fi> +Cc: Tomi Ollila +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 24 Apr 2012 21:11:19 -0000 + +From: Tomi Ollila + +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 + -- 2.26.2