From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#28864: 25.3.50; next-error-no-select does select Date: Fri, 03 Nov 2017 00:00:20 +0200 Organization: LINKOV.NET Message-ID: <87h8uc1guj.fsf@localhost> References: <87bml72qck.fsf@gmail.com> <4045abe7-1acb-314b-b9ac-72b62db30570@yandex.ru> <87sheh270d.fsf@gmail.com> <6f3b7c2c-31af-8eb2-8f13-a9ba17d3d8e6@yandex.ru> <87mv4m5lok.fsf@gmail.com> <87d15h5f97.fsf@gmail.com> <874lqreyj5.fsf@localhost> <7f67cb1c-062f-44fa-ba8e-9ac0cab220a3@yandex.ru> <87po9del14.fsf@localhost> <5c524170-7ba7-8279-41b5-b4286c2980f0@yandex.ru> <87tvyomh37.fsf@localhost> <7821c28e-3bf5-0bab-46ab-23f3a02566a8@yandex.ru> <87po97vuoh.fsf@localhost> <87778f88-a6e6-06d5-f5ad-8a46d73144cc@yandex.ru> <87efplk4vu.fsf@localhost> <87tvyg72z1.fsf@localhost> <87o9onc775.fsf@localhost> <0cee613e-6189-2eef-2407-b84c46dd3175@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1509660378 10091 195.159.176.226 (2 Nov 2017 22:06:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 2 Nov 2017 22:06:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (build 4, x86_64-pc-linux-gnu) Cc: 28864@debbugs.gnu.org, Noam Postavsky , Tino Calancha To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 02 23:06:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eANck-0001ev-NJ for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Nov 2017 23:06:06 +0100 Original-Received: from localhost ([::1]:34061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eANcs-0008Er-5y for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Nov 2017 18:06:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eANcl-0008El-8D for bug-gnu-emacs@gnu.org; Thu, 02 Nov 2017 18:06:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eANcg-0003eh-7y for bug-gnu-emacs@gnu.org; Thu, 02 Nov 2017 18:06:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eANcg-0003dc-1e for bug-gnu-emacs@gnu.org; Thu, 02 Nov 2017 18:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eANcf-0002wN-JB for bug-gnu-emacs@gnu.org; Thu, 02 Nov 2017 18:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Nov 2017 22:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28864 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28864-submit@debbugs.gnu.org id=B28864.150966031111238 (code B ref 28864); Thu, 02 Nov 2017 22:06:01 +0000 Original-Received: (at 28864) by debbugs.gnu.org; 2 Nov 2017 22:05:11 +0000 Original-Received: from localhost ([127.0.0.1]:48378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eANbr-0002vB-BQ for submit@debbugs.gnu.org; Thu, 02 Nov 2017 18:05:11 -0400 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:56217 helo=homiemail-a17.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eANbp-0002v2-D5 for 28864@debbugs.gnu.org; Thu, 02 Nov 2017 18:05:10 -0400 Original-Received: from homiemail-a17.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a17.g.dreamhost.com (Postfix) with ESMTP id 1D9762B206A; Thu, 2 Nov 2017 15:05:05 -0700 (PDT) Original-Received: from localhost.linkov.net (m91-129-116-254.cust.tele2.ee [91.129.116.254]) (Authenticated sender: jurta@jurta.org) by homiemail-a17.g.dreamhost.com (Postfix) with ESMTPA id D5B222B2065; Thu, 2 Nov 2017 15:05:03 -0700 (PDT) In-Reply-To: <0cee613e-6189-2eef-2407-b84c46dd3175@yandex.ru> (Dmitry Gutov's message of "Wed, 1 Nov 2017 01:42:21 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:139379 Archived-At: --=-=-= Content-Type: text/plain >> I'm thinking about adding 3 customizable options for >> next-error-find-buffer-function: >> >> 1. buffer-local - new default >> 2. window-local - useful for one window per each navigation buffer > > I'm not sure either can be congruent to all next-error-function > applications. Some next-error source buffers contain their own errors (so > buffer-local is natural), and others point to errors in other buffers > (supposing they can learn to open those in the same window, window-local > might be fitting). But both kinds are there, and all users deal with both. They can learn to open those in the same window by the patch below. >> 3. frame-local - old implicit default now separated into its own function > > That doesn't sound like a sufficient description: the old default also > includes visibility-based logic. So it's not just one value per frame. Do you think we should use the real frame-parameter? >>> In general, next-error can jump between windows, so window-local is not >>> a good fit for my mental model. >> >> It's bad when next-error unpredictably jumps between windows. >> I hope we could find a way to fix this erratic behavior. > > It basically a rule now that Grep opens errors in a different windows (so > that the Grep buffer stays visible). So erratic or not, multiple windows > are used routinely. This is improved by the same patch. >>> Do we need the buffer-local-ity changes to next-error-last-buffer for that? >>> Because if we do, that's okay, let's commit it and everything, but >>> otherwise I'd rather wait and look for a more elegant approach (for other >>> issues aside from this one). >> >> In the last previous patch, next-error visits next-error-find-buffer, >> calls next-error-function that possibly navigates to another buffer, >> then sets both global and buffer-local of next-error-last-buffer. >> This seems quite logical. And it works in all my tests. > > That... doesn't answer my question, I think. Or I didn't understand > the answer. > > So let me try again: is the new next-error-find-buffer stuff necessary to > fix the current bug? Or is suppressing the change to next-error-last-buffer > during next-error-function calls enough for that? The key point is (setq next-error-last-buffer) after (funcall next-error-function), not before. >>>> + (message "Showing another error from %s" next-error-last-buffer) >>> >>> Is it really "another"? Or maybe it's "current", "last" or "closest" error? >> >> Maybe just "Showing error from %s"? Or simply "Error from %s". >> Then we could simplify the above messages as well: "%s error from %s" >> for e.g. "Next error from %s", "Previous error from %s", ... > > Why not use "current" here as well? After all, we pass 0 to > next-error-function here. OK, here is the next patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=next-error-4.patch diff --git a/lisp/simple.el b/lisp/simple.el index 12d65e5..a741bf8 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -143,6 +143,7 @@ next-error-last-buffer A buffer becomes most recent when its compilation, grep, or similar mode is started, or when it is used with \\[next-error] or \\[compile-goto-error].") +(make-variable-buffer-local 'next-error-last-buffer) (defvar next-error-function nil "Function to use to find the next error in the current buffer. @@ -191,6 +192,13 @@ next-error-buffer-p (and extra-test-inclusive (funcall extra-test-inclusive)))))) +(defcustom next-error-find-buffer-function nil + "Function called to find a `next-error' capable buffer." + :type '(choice (const :tag "No default" nil) + (function :tag "Other function")) + :group 'next-error + :version "27.1") + (defun next-error-find-buffer (&optional avoid-current extra-test-inclusive extra-test-exclusive) @@ -207,18 +215,11 @@ next-error-find-buffer that would normally be considered usable. If it returns nil, that buffer is rejected." (or - ;; 1. If one window on the selected frame displays such buffer, return it. - (let ((window-buffers - (delete-dups - (delq nil (mapcar (lambda (w) - (if (next-error-buffer-p - (window-buffer w) - avoid-current - extra-test-inclusive extra-test-exclusive) - (window-buffer w))) - (window-list)))))) - (if (eq (length window-buffers) 1) - (car window-buffers))) + ;; 1. If a customizable function returns a buffer, use it. + (when next-error-find-buffer-function + (funcall next-error-find-buffer-function avoid-current + extra-test-inclusive + extra-test-exclusive)) ;; 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 @@ -279,23 +280,48 @@ next-error `compilation-error-regexp-alist'." (interactive "P") (if (consp arg) (setq reset t arg nil)) - (when (setq next-error-last-buffer (next-error-find-buffer)) + (let ((next-error-buffer (next-error-find-buffer))) + (when next-error-buffer + ;; we know here that next-error-function is a valid symbol we can funcall + (with-current-buffer next-error-buffer + (funcall next-error-function (prefix-numeric-value arg) reset) + ;; next-error-function might change the value of + ;; next-error-last-buffer, so set it later + (setq next-error-last-buffer next-error-buffer) + (setq-default next-error-last-buffer next-error-last-buffer) + (when next-error-recenter + (recenter next-error-recenter)) + (message "%s error from %s" + (cond (reset "First") + ((eq (prefix-numeric-value arg) 0) "Current") + ((< (prefix-numeric-value arg) 0) "Previous") + (t "Next")) + next-error-last-buffer) + (run-hooks 'next-error-hook))))) + +(defun next-error-internal () + "Visit the source code corresponding to the `next-error' message at point." + (let ((next-error-buffer (current-buffer))) ;; we know here that next-error-function is a valid symbol we can funcall - (with-current-buffer next-error-last-buffer - (funcall next-error-function (prefix-numeric-value arg) reset) + (with-current-buffer next-error-buffer + (funcall next-error-function 0 nil) + ;; next-error-function might change the value of + ;; next-error-last-buffer, so set it later + (setq next-error-last-buffer next-error-buffer) + (setq-default next-error-last-buffer next-error-last-buffer) (when next-error-recenter (recenter next-error-recenter)) + (message "Current error from %s" next-error-last-buffer) (run-hooks 'next-error-hook)))) -(defun next-error-internal () - "Visit the source code corresponding to the `next-error' message at point." - (setq next-error-last-buffer (current-buffer)) - ;; we know here that next-error-function is a valid symbol we can funcall - (with-current-buffer next-error-last-buffer - (funcall next-error-function 0 nil) - (when next-error-recenter - (recenter next-error-recenter)) - (run-hooks 'next-error-hook))) +(defun next-error-select-buffer (next-error-buffer) + "Select a `next-error' capable buffer and set it as the last used." + (interactive + (list (get-buffer + (read-buffer "Select next-error buffer: " nil nil + (lambda (b) (next-error-buffer-p (cdr b))))))) + (setq next-error-last-buffer next-error-buffer) + (setq-default next-error-last-buffer next-error-last-buffer)) (defalias 'goto-next-locus 'next-error) (defalias 'next-match 'next-error) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=compile-1.patch diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index e4b77ab..8496cc9 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -2624,6 +2624,23 @@ compilation-set-window (defvar next-error-highlight-timer) +(defun display-buffer-in-next-error-last-window (buffer alist) + "Return a window used to display the last next-error buffer." + (let* ((window (car (delq nil + (mapcar (lambda (w) (when (and (local-variable-p 'next-error-last-buffer + (window-buffer w)) + (eq (current-buffer) + (buffer-local-value + 'next-error-last-buffer + (window-buffer w)))) + w)) + (window-list-1 nil 'nomini)))))) + (when (window-live-p window) + window + (prog1 (window--display-buffer buffer window 'reuse alist) + (unless (cdr (assq 'inhibit-switch-frame alist)) + (window--maybe-raise-frame (window-frame window))))))) + (defun compilation-goto-locus (msg mk end-mk) "Jump to an error corresponding to MSG at MK. All arguments are markers. If END-MK is non-nil, mark is set there @@ -2654,7 +2671,8 @@ compilation-goto-locus ;; keep the compilation buffer in this window; ;; display the source in another window. (let ((pop-up-windows t)) - (pop-to-buffer (marker-buffer mk) 'other-window)) + (pop-to-buffer (marker-buffer mk) '((display-buffer-in-next-error-last-window) + (inhibit-same-window . t)))) (switch-to-buffer (marker-buffer mk))) (unless (eq (goto-char mk) (point)) ;; If narrowing gets in the way of going to the right place, widen. --=-=-=--