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: Mon, 30 Oct 2017 23:14:27 +0200 Organization: LINKOV.NET Message-ID: <87tvyg72z1.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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1509398361 10094 195.159.176.226 (30 Oct 2017 21:19:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 30 Oct 2017 21:19:21 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (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 Mon Oct 30 22:19:14 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 1e9HSg-0001h4-Dp for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 Oct 2017 22:19:10 +0100 Original-Received: from localhost ([::1]:42666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9HSn-0002Vx-OQ for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 Oct 2017 17:19:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9HSc-0002VU-Ju for bug-gnu-emacs@gnu.org; Mon, 30 Oct 2017 17:19:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9HSY-00006J-Ib for bug-gnu-emacs@gnu.org; Mon, 30 Oct 2017 17:19:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34079) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9HSY-000066-En for bug-gnu-emacs@gnu.org; Mon, 30 Oct 2017 17:19:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e9HSY-0000HJ-8z for bug-gnu-emacs@gnu.org; Mon, 30 Oct 2017 17:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Oct 2017 21:19:02 +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.1509398288993 (code B ref 28864); Mon, 30 Oct 2017 21:19:02 +0000 Original-Received: (at 28864) by debbugs.gnu.org; 30 Oct 2017 21:18:08 +0000 Original-Received: from localhost ([127.0.0.1]:42757 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9HRg-0000Fw-52 for submit@debbugs.gnu.org; Mon, 30 Oct 2017 17:18:08 -0400 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:46552 helo=homiemail-a76.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9HRd-0000Fh-4s for 28864@debbugs.gnu.org; Mon, 30 Oct 2017 17:18:05 -0400 Original-Received: from homiemail-a76.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a76.g.dreamhost.com (Postfix) with ESMTP id 36A0845807B; Mon, 30 Oct 2017 14:18:04 -0700 (PDT) Original-Received: from localhost.linkov.net (m91-131-180-239.cust.tele2.ee [91.131.180.239]) (Authenticated sender: jurta@jurta.org) by homiemail-a76.g.dreamhost.com (Postfix) with ESMTPA id 0053B458079; Mon, 30 Oct 2017 14:18:02 -0700 (PDT) In-Reply-To: (Dmitry Gutov's message of "Mon, 30 Oct 2017 16:59:28 +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:139213 Archived-At: >> We need the global value as well to get the last next-error buffer >> when there is no buffer-local value yet in the current buffer. > > Doesn't sound very elegant: we accumulate hidden state as the time passes, > and the user calls 'next-error' with compilations, grep, and so on. But > this is better than nothing, of course. > > Does it also mean that the effect of next-error-select-buffer will also be > buffer-local? Yes, next-error-select-buffer sets both buffer-local and global values, exactly like in next-error. >>>> 4. moves window-on-frame-visibility code to separate function >>>> that can be used to customize for backward-compatibility >>> >>> Do we get a built-in alternative to this value? If we just provide >>> a customization point, that nice, but not a significant improvement. >> >> You mean to remove next-error-buffer-on-selected-frame? >> Or maybe to do the other way: add more predefined functions like >> a function to use window-local navigation as an alternative. > > Now I see it: you have moved the visibility-based search to the custom > variable and disabled it by default. So the default behavior is changed > (for the better, IMO), and I withdraw the question, thanks. :) We could also add an alternative function based on window-local values. At least, when I tried this code, it works as expected: (setq next-error-find-buffer-function (lambda (&optional avoid-current extra-test-inclusive extra-test-exclusive) (window-parameter nil 'next-error-buffer))) (add-hook 'next-error-hook (lambda () (set-window-parameter nil 'next-error-buffer next-error-last-buffer))) >> When the user visits a ChangeLog buffer from *grep*, then >> next-error continues the *grep* navigation. When the user >> visit a ChangeLog file by any other command, then next-error >> navigates entries in that ChangeLog buffer. > > Does this also work with next-error, not just next-error-no-select? > > I'm guessing this part helps with that: > > + (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-last-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) > > So we ignore the next-error-last-buffer change during a call to > next-error-last-function, but not in any other circumstances? Like visiting > a ChangeLog file manually. Maybe that's okay... Oh, sorry, there was a typo: it should be (with-current-buffer next-error-buffer Fixed in the next version of the patch below. >>>> 6. message to show which next-error buffer is currently used >>> >>> Every time we call `next-error'? >> >> That's right. > > That might be a bit excessive. But more importantly, opaque to an > average user. > > How about a message like this: > > "Showing next/last/previous error from %s" > > ? Yes, it's good to show its direction as well: diff --git a/lisp/simple.el b/lisp/simple.el index 12d65e5..ce5c858 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-function) (defvar next-error-function nil "Function to use to find the next error in the current buffer. @@ -191,6 +192,30 @@ 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 "Buffer on selected frame" next-error-buffer-on-selected-frame) + (const :tag "No default" nil) + (function :tag "Other function")) + :group 'next-error + :version "27.1") + +(defun next-error-buffer-on-selected-frame (&optional avoid-current + extra-test-inclusive + extra-test-exclusive) + "Return a single visible next-error buffer on the selected frame." + (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)))) + (defun next-error-find-buffer (&optional avoid-current extra-test-inclusive extra-test-exclusive) @@ -207,18 +232,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 +297,47 @@ 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 "Showing %s error from %s" + (cond (reset "first") + ((< (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 "Showing another 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)