[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#33871: 27.0.50; Revert Dired window saved in window configuration
From: |
Juri Linkov |
Subject: |
bug#33871: 27.0.50; Revert Dired window saved in window configuration |
Date: |
Tue, 20 Feb 2024 09:45:09 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) |
>> 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)