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#33871: 27.0.50; Revert Dired window saved in window configuration Date: Fri, 16 Feb 2024 09:37:39 +0200 Organization: LINKOV.NET Message-ID: <86zfw07tbw.fsf@mail.linkov.net> References: <87bm59mglk.fsf@mail.linkov.net> <87fsoo323s.fsf@gnus.org> <86h792x3wv.fsf@mail.linkov.net> <119a9c2c-e27f-6c3a-07ad-66bc76fc58cf@gmx.at> <861r05co9l.fsf@mail.linkov.net> <86zgmsne32.fsf@mail.linkov.net> <86sfsi29yc.fsf@mail.linkov.net> <1830e7af-27a8-ac7f-ba6f-fa2006139208@gmx.at> <86fsohmqn9.fsf@mail.linkov.net> <9df28298-fedc-0cfe-7243-c04868115e90@gmx.at> <86fsoezsw3.fsf@mail.linkov.net> <86sfsewvxr.fsf@mail.linkov.net> <9d741b43-e3bb-669b-b345-6b877c902b33@gmx.at> <86fsoaq4lo.fsf@mail.linkov.net> <86tucp7dbp.fsf@mail.linkov.net> <37e2129c-464f-7f0a-0870-f7360ca21dc3@gmx.at> 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="38605"; 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: 33871@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 16 08:41:05 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 1rasqG-0009u5-RM for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 16 Feb 2024 08:41:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1raspy-0008Mr-LO; Fri, 16 Feb 2024 02:40:46 -0500 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 1raspv-0008MZ-MW for bug-gnu-emacs@gnu.org; Fri, 16 Feb 2024 02:40:44 -0500 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 1raspv-0004Ys-53 for bug-gnu-emacs@gnu.org; Fri, 16 Feb 2024 02:40:43 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rasqE-0005sh-2X for bug-gnu-emacs@gnu.org; Fri, 16 Feb 2024 02:41:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Feb 2024 07:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33871 X-GNU-PR-Package: emacs Original-Received: via spool by 33871-submit@debbugs.gnu.org id=B33871.170806920822532 (code B ref 33871); Fri, 16 Feb 2024 07:41:02 +0000 Original-Received: (at 33871) by debbugs.gnu.org; 16 Feb 2024 07:40:08 +0000 Original-Received: from localhost ([127.0.0.1]:57824 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1raspL-0005rL-P7 for submit@debbugs.gnu.org; Fri, 16 Feb 2024 02:40:08 -0500 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:37067) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1raspI-0005qm-TY for 33871@debbugs.gnu.org; Fri, 16 Feb 2024 02:40:06 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 844BCFF809; Fri, 16 Feb 2024 07:39:18 +0000 (UTC) In-Reply-To: <37e2129c-464f-7f0a-0870-f7360ca21dc3@gmx.at> (martin rudalics's message of "Thu, 24 Feb 2022 10:19:17 +0100") 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:280092 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit >> ;; set-window-configuration does not restore the value of >> ;; point in the current buffer, so restore it separately. >> (when (and (markerp wc-point) >> (marker-buffer wc-point) >> ;; FIXME: After dired-revert, marker relocates to 1. >> ;; window-configuration restores point to global point >> ;; in this dired buffer, not to its window point, >> ;; but this is slightly better than 1. >> ;; Maybe better to save dired-filename in each window? >> (not (eq 1 (marker-position wc-point)))) >> (goto-char wc-point)) >> >> Please note that this bug report is related to FIXME above. >> >> So a possible solution is also to save more context information >> like dired-filename, and then restore it using dired-goto-file. > > We obviously then should strive for a solution that stores any kind of > information via a hook in an alist of entries, one for each window in a > buffer local way, and one global entry for the frame itself. Here is the patch that stores any kind of information via a hook, one for each window in a buffer local way. Currently only dired positions for the revert case are supported. But also I tried to save context of any buffer in a bookmark way, and this works nicely, and correctly restores old positions even from window states from the desktop: #+begin_src emacs-lisp ;; Like ‘bookmark-make-record-default’: (setq-default window-set-context-function (lambda () `((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))))))) ;; Like ‘bookmark-default-handler’: (setq-default window-use-context-function (lambda (context) (when (search-forward (alist-get 'front-context-string context) (point-max) t) (goto-char (match-beginning 0))) (when (search-backward (alist-get 'rear-context-string context) (point-min) t) (goto-char (match-end 0))))) #+end_src --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=window-context-function.patch diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 3e1d8278b04..fc1b20287d3 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1283,6 +1283,10 @@ frameset-filter-tabs (push '(tabs . frameset-filter-tabs) frameset-filter-alist) +(defvar window-set-context-function nil) +(defvar window-use-context-function nil) +(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 +1296,14 @@ tab-bar--tab frame 'buffer-list))) (bbl (seq-filter #'buffer-live-p (frame-parameter frame 'buried-buffer-list)))) + (walk-windows + (lambda (w) + (with-selected-window w + (when (functionp window-set-context-function) + (when-let ((context (funcall window-set-context-function))) + (set-window-parameter w 'context (cons (buffer-name) context)))))) + 'nomini) + `(tab (name . ,(if tab-explicit-name (alist-get 'name tab) @@ -1479,6 +1491,15 @@ tab-bar-select-tab (select-window (get-mru-window))) (window-state-put ws nil 'safe))) + (walk-windows + (lambda (w) + (with-selected-window w + (when-let ((context (window-parameter w 'context))) + (when (and (functionp window-use-context-function) + (equal (buffer-name) (car context))) + (funcall window-use-context-function (cdr context)))))) + 'nomini) + ;; Select the minibuffer when it was active before switching tabs (when (and minibuffer-was-active (active-minibuffer-window)) (select-window (active-minibuffer-window))) diff --git a/lisp/dired.el b/lisp/dired.el index 9e3b888df14..df50f37df7b 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2743,6 +2745,12 @@ 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 () + `((dired-filename . ,(dired-get-filename nil t))))) + (setq-local window-use-context-function + (lambda (context) + (dired-goto-file (alist-get 'dired-filename context)))) (setq dired-switches-alist nil) (hack-dir-local-variables-non-file-buffer) ; before sorting (dired-sort-other dired-actual-switches t) --=-=-=--