GNU bug report logs - #49275
28.0.50; [PATCH] improve-switch-to-prev-buffer-skip

Previous Next

Package: emacs;

Reported by: Trust me I am a Doctor <pillule <at> riseup.net>

Date: Tue, 29 Jun 2021 16:21:01 UTC

Severity: normal

Tags: patch

Found in version 28.0.50

Done: Trust me I am a Doctor <pillule <at> riseup.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Trust me I am a Doctor <pillule <at> riseup.net>
To: 49275 <at> debbugs.gnu.org
Subject: bug#49275: 28.0.50; [PATCH] improve-switch-to-prev-buffer-skip
Date: Tue, 29 Jun 2021 17:56:18 +0200
[Message part 1 (text/plain, inline)]
$ 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.

[0001-Improve-switch-to-prev-buffer-skip.patch (text/x-diff, attachment)]

This bug report was last modified 3 years and 274 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.