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 857E7431FC0 for ; Wed, 16 Jul 2014 10:56:10 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.7 X-Spam-Level: ** X-Spam-Status: No, score=2.7 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, FREEMAIL_REPLY=2.499, 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 c9bSoQFTCfTv for ; Wed, 16 Jul 2014 10:56:05 -0700 (PDT) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D42E8431FBD for ; Wed, 16 Jul 2014 10:56:04 -0700 (PDT) Received: by mail-wi0-f180.google.com with SMTP id n3so1787077wiv.7 for ; Wed, 16 Jul 2014 10:56:02 -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; bh=T2Go5F+rzQh6l6ku5sDQfFV8eeO2ywGp+dnuq4ZVRjQ=; b=FIe6T/fuvbsFpT2Y0BTaY+gqNHI8jU6sLZ33hmvc+Q0lO5Orfv7V9uGCHIy5sfv5zW BgNEbz307W28OmmvTO2UF6mHRbSlcB56tKNIfrOEyrtGmiYVAZkSAH/7Bnbz8aVKPz0b m0GvGc5ilKnXjkMYlF05ochc44RjDU4+X/0UkpeyLL9aLn6O4S8Xl5YVbY1f8haheQw5 EC3+OHh2TiQ/Fco/rWY4RGNWU7idlBEe5vJ5kxT9b8+58C2l5SVZ1GFl/yBozSo+DlVf P9ow/uuK2WgFK93wgXqY4cv05mj9BBNX5wJ8NzaRgHJoAeK4LREorqxtraWukPJ5KbCi BgIw== X-Received: by 10.194.92.115 with SMTP id cl19mr38437606wjb.29.1405533362352; Wed, 16 Jul 2014 10:56:02 -0700 (PDT) Received: from localhost ([194.42.225.52]) by mx.google.com with ESMTPSA id hi2sm55656wjb.29.2014.07.16.10.56.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jul 2014 10:56:01 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] emacs: show: mark messages unread if seen in buffer Date: Wed, 16 Jul 2014 18:55:39 +0100 Message-Id: <1405533339-7666-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.10.4 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: Wed, 16 Jul 2014 17:56:10 -0000 This adds a function that marks messages unread if they are "seen" that is a user configurable amount of them has been visible in the buffer. --- This adds my preferred mark unread function as an option: see id:1399650320-1382-1-git-send-email-markwalters1009@gmail.com for a previous version. This version moves this functions configuration parameter inside the defcustom. I am not sure if this (using :set) is the best way to do that but it works and will work if other people want to add functions which have parameters too. Best wishes Mark emacs/notmuch-show.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 529baa9..9563a74 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -225,7 +225,29 @@ For example, if you wanted to remove an \"unread\" tag and add a (defcustom notmuch-show-mark-read-function #'notmuch-show-seen-current-message "Function to control which messages are marked read." - :type 'function + :type '(radio (const :format "%h" :doc "Mark current message read. + +Marks the message containing point read." + notmuch-show-seen-current-message) + (list :format "%v" + (const :tag "Mark read if enough of the message has been visible" notmuch-show-do-seen) + (number :format "%h %v" + :doc "Proportion or Lines needed + +A message is marked read if both the top of the message +and a point far \"enough\" down in the message have each been +visible in the buffer at some point. This parameter controls the +definition of enough. Seeing the bottom of message is always +deemed enough. Additionally, it is deemed enough if a point n +lines into the message has been visible in the window where n is +this variable if this variable is an integer and n is this +variable times the height of the window if this variable is a +float." + :value 0.75)) + (function)) + :set (lambda (symbol value) (if (listp value) + (set-default symbol (apply 'apply-partially (car value) (cdr value))) + (set-default symbol value))) :group 'notmuch-show) (defmacro with-current-notmuch-show-message (&rest body) @@ -1569,6 +1591,58 @@ marked as unread, i.e. the tag changes in (apply 'notmuch-show-tag-message (notmuch-tag-change-list notmuch-show-mark-read-tags unread)))) +(defun notmuch-show-update-seen (top-or-bottom) + "Update seen status of current message + +Mark that we have seen the TOP-OR-BOTTOM of current message." + (let ((current (notmuch-show-get-prop :seen))) + (unless (or (eq current 'both) (eq current top-or-bottom)) + (if (not current) + (notmuch-show-set-prop :seen top-or-bottom) + (notmuch-show-set-prop :seen 'both) + (notmuch-show-mark-read))))) + +(defun notmuch-show-do-message-seen (needed start end) + "Update seen status for the current message. + +A message is seen if both the top and enough of the rest of the +message have been visible in the buffer. Enough means either the +bottom of the message or a point in the message more than +LINES-NEEDED lines into the message. LINES-NEEDED is +NEEDED if NEEDED is an integer and NEEDED +times the current window height if NEEDED is a float." + (let* ((lines-needed (if (integerp needed) + needed + (truncate (* needed (window-body-height))))) + (top (notmuch-show-message-top)) + (bottom (notmuch-show-message-bottom))) + (when (notmuch-show-message-visible-p) + (when (>= top start) + (notmuch-show-update-seen 'top)) + (when (or (<= bottom end) + (> (count-screen-lines top end) lines-needed)) + (notmuch-show-update-seen 'bottom))))) + +(defun notmuch-show-do-seen (needed start end) + "Update seen status for all messages between start and end. + +We mark the top (bottom) of a message seen if the top (enough of +the rest of the message) respectively have been visible in the +buffer. See `notmuch-show-do-message-seen` for the definition of +enough. When both the top and bottom have been seen we mark the +message read." + (save-excursion + (goto-char start) + (notmuch-show-do-message-seen needed start end) + (while (and (< (notmuch-show-message-bottom) end) + (notmuch-show-goto-message-next)) + (notmuch-show-do-message-seen needed start end)) + ;; This is a work around because emacs gives weird answers for + ;; window-end if the buffer ends with invisible text. + (when (and (pos-visible-in-window-p (point-max)) + (notmuch-show-message-visible-p)) + (notmuch-show-update-seen 'bottom)))) + (defun notmuch-show-seen-current-message (start end) "Mark the current message read if it is open. -- 1.7.10.4