From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id yNK5Nxx43GHriQAAgWs5BA (envelope-from ) for ; Mon, 10 Jan 2022 19:17:00 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id aBJfMBx43GHBEAEAG6o9tA (envelope-from ) for ; Mon, 10 Jan 2022 19:17:00 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (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 86C5E28950 for ; Mon, 10 Jan 2022 19:17:00 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 9152E5F742; Mon, 10 Jan 2022 18:16:56 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [209.51.188.92]) by mail.notmuchmail.org (Postfix) with ESMTPS id 78CBE5F732 for ; Mon, 10 Jan 2022 18:16:53 +0000 (UTC) Received: from [2001:470:142:3::e] (port=52992 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6zDv-0002gU-MX; Mon, 10 Jan 2022 13:16:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=cePlzfinv7KWCU82mfeSCT7+9DqA87IpLoj67sRQ0es=; b=q/V7a4UagT9oWg Y6kYIsEDBU19N/A8ZtjAMwOH6A9RPeHPC8OFyI7bd6YNyTfMSho0eI2tlAInyYu5nMV62ZB+h1NPH 4hQD7VV+p9fl1zQvMam1/ke6HVtF+4YtHnEAU+kXHRz+uq3ja6FWxikhgceC4cWyRZDczJjjsU/n6 0nnFfFyNyhLmq1tA0CSMLdLTbL0QMhYEQOO1Bhtldg8nKwLpqd0WZ6m9Z6upao8VwQ9SbeWCm5jnD zibAlGHoJhWu/GMb/Rj2d1yhJ+p1Ls0/XS1pAO/ZCnYUdbYhwyXp/MmqGTYo9ZtHp991Dmtf77IMW t0c4uSqiIEGwu8WlB7Mg==; Received: from 92.40.179.55.threembb.co.uk ([92.40.179.55]:15986 helo=rivendell.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6zDv-0000G0-KX; Mon, 10 Jan 2022 13:16:52 -0500 From: jao To: notmuch@notmuchmail.org Subject: [PATCH v4] emacs: customizable names for search buffers Date: Mon, 10 Jan 2022 18:16:44 +0000 Message-Id: <20220110181644.1457631-1-jao@gnu.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: H6JCCWATXW6ZV2TL333UT7CZMAXDDU4S X-Message-ID-Hash: H6JCCWATXW6ZV2TL333UT7CZMAXDDU4S X-MailFrom: jao@gnu.org 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; digests; suspicious-header CC: jao X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641838620; 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:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=UoBr82pnnft2+vGT3fBXMpQW/DJHOLdpqASz2lrql5M=; b=YYmOAF9rsNnzi4HkipwlO/rt8dtrj72wHyFuLO1T4zPzviEFyMhRTN8GOUSXLCK0Uy6gaV F6wRAA4W8Fo11dSGNK6Oe917M3wx+1c7PXdHuUaC1N0lEG8GCRSQXKAzJtRFFSNScdEBcI 4Ifz3LF3N/yII4W2oXEdRsvNmlm1flnEC5dWc7dROjClL4CCAUDe8oY/XIseMFJIkvfVML uezuCqAjxPyN6nSh9FXd44e4WwUVrFBTm1ITkzdoM+wkUtKL39s3/vFWH04A1ftRqKs2Rf IYKJDUKnCLKykWCC01g83+h/C7Glo8MxpEgaE/ruKDHLmQREC6XHW7QChhhrVw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641838620; a=rsa-sha256; cv=none; b=S1q04HYaOGXNUStdDTem+ADBZcvZRXNPta3dWfLcl2JfseKJuPvuR14bx+2muo7nX+AS2m KDuaadQtQxTDKJrn/PrwxDElbxaVcN21jyE/TJrcyFHlCHrjkJoYKU57oCFpL/Ji0QGQK/ db6Cwe4+Ke16WbOyifce5s01SerhD/GrXRUkpS2g53Avf5sRZZcHrVfyhmcLHnbOD4cz73 iOYP1awEPUeL75Iums4/Dq3LnWtiNB4Jt4gZLGZUly63y7UMf1GYFXxVdxfPjEToLsT+tJ DJrE2D/apvNyCeXa8/Qln65pHmkVoXbhzFYHwu4WZ2Fl9wvmEZ9tZhPKtrVE2w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b="q/V7a4Ua"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 2.67 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b="q/V7a4Ua"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 86C5E28950 X-Spam-Score: 2.67 X-Migadu-Scanner: scn1.migadu.com X-TUID: 2LLlvOXEVqeu Customizable names for buffers presenting search results, via two custom variables (notmuch-search-buffer-name-format and notmuch-saved-search-buffer-name-format), defaulting to values currently used for plain searches and including too tree and unthreaded search buffers. --- This is a much improved version of the patch in id:20220108204121.1053932-1-jao@gnu.org, according to discussion on that thread. This version fixes a doc string. Signed-off-by: jao --- emacs/notmuch-hello.el | 11 +++++---- emacs/notmuch-tree.el | 10 ++++----- emacs/notmuch.el | 51 +++++++++++++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index fc007c4c..44341dd6 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -486,11 +486,14 @@ diagonal." (defun notmuch-hello-widget-search (widget &rest _ignore) (cl-case (widget-get widget :notmuch-search-type) (tree - (notmuch-tree (widget-get widget :notmuch-search-terms) - nil nil nil nil nil nil - (widget-get widget :notmuch-search-oldest-first))) + (let ((n (notmuch-search-format-buffer-name (widget-value widget) "tree" t))) + (notmuch-tree (widget-get widget :notmuch-search-terms) + nil nil n nil nil nil + (widget-get widget :notmuch-search-oldest-first)))) (unthreaded - (notmuch-unthreaded (widget-get widget :notmuch-search-terms))) + (let ((n (notmuch-search-format-buffer-name (widget-value widget) + "unthreaded" t))) + (notmuch-unthreaded (widget-get widget :notmuch-search-terms) nil nil n))) (t (notmuch-search (widget-get widget :notmuch-search-terms) (widget-get widget :notmuch-search-oldest-first))))) diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index d7486904..303c6fad 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -1191,11 +1191,11 @@ The arguments are: (setq query (notmuch-read-query (concat "Notmuch " (if unthreaded "unthreaded " "tree ") "view search: ")))) - (let ((buffer (get-buffer-create (generate-new-buffer-name - (or buffer-name - (concat "*notmuch-" - (if unthreaded "unthreaded-" "tree-") - query "*"))))) + (let* ((name + (or buffer-name + (notmuch-search-buffer-title query + (if unthreaded "unthreaded" "tree")))) + (buffer (get-buffer-create (generate-new-buffer-name name))) (inhibit-read-only t)) (pop-to-buffer-same-window buffer)) ;; Don't track undo information for this buffer diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 85a54706..afb0a115 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -915,7 +915,37 @@ See `notmuch-tag' for information on the format of TAG-CHANGES." (notmuch-search-get-tags-region (point-min) (point-max)) "Tag all"))) (notmuch-search-tag tag-changes (point-min) (point-max) t)) -(defun notmuch-search-buffer-title (query) +(defcustom notmuch-search-buffer-name-format "*notmuch-%t-%s*" + "Format for the name of search results buffers. + +In this spec, %s will be replaced by a description of the search +query and %t by its type (search, tree or unthreaded). + +See also `notmuch-saved-search-buffer-name-format'" + :type 'string + :group 'notmuch-search) + +(defcustom notmuch-saved-search-buffer-name-format "*notmuch-saved-%t-%s*" + "Format for the name of search results buffers. + +In this spec, %s will be replaced by the saved search name and %t +by its type (search, tree or unthreaded). + +See also `notmuch-search-buffer-name-format'" + :type 'string + :group 'notmuch-search) + +(defun notmuch-search-format-buffer-name (query type saved) + "Compose a buffer name for the given QUERY, TYPE (search, tree, +unthreaded) and whether it's SAVED (t or nil)." + (let ((fmt (if saved + notmuch-saved-search-buffer-name-format + notmuch-search-buffer-name-format))) + (if (fboundp 'format-spec) + (format-spec fmt `((?t . ,(or type "search")) (?s . ,query)))) + (format (replace-regexp-in-string "\\b%t\\b" (or type "search") fmt) query))) + +(defun notmuch-search-buffer-title (query &optional type) "Returns the title for a buffer with notmuch search results." (let* ((saved-search (let (longest @@ -930,19 +960,20 @@ See `notmuch-tag' for information on the format of TAG-CHANGES." do (setq longest tuple)) longest)) (saved-search-name (notmuch-saved-search-get saved-search :name)) + (saved-search-type (notmuch-saved-search-get saved-search :search-type)) (saved-search-query (notmuch-saved-search-get saved-search :query))) (cond ((and saved-search (equal saved-search-query query)) ;; Query is the same as saved search (ignoring case) - (concat "*notmuch-saved-search-" saved-search-name "*")) + (notmuch-search-format-buffer-name saved-search-name + saved-search-type + t)) (saved-search - (concat "*notmuch-search-" - (replace-regexp-in-string - (concat "^" (regexp-quote saved-search-query)) - (concat "[ " saved-search-name " ]") - query) - "*")) - (t - (concat "*notmuch-search-" query "*"))))) + (let ((query (replace-regexp-in-string + (concat "^" (regexp-quote saved-search-query)) + (concat "[ " saved-search-name " ]") + query))) + (notmuch-search-format-buffer-name query saved-search-type t))) + (t (notmuch-search-format-buffer-name query type nil))))) (defun notmuch-read-query (prompt) "Read a notmuch-query from the minibuffer with completion. -- 2.34.1