From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#40919: 27.0.91; next-error-select-buffer does not always behave as documented Date: Fri, 22 May 2020 02:57:37 +0300 Message-ID: References: <53913bd9-2bdc-0f70-f7b4-744283e0512f@ieee.org> <87d07rmb6j.fsf@mail.linkov.net> <87zhau5bfw.fsf@mail.linkov.net> <66f63b16-307a-919c-1d25-60ff63f92ae6@ieee.org> <87bln8u3xq.fsf@mail.linkov.net> <851cd382-4b2e-447a-2212-919c8a4ce908@ieee.org> <87d07lykkd.fsf@mail.linkov.net> <83bln5rbah.fsf@gnu.org> <87zhaozlvo.fsf@mail.linkov.net> <87v9kr8t1s.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------999E6205C3908AAA7F507F55" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="122780"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Cc: 40919@debbugs.gnu.org, tspiteri@ieee.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 22 01:58:09 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jbv4j-000VqM-06 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 May 2020 01:58:09 +0200 Original-Received: from localhost ([::1]:59448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbv4i-0005sa-3e for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 21 May 2020 19:58:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbv4c-0005sO-8v for bug-gnu-emacs@gnu.org; Thu, 21 May 2020 19:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46050) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbv4b-00032q-W3 for bug-gnu-emacs@gnu.org; Thu, 21 May 2020 19:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jbv4b-00051r-VV for bug-gnu-emacs@gnu.org; Thu, 21 May 2020 19:58:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 May 2020 23:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40919 X-GNU-PR-Package: emacs Original-Received: via spool by 40919-submit@debbugs.gnu.org id=B40919.159010546719311 (code B ref 40919); Thu, 21 May 2020 23:58:01 +0000 Original-Received: (at 40919) by debbugs.gnu.org; 21 May 2020 23:57:47 +0000 Original-Received: from localhost ([127.0.0.1]:57596 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jbv4N-00051N-4k for submit@debbugs.gnu.org; Thu, 21 May 2020 19:57:47 -0400 Original-Received: from mail-wr1-f42.google.com ([209.85.221.42]:37911) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jbv4M-00051B-56 for 40919@debbugs.gnu.org; Thu, 21 May 2020 19:57:46 -0400 Original-Received: by mail-wr1-f42.google.com with SMTP id e1so8405011wrt.5 for <40919@debbugs.gnu.org>; Thu, 21 May 2020 16:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=+NliZw2joC5srp+vgKbLowcYyq7MFFHHwrouRXPAdbs=; b=Ob5tOjphgEjF0pElVLpRAmoGiS/t9MtBmyh7IqtypjQQCvgzd+O9G7ce+6RJhaCYhM SoU7nvExyJ6qI6E5hravZ6BnFJ0aQLN0eVbcFGqPYTc2fEKz43sT/eeZ0eew43LWuU3t Dz2Hk+Z86zZaxEf9Hy8u2ECUabjV4jQhlipfGQGZNSRnVPKWHgsFTrCkv4BQ5/Mk7Rr6 9vq0IUFhvF2BnkRyJDSqt74eGDdN+vGUir1iJuG7UT5Gh52iNCxtJhzbRVOza1gt3YjU noXEZXRV6L2Bu48noc+flQf/irBnTTfxzQmDJJzojr8E8T8WgPJqOTrltYNV96YgllC4 5Tdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=+NliZw2joC5srp+vgKbLowcYyq7MFFHHwrouRXPAdbs=; b=jj5t7OMfCn7ASI543mGtY/07TwWOyJmsn+qIweXo3zTwE/vZokBoWk7oj1l7M0HYDe szMkq10QJdaV2YLoarXI9JkhZJe2m9sygdx0ZDFAKWI2ZMG9SRWomDkxXe08WEIIL5Xj yNmEG1nhJIl3rrWHcuVwng6IAkVI/Tq/WvV2rvoBNJGvH3u5xUL+3heMsDhGNzKFD93p Yw4ZUUcqSiIJIIrJ64PVOhfu315vVJ23KAraVeHJymDIX2nVhDR/CgVVkjbxZdF2zSPw Loa7JCqrZWn/1q7C5ZB4Ldx7PZ7KDRzDwuIdxOf/zzm9hV9hZDxr9Swo9arfwVVdrH2z +zeQ== X-Gm-Message-State: AOAM530xpaQkSuwdaJRCErDhn5LtHploOhF+yAHz9y8p/RK7b4FNHjJX sCq7iDmW+KScDjJVHo3U+/4= X-Google-Smtp-Source: ABdhPJwDbNFgYPLQhDPjTudjsmajPeCm+ZzmrEewG1FgPr81J1JXRel3DteGb8KYbHmKoMkLBXS2Gw== X-Received: by 2002:adf:dd50:: with SMTP id u16mr958768wrm.58.1590105460161; Thu, 21 May 2020 16:57:40 -0700 (PDT) Original-Received: from [192.168.0.3] ([66.205.73.129]) by smtp.googlemail.com with ESMTPSA id w15sm7750599wmi.35.2020.05.21.16.57.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2020 16:57:39 -0700 (PDT) In-Reply-To: <87v9kr8t1s.fsf@mail.linkov.net> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:180730 Archived-At: This is a multi-part message in MIME format. --------------999E6205C3908AAA7F507F55 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 20.05.2020 01:21, Juri Linkov wrote: >>> Another variant would be >>> to add an optional choice to the existing option that allows to restore >>> the old behavior and doesn't affect the current behavior in any way. >> >> FWIW, I'd consider that more of a documentation change. >> >> More importantly, and certainly only for Emacs 28, Juri could you remind me >> what we'll be losing by removing the case no. 2 from >> next-error-find-buffer? > > It is used to handle such cases when navigating one next-error list > visits a buffer that contains another next-error list - visiting > such buffer should not switch the navigation, it should continue > the initial navigation. Didn't we fix changelog-mode so this doesn't happen anymore? I think as long as file major modes don't set next-error-last-buffer (and minor modes either, on initialization), we should be safe. Can you reproduce a problematic scenario with the attached patch? > But I'm not proud of the case no. 2, so you can drop it :) > > Or better move it to a separate function and provide this function > as an option in next-error-find-buffer-function. Patch attached. Comments welcome. >> The ability to switch to an arbitrary Grep buffer and start using it with >> 'M-x next-error'? E.g. if there are several of them. That's more of >> a backward compatibility concern, right? Or do you have scenarios in >> mind where this will really save on keystrokes? > > The ability to visit an arbitrary Grep buffer and use 'next-error' in it > to switch navigation should always work as the most reliable and implicit > way to switch navigation. This is the case no. 3 in next-error-find-buffer. Not if there are, say, two Compilation buffers (or Grep and Occur, etc), and you switch to the least recently used one, and press M-g n. It's probably fine, though. >> On another note, perhaps we could add a message to next-error-select-buffer >> that would be shown if we suspect this command will not have the expected >> result for the user. > > Or maybe ask the user using the minibuffer to resolve ambiguity. Resolve it how? I think we can safely guess their intention, it's just not trivial to execute it. Anyway, this problem should go away with the attached patch. --------------999E6205C3908AAA7F507F55 Content-Type: text/x-patch; charset=UTF-8; name="next-error-extract-case-2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="next-error-extract-case-2.diff" diff --git a/lisp/simple.el b/lisp/simple.el index 111afa69d1..31d6cbcef2 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -211,6 +211,8 @@ next-error-find-buffer-function :type '(choice (const :tag "No default" ignore) (const :tag "Single next-error capable buffer on selected frame" next-error-buffer-on-selected-frame) + (const :tag "Current buffer if next-error capable and outside navigation" + next-error-buffer-try-current-outside-navigation) (function :tag "Other function")) :group 'next-error :version "27.1") @@ -240,6 +242,21 @@ next-error-buffer-on-selected-frame (if (eq (length window-buffers) 1) (car window-buffers)))) +(defun next-error-buffer-try-current-outside-navigation (&optional + avoid-current + extra-test-inclusive + extra-test-exclusive) + "Maybe Return current buffer if it's next-error capable. +But return nil if we navigated to the current buffer by the means +of `next-error' command." + ;; Check that next-error-buffer has no buffer-local value + ;; (i.e. never navigated to the current buffer from another), + ;; and the current buffer is a `next-error' capable buffer. + (if (and (not (local-variable-p 'next-error-buffer)) + (next-error-buffer-p (current-buffer) avoid-current + extra-test-inclusive extra-test-exclusive)) + (current-buffer))) + (defun next-error-find-buffer (&optional avoid-current extra-test-inclusive extra-test-exclusive) @@ -260,24 +277,16 @@ next-error-find-buffer (funcall next-error-find-buffer-function avoid-current extra-test-inclusive extra-test-exclusive) - ;; 2. If next-error-buffer has no buffer-local value - ;; (i.e. never navigated to the current buffer from another), - ;; and the current buffer is a `next-error' capable buffer, - ;; use it unconditionally, so next-error will always use it. - (if (and (not (local-variable-p 'next-error-buffer)) - (next-error-buffer-p (current-buffer) avoid-current - extra-test-inclusive extra-test-exclusive)) - (current-buffer)) - ;; 3. If next-error-last-buffer is an acceptable buffer, use that. + ;; 2. If next-error-last-buffer is an acceptable buffer, use that. (if (and next-error-last-buffer (next-error-buffer-p next-error-last-buffer avoid-current extra-test-inclusive extra-test-exclusive)) next-error-last-buffer) - ;; 4. If the current buffer is acceptable, choose it. + ;; 3. If the current buffer is acceptable, choose it. (if (next-error-buffer-p (current-buffer) avoid-current extra-test-inclusive extra-test-exclusive) (current-buffer)) - ;; 5. Look for any acceptable buffer. + ;; 4. Look for any acceptable buffer. (let ((buffers (buffer-list))) (while (and buffers (not (next-error-buffer-p @@ -285,7 +294,7 @@ next-error-find-buffer extra-test-inclusive extra-test-exclusive))) (setq buffers (cdr buffers))) (car buffers)) - ;; 6. Use the current buffer as a last resort if it qualifies, + ;; 5. Use the current buffer as a last resort if it qualifies, ;; even despite AVOID-CURRENT. (and avoid-current (next-error-buffer-p (current-buffer) nil @@ -293,7 +302,7 @@ next-error-find-buffer (progn (message "This is the only buffer with error message locations") (current-buffer))) - ;; 7. Give up. + ;; 6. Give up. (error "No buffers contain error message locations"))) (defun next-error (&optional arg reset) --------------999E6205C3908AAA7F507F55--