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: Tue, 20 Feb 2024 09:45:09 +0200 Organization: LINKOV.NET Message-ID: <86y1bffvya.fsf@mail.linkov.net> References: <87bm59mglk.fsf@mail.linkov.net> <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> <86zfw07tbw.fsf@mail.linkov.net> <96fd3170-e5d2-4d16-93ec-c6fff3efb787@gmx.at> <86wmr2w7to.fsf@mail.linkov.net> <3808f9f8-624a-449c-8572-085582395859@gmx.at> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1002"; 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 Tue Feb 20 09:00:09 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 1rcL2u-00006Q-PO for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 20 Feb 2024 09:00:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcL2W-0007PQ-3X; Tue, 20 Feb 2024 02:59:44 -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 1rcL2U-0007Od-6Y for bug-gnu-emacs@gnu.org; Tue, 20 Feb 2024 02:59:42 -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 1rcL2T-0007dx-Uv for bug-gnu-emacs@gnu.org; Tue, 20 Feb 2024 02:59:41 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rcL2o-00065W-J1 for bug-gnu-emacs@gnu.org; Tue, 20 Feb 2024 03:00: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: Tue, 20 Feb 2024 08:00: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.170841596223305 (code B ref 33871); Tue, 20 Feb 2024 08:00:02 +0000 Original-Received: (at 33871) by debbugs.gnu.org; 20 Feb 2024 07:59:22 +0000 Original-Received: from localhost ([127.0.0.1]:44232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcL2A-00063p-Ev for submit@debbugs.gnu.org; Tue, 20 Feb 2024 02:59:22 -0500 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:59081) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcL27-00063N-2g for 33871@debbugs.gnu.org; Tue, 20 Feb 2024 02:59:19 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 59BAF2000E; Tue, 20 Feb 2024 07:58:49 +0000 (UTC) In-Reply-To: <3808f9f8-624a-449c-8572-085582395859@gmx.at> (martin rudalics's message of "Mon, 19 Feb 2024 10:42:46 +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:280314 Archived-At: >> Ok, let's add the WINDOW argument. This means that most hooks >> will need to call 'with-selected-window' explicitly. But maybe >> there will be hooks that don't need to select a window. > > (setq-default window-set-context-function > (lambda (w) > (let ((point (window-point w))) > (with-current-buffer (window-buffer 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))))))))) > > should suffice to make 'buffer-substring-no-properties' work. Note that > if you select the window beforehand, 'selected-window' will not return a > meaningful value in the body of the function called. This is a problem > of many "hooks" like 'mode-line-format' or 'window-configuration-hook'. > The comfort you get comes at the price of a lack of generality. Thanks. Is it possible to avoid 'with-selected-window' in other hooks? Maybe something like this: (setq-default window-use-context-function (lambda (w context) (let ((point (window-point w))) (with-current-buffer (window-buffer w) (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)))) and for Dired: diff --git a/lisp/dired.el b/lisp/dired.el index 9e3b888df14..fc8da1635f9 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))) + (with-current-buffer (window-buffer w) + (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))) + (with-current-buffer (window-buffer w) + (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)