From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Trust me I am a Doctor Newsgroups: gmane.emacs.bugs Subject: bug#49275: 28.0.50; [PATCH] improve-switch-to-prev-buffer-skip Date: Tue, 29 Jun 2021 17:56:18 +0200 Message-ID: <87lf6sy76c.fsf@riseup.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13138"; mail-complaints-to="usenet@ciao.gmane.io" To: 49275@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 29 18:21:10 2021 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 1lyGU2-0003Af-5a for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Jun 2021 18:21:10 +0200 Original-Received: from localhost ([::1]:33026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyGU1-0000qt-3p for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Jun 2021 12:21:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyGTu-0000qB-Hg for bug-gnu-emacs@gnu.org; Tue, 29 Jun 2021 12:21:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyGTu-0007es-8y for bug-gnu-emacs@gnu.org; Tue, 29 Jun 2021 12:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lyGTu-0001P2-1G for bug-gnu-emacs@gnu.org; Tue, 29 Jun 2021 12:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Trust me I am a Doctor Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Jun 2021 16:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49275 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16249836195313 (code B ref -1); Tue, 29 Jun 2021 16:21:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Jun 2021 16:20:19 +0000 Original-Received: from localhost ([127.0.0.1]:55172 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyGTC-0001Nc-NV for submit@debbugs.gnu.org; Tue, 29 Jun 2021 12:20:19 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:48536) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyGTA-0001NU-SO for submit@debbugs.gnu.org; Tue, 29 Jun 2021 12:20:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyGTA-0000YD-Lv for bug-gnu-emacs@gnu.org; Tue, 29 Jun 2021 12:20:16 -0400 Original-Received: from mx1.riseup.net ([198.252.153.129]:33032) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyGT4-0006uM-Vi for bug-gnu-emacs@gnu.org; Tue, 29 Jun 2021 12:20:16 -0400 Original-Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4GDqSm1VHrzDqr0 for ; Tue, 29 Jun 2021 09:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1624983608; bh=4o8arc121vx/G4xfrNAZAa3SYvLft+447CPIcQmq7k0=; h=From:To:Subject:Date:From; b=MFzr2LXm4FzLVFQArb7mGp9r5dOSY+Aav6qj/i1jupK5PGDiyRA3z14vtjY/HDxJe SjvqXPwkbjUZTk7DTDzBHU1ileVXANrbtK+3e5GJbLSkgnO6rdWTOV9JgEThyHkygi Bak0x2SivNNChXKQf/9bTBZOk3eFzx4hiQ6yM6Fs= X-Riseup-User-ID: F0A74C3DC130224F6856F8F0F3A757E1B3FB4E0DFE5DE686B035017A27605224 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4GDqSk3BWVz5vbQ for ; Tue, 29 Jun 2021 09:20:05 -0700 (PDT) Received-SPF: pass client-ip=198.252.153.129; envelope-from=pillule@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:209109 Archived-At: --=-=-= Content-Type: text/plain $ emacs -Q ;; Considering the next commands : (defun pils/cycle-buffer-of-major-mode (&optional arg) "Switch to previous buffer of this major mode. With ARG as \\[universal-argument], switch to the next instead." (interactive "P") (let ((switch-to-prev-buffer-skip (lambda (window buffer _bury-or-kill) (not (eq (buffer-local-value 'major-mode (window-buffer window)) (buffer-local-value 'major-mode buffer)))))) (if arg (switch-to-next-buffer) (switch-to-prev-buffer nil 'append))) (when (eq (current-buffer) (window-old-buffer)) (user-error "No other %s buffer available." major-mode))) (defun pils/next-buffer-of-major-mode () "Switch to the next buffer of this major mode." (interactive) (pils/cycle-buffer-of-major-mode t)) ;; That we could temporary bind to : (global-set-key (kbd "M-p") #'pils/cycle-buffer-of-major-mode) (global-set-key (kbd "M-n") #'pils/next-buffer-of-major-mode) Now gently but firmly, play theses emacs chords. What happened ? The first command will put you in another mode. That is unexpected ... Worse the second one will quickly jam. The current implementation 'switch-to-prev-buffer-skip' fallback to the first skipped buffer if no one have satisfied its anti-predicate. That's why you could end up in another mode despite setting 'switch-to-prev-buffer-skip' to not select others modes. Conservatively I fix that by checking if 'switch-to-prev-buffer-skip' is a function. The second issue is a bug in the implementation of 'switch-to-next-buffer'. This command should never return the same buffer, it is wrote in its docstring, and it escaped me in commit d0c7d8bc22. So here a little patch to fix both. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Improve-switch-to-prev-buffer-skip.patch Content-Description: Improve-switch-to-prev-buffer-skip >From 687725fa0ab9c5cae9a6c5efb7e24c14ce2c2a1f Mon Sep 17 00:00:00 2001 From: Trust me I am a doctor Date: Sun, 27 Jun 2021 02:24:27 +0200 Subject: [PATCH] Improve switch-to-prev-buffer-skip * lisp/window.el (switch-to-prev-buffer): It was fall-backing to the first skipped buffer, what I know is it is most probably undesirable when 'switch-to-prev-buffer-skip' is a function. So we only do it when it is not a function. (switch-to-next-buffer): Tiddo, and also fix a bug where this function was returning the same buffer, as it never should do. --- lisp/window.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/window.el b/lisp/window.el index c0511bec4c..668bcf0d04 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4721,8 +4721,8 @@ switch-to-prev-buffer window new-buffer (nth 1 entry) (nth 2 entry)) (throw 'found t))))) - (when skipped - ;; Show first skipped buffer. + (when (and skipped (not functionp switch-to-prev-buffer-skip-p)) + ;; Show first skipped buffer, unless skip was a function. (setq new-buffer skipped) (set-window-buffer-start-and-point window new-buffer))) @@ -4831,6 +4831,7 @@ switch-to-next-buffer ;; nreverse here!) (dolist (entry (reverse (window-prev-buffers window))) (when (and (not (eq new-buffer (car entry))) + (not (eq old-buffer (car entry))) (setq new-buffer (car entry)) (or (buffer-live-p new-buffer) (not (setq killed-buffers @@ -4842,8 +4843,8 @@ switch-to-next-buffer window new-buffer (nth 1 entry) (nth 2 entry)) (throw 'found t)))) - (when skipped - ;; Show first skipped buffer. + (when (and skipped (not functionp switch-to-prev-buffer-skip-p)) + ;; Show first skipped buffer, unless skip was a function. (setq new-buffer skipped) (set-window-buffer-start-and-point window new-buffer))) -- 2.20.1 --=-=-=--