From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id yNYkLcSjPmGrZAAAgWs5BA (envelope-from ) for ; Mon, 13 Sep 2021 03:05:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id gPLmKMSjPmHzdAAAB5/wlQ (envelope-from ) for ; Mon, 13 Sep 2021 01:05:08 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6778313328 for ; Mon, 13 Sep 2021 03:05:08 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id AD3491FC8B; Sun, 12 Sep 2021 21:05:04 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 1817D1FC15 for ; Sun, 12 Sep 2021 21:05:02 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 8588F5FD5C; Sun, 12 Sep 2021 21:05:01 -0400 (EDT) Received: (nullmailer pid 2211252 invoked by uid 1000); Mon, 13 Sep 2021 01:04:59 -0000 From: David Bremner To: Fabio Natali , notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH] emacs: run notmuch-search-hook lazily Date: Sun, 12 Sep 2021 22:03:50 -0300 Message-Id: <20210913010350.2211117-1-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: MIME-Version: 1.0 Message-ID-Hash: NMV4XRHIRTV7PZXFCEURAKCQTXZ2TID3 X-Message-ID-Hash: NMV4XRHIRTV7PZXFCEURAKCQTXZ2TID3 X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1631495108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=M+wIQ26dCltjh7cN3PJC1xA93AxQ/CJjpyqgioFXyS8=; b=JZ0rriGdAjs0Q4nZQhsPnVIhmCwyYyyUh0wSkq6VHoyVWRvRabsVvWKcorVEEPIvvEU7Vu xzoads+5P51v5KPkomwRXymy98WMayrnXpC1D/bANJUFFBhInHw/0rAKzrnNl/NEV+rncq 8SLd7FuQLN15d6J7XNd5MSM8tCUKRhC3YaQ3JpC14ZCL5kbVGZhoLzJOhBalsnyqvCLSEA E2Uh8vMA75NrkiTEIeTkG7D9Xw9vIiUwD/i2A/N6XIHkKfkR2Pvy996hFDiuuAu50KGSim RYiQ3kTVVX//bd3g9kHGtnI8jV/b3zxViTZEUp094NYpGZe29I5i/izRtZYFnw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1631495108; a=rsa-sha256; cv=none; b=MzDvPTrgG82blNzv41o3n8uhtoZRGXNV4skgcIij5UPzLlOwJatg1RWS3idFWtCKkVNAR8 Bh8tbHh1AqSBZObMpr7sVYP/j7fuLqLfeiO47bgVXeCdL7hcminjp3M54xtsxmQVH9m6Xz HKhkh7gxlqy3ZmzEu6fzlLr6tjjrQasHPRDs68vX/CkiBHxY5yIYUzZFvUXGfBg2vqfpXP POsYPX3nSDWsML+eZLD1Dly0v+ri/w3scex1Pw7Mlorb4EBevuq6xOX1LhwdfDoXlc6Ptm 48AHcwRlC2JtCL4wV2IQU4aKrLcIwIgzig0QGuJLj/FB89IsrLCEjEoZ/3iKVQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.13 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 6778313328 X-Spam-Score: -1.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: 3Jc7CPt40JFz In message id:YT3ueuZHKW931NW3@localhost, Fabio Natali isolated a visual glitch caused by running notmuch-search-hook too early. This change moves the running of that hook to notmuch-search-process-filter, which ensures there is some output in the buffer before running the hook. Since n-s-p-f can be called many times for a given buffer, add a buffer local flag to make sure it is only run once per buffer. --- emacs/notmuch.el | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 2ef67c0e..052f7578 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -880,6 +880,14 @@ sets the :orig-tag property." (setq notmuch-search-target-thread "found") (goto-char pos)))) +(defvar-local notmuch--search-hook-run nil + "Flag used to ensure the notmuch-search-hook is only run once per buffer") + +(defun notmuch--search-hook-wrapper () + (unless notmuch--search-hook-run + (setq notmuch--search-hook-run t) + (run-hooks 'notmuch-search-hook))) + (defun notmuch-search-process-filter (proc string) "Process and filter the output of \"notmuch search\"." (let ((results-buf (process-buffer proc)) @@ -892,7 +900,9 @@ sets the :orig-tag property." (goto-char (point-max)) (insert string)) (notmuch-sexp-parse-partial-list 'notmuch-search-append-result - results-buf))))) + results-buf)) + (with-current-buffer results-buf + (notmuch--search-hook-wrapper))))) ;;; Commands (and some helper functions used by them) @@ -1036,8 +1046,7 @@ the configured default sort order." (process-put proc 'parse-buf (generate-new-buffer " *notmuch search parse*")) (set-process-filter proc 'notmuch-search-process-filter) - (set-process-query-on-exit-flag proc nil)))) - (run-hooks 'notmuch-search-hook))) + (set-process-query-on-exit-flag proc nil)))))) (defun notmuch-search-refresh-view () "Refresh the current view. -- 2.33.0