From: Juri Linkov <juri@linkov.net>
To: martin rudalics <rudalics@gmx.at>
Cc: 33871@debbugs.gnu.org
Subject: bug#33871: 27.0.50; Revert Dired window saved in window configuration
Date: Wed, 20 Mar 2024 19:27:43 +0200 [thread overview]
Message-ID: <8634skstio.fsf@mail.linkov.net> (raw)
In-Reply-To: <bcaea0d2-37ca-47e5-8a1f-29f293bec2cf@gmx.at> (martin rudalics's message of "Wed, 21 Feb 2024 10:05:11 +0100")
[-- Attachment #1: Type: text/plain, Size: 350 bytes --]
> Probably something similar is needed for dired, for example to handle
> the case where its buffer is simultaneously shown in two windows with
> their points on different lines.
Avoiding select-window removed simplicity and now requires
adding more handling and more testing. But finally
everything works correctly. Please review the new patch:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: tab-bar-select-restore-context.patch --]
[-- Type: text/x-diff, Size: 4905 bytes --]
diff --git a/lisp/dired.el b/lisp/dired.el
index 9e3b888df14..cb2fc97d0ae 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2743,6 +2745,24 @@ dired-mode
'(dired-font-lock-keywords t nil nil beginning-of-line))
(setq-local desktop-save-buffer 'dired-desktop-buffer-misc-data)
(setq-local grep-read-files-function #'dired-grep-read-files)
+ (setq-local window-set-context-function
+ (lambda (w)
+ (let ((point (window-point w)))
+ (save-excursion
+ (goto-char point)
+ (if-let ((f (dired-get-filename nil t)))
+ `((dired-filename . ,f))
+ `((position . ,(point))))))))
+ (setq-local window-use-context-function
+ (lambda (w context)
+ (let ((point (window-point w)))
+ (save-excursion
+ (if-let ((f (alist-get 'dired-filename context)))
+ (dired-goto-file f)
+ (when-let ((p (alist-get 'position context)))
+ (goto-char p)))
+ (setq point (point)))
+ (set-window-point w point))))
(setq dired-switches-alist nil)
(hack-dir-local-variables-non-file-buffer) ; before sorting
(dired-sort-other dired-actual-switches t)
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index fa22500a04e..af2658d60a3 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1283,6 +1294,36 @@ frameset-filter-tabs
(push '(tabs . frameset-filter-tabs) frameset-filter-alist)
+(defun window-set-context-default-function (w)
+ "Set context to the front/rear strings."
+ (when buffer-file-name
+ (let ((point (window-point w)))
+ `((front-context-string
+ . ,(buffer-substring-no-properties
+ point (min (+ point 16) (point-max))))
+ (rear-context-string
+ . ,(buffer-substring-no-properties
+ point (max (- point 16) (point-min))))))))
+
+(defun window-use-context-default-function (w context)
+ "Restore context by the front/rear strings."
+ (let ((point (window-point w)))
+ (save-excursion
+ (goto-char point)
+ (when-let ((f (alist-get 'front-context-string context))
+ ((search-forward f (point-max) t)))
+ (goto-char (match-beginning 0))
+ (when-let ((r (alist-get 'rear-context-string context))
+ ((search-backward r (point-min) t)))
+ (goto-char (match-end 0))
+ (setq point (point)))))
+ (set-window-point w point)))
+
+(defvar window-set-context-function 'window-set-context-default-function)
+(defvar window-use-context-function 'window-use-context-default-function)
+
+(add-to-list 'window-persistent-parameters '(context . writable))
+
(defun tab-bar--tab (&optional frame)
"Make a new tab data structure that can be added to tabs on the FRAME."
(let* ((tab (tab-bar--current-tab-find nil frame))
@@ -1292,6 +1333,15 @@ tab-bar--tab
frame 'buffer-list)))
(bbl (seq-filter #'buffer-live-p (frame-parameter
frame 'buried-buffer-list))))
+ (when tab-bar-select-restore-context
+ (walk-windows
+ (lambda (w)
+ (with-current-buffer (window-buffer w)
+ (when-let (((functionp window-set-context-function))
+ (context (funcall window-set-context-function w)))
+ (set-window-parameter w 'context (cons (buffer-name) context)))))
+ 'nomini))
+
`(tab
(name . ,(if tab-explicit-name
(alist-get 'name tab)
@@ -1442,6 +1492,12 @@ tab-bar-select-restore-windows
(setq buffer-read-only t)
(set-window-buffer window new-buffer))))))
+(defcustom tab-bar-select-restore-context t
+ "Non-nil to restore context of the restored tab."
+ :type 'boolean
+ :group 'tab-bar
+ :version "30.1")
+
(defvar tab-bar-minibuffer-restore-tab nil
"Tab number for `tab-bar-minibuffer-restore-tab'.")
@@ -1539,6 +1595,17 @@ tab-bar-select-tab
(select-window (get-mru-window)))
(window-state-put ws nil 'safe)))
+ (when tab-bar-select-restore-context
+ (walk-windows
+ (lambda (w)
+ (with-current-buffer (window-buffer w)
+ (when-let (((functionp window-use-context-function))
+ (context (window-parameter w 'context))
+ ((equal (buffer-name) (car context))))
+ (funcall window-use-context-function w (cdr context))
+ (set-window-parameter w 'context nil))))
+ 'nomini))
+
;; Select the minibuffer when it was active before switching tabs
(when (and minibuffer-was-active (active-minibuffer-window))
(select-window (active-minibuffer-window)))
next prev parent reply other threads:[~2024-03-20 17:27 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-25 21:39 bug#33871: 27.0.50; Revert Dired window saved in window configuration Juri Linkov
2018-12-26 9:43 ` martin rudalics
2018-12-27 0:01 ` Juri Linkov
2018-12-27 9:37 ` martin rudalics
2018-12-27 21:34 ` Juri Linkov
2018-12-28 8:34 ` martin rudalics
2018-12-29 11:19 ` Markus Triska
2018-12-29 18:18 ` martin rudalics
2018-12-29 23:21 ` Juri Linkov
2018-12-30 9:52 ` martin rudalics
2018-12-30 14:57 ` martin rudalics
2018-12-30 21:29 ` Juri Linkov
2022-02-12 8:45 ` Lars Ingebrigtsen
2022-02-13 18:40 ` Juri Linkov
2022-02-14 9:13 ` martin rudalics
2022-02-14 18:10 ` Juri Linkov
2022-02-14 18:36 ` martin rudalics
2022-02-15 19:30 ` Juri Linkov
2022-02-16 8:50 ` martin rudalics
2022-02-16 18:34 ` Juri Linkov
2022-02-17 10:05 ` martin rudalics
2022-02-17 17:28 ` Juri Linkov
2022-02-19 9:37 ` martin rudalics
2022-02-19 17:08 ` Juri Linkov
2022-02-19 17:22 ` martin rudalics
2022-02-20 18:40 ` Juri Linkov
2022-02-21 9:07 ` martin rudalics
2022-02-22 17:14 ` Juri Linkov
2022-02-23 9:31 ` martin rudalics
2022-02-23 17:53 ` Juri Linkov
2022-02-24 9:19 ` martin rudalics
2024-02-16 7:37 ` Juri Linkov
2024-02-16 9:41 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-18 7:39 ` Juri Linkov
2024-02-19 9:42 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-20 7:45 ` Juri Linkov
2024-02-21 9:05 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-21 17:18 ` Juri Linkov
2024-03-20 17:27 ` Juri Linkov [this message]
2024-03-21 9:20 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-21 17:54 ` Juri Linkov
2024-03-22 9:26 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-22 16:15 ` Juri Linkov
2024-03-23 9:14 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-23 18:31 ` Juri Linkov
2024-03-24 9:54 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-24 17:12 ` Juri Linkov
2024-03-25 9:41 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-25 17:10 ` Juri Linkov
2024-03-26 9:55 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-28 7:40 ` Juri Linkov
2024-03-28 9:18 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-28 17:54 ` Juri Linkov
2024-03-29 8:45 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-29 16:25 ` Juri Linkov
2024-03-30 9:36 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 18:19 ` Juri Linkov
2024-04-02 17:19 ` Juri Linkov
2024-04-09 6:44 ` Juri Linkov
2024-04-09 9:05 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8634skstio.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=33871@debbugs.gnu.org \
--cc=rudalics@gmx.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.