From 35d428d1504f4a200433a23227905a7a02490c99 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Fri, 9 May 2014 01:20:08 +0100 Subject: [PATCH] [PATCH v4 2/2] emacs: show: add an update seen function to post-command-hook --- cc/6236bbe74f2355b61384fa6bd87afd3ad61f8b | 212 ++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 cc/6236bbe74f2355b61384fa6bd87afd3ad61f8b diff --git a/cc/6236bbe74f2355b61384fa6bd87afd3ad61f8b b/cc/6236bbe74f2355b61384fa6bd87afd3ad61f8b new file mode 100644 index 000000000..2d63f0a5a --- /dev/null +++ b/cc/6236bbe74f2355b61384fa6bd87afd3ad61f8b @@ -0,0 +1,212 @@ +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 192A3431FBF + for ; Thu, 8 May 2014 17:20:28 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7] 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 D2Fo8i94+dD7 for ; + Thu, 8 May 2014 17:20:24 -0700 (PDT) +Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com + [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 0A03B431FC0 + for ; Thu, 8 May 2014 17:20:23 -0700 (PDT) +Received: by mail-wi0-f169.google.com with SMTP id hi2so1775839wib.0 + for ; Thu, 08 May 2014 17:20:22 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:in-reply-to:references; + bh=vluGkX3vL5l6nusE434lNUa06J/f/OoNW38OHt2K/Us=; + b=dDrJZlBrsuaxV5cE9vwt6TsYGnhxW9csHXYqfJaPaT/waxqPJgoD3QC4qZqiVAR0Q9 + xpPiqi2LOjhc5/G2RUZvf4OY35nUUNayXwpHT/dlmdiqwXSbwIcTs1BM/0U5z/NEv6Vh + 4k5GoWCL7Rob9baVpDgKeGGIAHtd/jDSo0Gs5MLLfrkWqs8rjGiZ4Th03iey1+kO95VB + WiqJZcDDQd51hee3BCn90YdcYR+S0bAvpCy9e9YcFzpR1ClBURmhrML9y9ywR/K9h+9i + hHNkrooqs1qXL7PYpSM+m5mp+pH0s7nC7HNKI0Rrs636ZdKTeONQOP3tOTes3Fq5yTlO + 8aDw== +X-Received: by 10.194.80.7 with SMTP id n7mr5688320wjx.8.1399594822949; + Thu, 08 May 2014 17:20:22 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id iy13sm2048708wic.1.2014.05.08.17.20.22 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Thu, 08 May 2014 17:20:22 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH v4 2/2] emacs: show: add an update seen function to + post-command-hook +Date: Fri, 9 May 2014 01:20:08 +0100 +Message-Id: <1399594808-2815-3-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1399594808-2815-1-git-send-email-markwalters1009@gmail.com> +References: <1399594808-2815-1-git-send-email-markwalters1009@gmail.com> +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: Fri, 09 May 2014 00:20:28 -0000 + +Add a function for updating seen messages to the +post-command-hook. This function calls a customizable (by eg +defcustom) function with parameters the start and end of the current +window and that function can decide what to mark read based on that +and the current point. + +Since this is in the post-command-hook it should get called after most +user actions (exceptions include user resizing the window) so it +should be possible to make sure the seen status gets updated whether +the user uses notmuch commands like next-message or normal emacs +commands like scroll-up. + +It removes all of the old mark read/seen points but introduces a +simple example function that just marks the current message read if it +is open. This function has one small subtlety: it makes sure it +doesn't mark the same message read twice (in the same instance of the +same buffer); otherwise the post-command-hook makes it impossible for +a user to manually mark a message unread. + +This fixes the current bugs (imo) that closed messages can be marked +read, and that opening a closed message does not mark it read. + +Another advantage of using the post-command-hook any programmatic use +with point passing through a message will not mark it read. +--- + emacs/notmuch-show.el | 43 ++++++++++++++++++++++++++++--------------- + 1 file changed, 28 insertions(+), 15 deletions(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 10fc872..2620f84 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -222,6 +222,10 @@ (defcustom notmuch-show-mark-read-tags '("-unread") + :type '(repeat string) + :group 'notmuch-show) + ++(defcustom notmuch-show-mark-read-function #'notmuch-show-seen-current-message ++ "Function to control which messages are marked read." ++ :type 'function ++ :group 'notmuch-show) + + (defmacro with-current-notmuch-show-message (&rest body) + "Evaluate body with current buffer set to the text of current message" +@@ -1156,6 +1160,8 @@ (defun notmuch-show-build-buffer () + (let ((inhibit-read-only t)) + + (notmuch-show-mode) ++ (add-hook 'post-command-hook #'notmuch-show-command-hook nil t) ++ + ;; Don't track undo information for this buffer + (set 'buffer-undo-list t) + +@@ -1544,6 +1550,23 @@ (defun notmuch-show-mark-read (&optional unread) + (apply 'notmuch-show-tag-message + (notmuch-tag-change-list notmuch-show-mark-read-tags unread)))) + ++(defun notmuch-show-seen-current-message (start end) ++ "Mark the current message read if it is open. ++ ++We only mark it read once: if it is changed back then that is a ++user decision and we should not override it." ++ (when (and (notmuch-show-message-visible-p) ++ (not (notmuch-show-get-prop :seen))) ++ (notmuch-show-mark-read) ++ (notmuch-show-set-prop :seen t))) ++ ++(defun notmuch-show-command-hook () ++ (when (eq major-mode 'notmuch-show-mode) ++ ;; We need to redisplay to get window-start and window-end correct. ++ (redisplay) ++ (save-excursion ++ (funcall notmuch-show-mark-read-function (window-start) (window-end))))) ++ + ;; Functions for getting attributes of several messages in the current + ;; thread. + +@@ -1679,9 +1702,7 @@ (defun notmuch-show-next-message (&optional pop-at-end) + thread, navigate to the next thread in the parent search buffer." + (interactive "P") + (if (notmuch-show-goto-message-next) +- (progn +- (notmuch-show-mark-read) +- (notmuch-show-message-adjust)) ++ (notmuch-show-message-adjust) + (if pop-at-end + (notmuch-show-next-thread) + (goto-char (point-max))))) +@@ -1692,7 +1713,6 @@ (defun notmuch-show-previous-message () + (if (= (point) (notmuch-show-message-top)) + (notmuch-show-goto-message-previous) + (notmuch-show-move-to-message-top)) +- (notmuch-show-mark-read) + (notmuch-show-message-adjust)) + + (defun notmuch-show-next-open-message (&optional pop-at-end) +@@ -1707,9 +1727,7 @@ (defun notmuch-show-next-open-message (&optional pop-at-end) + (while (and (setq r (notmuch-show-goto-message-next)) + (not (notmuch-show-message-visible-p)))) + (if r +- (progn +- (notmuch-show-mark-read) +- (notmuch-show-message-adjust)) ++ (notmuch-show-message-adjust) + (if pop-at-end + (notmuch-show-next-thread) + (goto-char (point-max)))) +@@ -1722,9 +1740,7 @@ (defun notmuch-show-next-matching-message () + (while (and (setq r (notmuch-show-goto-message-next)) + (not (notmuch-show-get-prop :match)))) + (if r +- (progn +- (notmuch-show-mark-read) +- (notmuch-show-message-adjust)) ++ (notmuch-show-message-adjust) + (goto-char (point-max))))) + + (defun notmuch-show-open-if-matched () +@@ -1735,8 +1751,7 @@ (defun notmuch-show-open-if-matched () + (defun notmuch-show-goto-first-wanted-message () + "Move to the first open message and mark it read" + (goto-char (point-min)) +- (if (notmuch-show-message-visible-p) +- (notmuch-show-mark-read) ++ (unless (notmuch-show-message-visible-p) + (notmuch-show-next-open-message)) + (when (eobp) + ;; There are no matched non-excluded messages so open all matched +@@ -1744,8 +1759,7 @@ (defun notmuch-show-goto-first-wanted-message () + (notmuch-show-mapc 'notmuch-show-open-if-matched) + (force-window-update) + (goto-char (point-min)) +- (if (notmuch-show-message-visible-p) +- (notmuch-show-mark-read) ++ (unless (notmuch-show-message-visible-p) + (notmuch-show-next-open-message)))) + + (defun notmuch-show-previous-open-message () +@@ -1755,7 +1769,6 @@ (defun notmuch-show-previous-open-message () + (notmuch-show-goto-message-previous) + (notmuch-show-move-to-message-top)) + (not (notmuch-show-message-visible-p)))) +- (notmuch-show-mark-read) + (notmuch-show-message-adjust)) + + (defun notmuch-show-view-raw-message () +-- +1.7.10.4 + -- 2.26.2