From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id QMRLI8P2qmMy8AAAbAwnHQ (envelope-from ) for ; Tue, 27 Dec 2022 14:44:35 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id QDVOI8P2qmMwzwAA9RJhRA (envelope-from ) for ; Tue, 27 Dec 2022 14:44:35 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 48D2430FF9 for ; Tue, 27 Dec 2022 14:44:35 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pAAFF-0008Qq-D0; Tue, 27 Dec 2022 08:43:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pAAFC-0008QY-Km for emacs-orgmode@gnu.org; Tue, 27 Dec 2022 08:43:50 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pAAFA-0005mR-Hp for emacs-orgmode@gnu.org; Tue, 27 Dec 2022 08:43:50 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 17C4E240236 for ; Tue, 27 Dec 2022 14:43:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1672148626; bh=W3JtXsZvCEhuUID4aJb7qXaG+zzUyGQ4tAqhYYw348A=; h=From:To:Cc:Subject:Date:From; b=jlYy2l5t1enQhVca/2sTnMW/t6yOlbiTUPKydH3mxV1f4jnp8N1lKjMH/TmnZxXcL WJjscuvy163IHdhRETFfz/a9IOw0YFz4vhgInr05TzVC4+b2F9sxGlzUdeSTDFPIYY rpbE38atqGX/g9Zj9lUYKF7tNDVsk6umS18uCN7iHlyTIeVFNl4YPoh1sMBaPnByCB 7vA1liSGS/rvVK73NdYBG27NB0HbRP75HwDUbE2Rvrs8rd4mYqk9MbM62y3MKzfeFT Yzoxf3AQNRu5rfp9g6MgmKhF1t+dusCc5tz5L2URnfcfc3LHIXDIucCRKB4fPh4xMV fGhmsZrU6g1Ig== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NhG8J3Pl7z6tmX; Tue, 27 Dec 2022 14:43:44 +0100 (CET) From: Ihor Radchenko To: alain.cochard@unistra.fr Cc: emacs-orgmode@gnu.org Subject: Re: Problem with multi-occur search when restricted to region In-Reply-To: <25514.61148.396137.347019@gargle.gargle.HOWL> References: <25514.61148.396137.347019@gargle.gargle.HOWL> Date: Tue, 27 Dec 2022 13:43:37 +0000 Message-ID: <8735912c8m.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1672148675; a=rsa-sha256; cv=none; b=iwsdvCA9YEOvk7mRc3mDGUkAPsbaOyDBSHNq5PAiu5TicFLSzUmtXh8vsGzf5g0QmmduPZ SvzEgTw3YPYh/EQBmKxAhacdQsn1Br/z6bPA5DYN4c/wSKtrOjBwwdcEzm8WMeP+OdGgFG HLiOQRzH3+b9ys4xS9RDq3bMF3Jzoek0mgfewMouo1DgVfzTxQ8P3h+DPoTZRL/5RyFg9E BtPu34FSq/eBR5hc4DpVUkvW/9zpH8XwSs63m2EpC5tR9z02qd2WOp98RdUQ8NRg5AG235 by37MQfqsgkOsIyjhuxS/wwuXbZofUiv6XghnYFoslTL8YmkpVou+9qYwLeszA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=jlYy2l5t; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1672148675; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=WkWavDynVQdoos7c8lik9DoHE9b2kRY2BioVC5I9TlY=; b=OsrfSMhsNOAsvLFd4pIKvsBRjtNjA9oIyny/zq6S8DzkMF7vbsI3Myh4tqQuqvYTbMlT19 wGjS//Xd5nI0orMUx0kWx5wwxMtRHsDorCThSfO6EoGCPxvE29Y++on+olfw99AVhl0vB8 kJ6xG5HvqZc6AdTyTWgquzjGIfS5m0YIuZKPJHABQ5iKEQXSSm/9kpWGuzcRwhZ7rclQtC AsZs/cwKG26LvFqFuLsUQiTucrWzb/fG7Uvtu4jrcGKiq3jh4YRxSn7oNrWGMSwKmbPLQR SjZzAShDiYYvrIJ+cl7AQ1RrC5E4bLHhYqnEo2CwhoD8PbQE9YmEBz147cOykA== X-Spam-Score: -9.77 X-Migadu-Queue-Id: 48D2430FF9 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=jlYy2l5t; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -9.77 X-TUID: KvbYs9AiDEo0 --=-=-= Content-Type: text/plain Alain.Cochard@unistra.fr writes: > * h1 > foo > * h2 > foo bar > > I make the 1st two lines the region. Then I do > > M-x org-agenda << / foo > > and I see > > 2 matches for "foo" in buffer: debug.org > 2:foo > 4:foo bar Thanks for reporting! Can you try the attached patch? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-occur-in-agenda-files-Respect-agenda-restriction.patch >From e0e18a6e98fb2faafcc9a43a55321206e8b3f9ed Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Tue, 27 Dec 2022 16:41:57 +0300 Subject: [PATCH] org-occur-in-agenda-files: Respect agenda restriction * lisp/org.el (org-occur-in-agenda-files): Respect agenda restriction when searching. Reported-by: Alain.Cochard@unistra.fr Link: https://orgmode.org/list/25514.61148.396137.347019@gargle.gargle.HOWL --- lisp/org.el | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 26a4c8b1c..2ab7c0ccf 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -18551,24 +18551,40 @@ (defun org-occur-in-agenda-files (regexp &optional _nlines) (interactive "sOrg-files matching: ") (let* ((files (org-agenda-files)) (tnames (mapcar #'file-truename files)) - (extra org-agenda-text-search-extra-files)) - (when (eq (car extra) 'agenda-archives) + (extra org-agenda-text-search-extra-files) + (narrows nil)) + (when (and (eq (car extra) 'agenda-archives) + (not org-agenda-restrict)) (setq extra (cdr extra)) (setq files (org-add-archive-files files))) - (dolist (f extra) - (unless (member (file-truename f) tnames) - (unless (member f files) (setq files (append files (list f)))) - (setq tnames (append tnames (list (file-truename f)))))) + (unless org-agenda-restrict + (dolist (f extra) + (unless (member (file-truename f) tnames) + (unless (member f files) (setq files (append files (list f)))) + (setq tnames (append tnames (list (file-truename f))))))) (multi-occur (mapcar (lambda (x) (with-current-buffer ;; FIXME: Why not just (find-file-noselect x)? ;; Is it to avoid the "revert buffer" prompt? (or (get-file-buffer x) (find-file-noselect x)) - (widen) + (if (eq (current-buffer) org-agenda-restrict) + (progn + ;; Save the narrowing state. + (push (list (current-buffer) (point-min) (point-max)) + narrows) + (widen) + (narrow-to-region org-agenda-restrict-begin + org-agenda-restrict-end)) + (widen)) (current-buffer))) files) - regexp))) + regexp) + ;; Restore the narrowing. + (dolist (narrow narrows) + (with-current-buffer (car narrow) + (widen) + (narrow-to-region (nth 1 narrow) (nth 2 narrow)))))) (add-hook 'occur-mode-find-occurrence-hook (lambda () (when (derived-mode-p 'org-mode) (org-fold-reveal)))) -- 2.38.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--