From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#69993: Wrap window buffers while cycling Date: Sun, 14 Apr 2024 19:15:17 +0300 Organization: LINKOV.NET Message-ID: <867ch09bx6.fsf@mail.linkov.net> References: <86h6gug41x.fsf@mail.linkov.net> <86v850jmmo.fsf@mail.linkov.net> <0d2fdebf-2149-4f92-89b8-45a8b6a7d272@gmx.at> <86plv8hz2v.fsf@mail.linkov.net> <8a131d8b-1330-4d82-92f6-309f499e9c15@gmx.at> <86h6gi49zw.fsf@mail.linkov.net> <1e50bd70-8cbb-46f9-9078-dd0e6226da63@gmx.at> <861q7k8gms.fsf@mail.linkov.net> <2d3f0d14-e39b-4399-be30-03f11725c505@gmx.at> <86ttkf6a8r.fsf@mail.linkov.net> <86jzlajpqq.fsf@mail.linkov.net> <85109880-3370-47e0-b7c9-6c5a32cfaafa@gmx.at> <86le5nhwqy.fsf@mail.linkov.net> <864jcajzxi.fsf@mail.linkov.net> <86o7ahglre.fsf@mail.linkov.net> <28a8149b-283a-4b08-9df5-f1139a0fccbe@gmx.at> <86ttk7m7ir.fsf@mail.linkov.net> <1b38c78c-6697-4c6b-81cf-5a72fdd3ba8d@gmx.at> <868r1i8si0.fsf@mail.linkov.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="23739"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 69993@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 14 18:18:27 2024 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 1rw2Yk-0005wj-At for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Apr 2024 18:18:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rw2YK-0002uH-B8; Sun, 14 Apr 2024 12:18:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rw2YI-0002td-0i for bug-gnu-emacs@gnu.org; Sun, 14 Apr 2024 12:17:58 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rw2YH-0005EA-Oi for bug-gnu-emacs@gnu.org; Sun, 14 Apr 2024 12:17:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rw2YS-0007at-QY for bug-gnu-emacs@gnu.org; Sun, 14 Apr 2024 12:18:08 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Apr 2024 16:18:08 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69993 X-GNU-PR-Package: emacs Original-Received: via spool by 69993-submit@debbugs.gnu.org id=B69993.171311148029083 (code B ref 69993); Sun, 14 Apr 2024 16:18:08 +0000 Original-Received: (at 69993) by debbugs.gnu.org; 14 Apr 2024 16:18:00 +0000 Original-Received: from localhost ([127.0.0.1]:36014 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rw2YH-0007YX-KQ for submit@debbugs.gnu.org; Sun, 14 Apr 2024 12:17:59 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:51737) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rw2Xw-0007Tb-US for 69993@debbugs.gnu.org; Sun, 14 Apr 2024 12:17:41 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id E8CF11C0002; Sun, 14 Apr 2024 16:17:18 +0000 (UTC) In-Reply-To: <868r1i8si0.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 12 Apr 2024 19:23:59 +0300") X-GND-Sasl: juri@linkov.net 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:283290 Archived-At: --=-=-= Content-Type: text/plain >>> So keeping the stable order of window prev/next buffers after C-x b >>> with a hook should be implemented in tab-line.el, not in window.el? >> >> I don't know how you currently handle C-x , C-x b or >> 'rename-buffer' or whether a buffer is modified on the tab line so I >> can't tell whether you would need a hook for these. But this issue is >> IMHO not connected to whether getting the previous or next buffer should >> wrap or be restricted to buffers previously shown in a window. > > Handling 'C-x b' and 'rename-buffer' is not yet implemented. > Probably need to add a new window parameter to keep a list > of tab buffers and sync it with window prev/next buffers. Now handling 'C-x b' is completely implemented here: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tab-line-buffer-change.patch diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 54e9ee16243..776d33de3e2 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -843,26 +857,9 @@ tab-line-select-tab (force-mode-line-update)))))))) (defun tab-line-select-tab-buffer (buffer &optional window) - (let* ((window-buffer (window-buffer window)) - (next-buffers (seq-remove (lambda (b) (eq b window-buffer)) - (window-next-buffers window))) - (prev-buffers (seq-remove (lambda (b) (eq b window-buffer)) - (mapcar #'car (window-prev-buffers window)))) - ;; Remove next-buffers from prev-buffers - (prev-buffers (seq-difference prev-buffers next-buffers))) - (cond - ((and (eq tab-line-tabs-function #'tab-line-tabs-window-buffers) - (memq buffer next-buffers)) - (dotimes (_ (1+ (seq-position next-buffers buffer))) - (switch-to-next-buffer window))) - ((and (eq tab-line-tabs-function #'tab-line-tabs-window-buffers) - (memq buffer prev-buffers)) - (dotimes (_ (1+ (seq-position prev-buffers buffer))) - (switch-to-prev-buffer window))) - (t - (with-selected-window window - (let ((switch-to-buffer-obey-display-actions nil)) - (switch-to-buffer buffer))))))) + (with-selected-window window + (let ((switch-to-buffer-obey-display-actions nil)) + (switch-to-buffer buffer)))) (defcustom tab-line-switch-cycling nil "Enable cycling tab switch. @@ -919,6 +916,26 @@ tab-line-switch-to-next-tab (let ((switch-to-buffer-obey-display-actions nil)) (switch-to-buffer buffer)))))))) +(defun tab-line-buffer-change (_window) + (let* ((new-buffer (window-buffer)) + (old-buffers (window-parameter nil 'tab-line-window-buffers)) + (prev-buffers (window-prev-buffers)) + (next-buffers (memq new-buffer old-buffers))) + (when next-buffers + (set-window-next-buffers nil (seq-filter (lambda (b) + (assq b prev-buffers)) + (cdr next-buffers)))) + (set-window-prev-buffers + nil (sort prev-buffers + (lambda (a b) + (cond + ((eq (car a) new-buffer) nil) + ((eq (car b) new-buffer) t) + (t (< (length (memq (car a) old-buffers)) + (length (memq (car b) old-buffers)))))))) + (set-window-parameter nil 'tab-line-window-buffers + (tab-line-tabs-window-buffers)))) + (defcustom tab-line-close-tab-function 'bury-buffer "What to do upon closing a tab on the tab line. @@ -1025,13 +1042,17 @@ tab-line-mode "Toggle display of tab line in the windows displaying the current buffer." :lighter nil (let ((default-value '(:eval (tab-line-format)))) - (if tab-line-mode - ;; Preserve the existing tab-line set outside of this mode - (unless tab-line-format - (setq tab-line-format default-value)) + (cond + (tab-line-mode + (add-hook 'window-buffer-change-functions #'tab-line-buffer-change nil t) + ;; Preserve the existing tab-line set outside of this mode + (unless tab-line-format + (setq tab-line-format default-value))) + (t + (remove-hook 'window-buffer-change-functions #'tab-line-buffer-change t) ;; Reset only values set by this mode (when (equal tab-line-format default-value) - (setq tab-line-format nil))))) + (setq tab-line-format nil)))))) (defcustom tab-line-exclude-modes '(completion-list-mode) --=-=-=--